#include <stdio.h>
#include <stdlib.h>

#include <cuda.h>

/* Time */
#include <sys/time.h>
#include <sys/resource.h>

static struct timeval tv0;
double getMicroSeconds()
{
	double t;
	gettimeofday(&tv0, (struct timezone*)0);
	t = ((tv0.tv_usec) + (tv0.tv_sec)*1000000);

	return (t);
}

void init_seed()
{
	int seedi=1;
	FILE *fd;

	/* Generated random values between 0.00 - 1.00 */
	fd = fopen("/dev/urandom", "r");
	fread( &seedi, sizeof(int), 1, fd);
	fclose (fd);
	srand( seedi );
}

void init2Drand(float **buffer, int n)
{
	int i, j;

	for (i=0; i<n; i++)
		for(j=0; j<n; j++)
			buffer[i][j] = 500.0*(float(rand())/RAND_MAX)-500.0; /* [-500 500]*/
}

float *getmemory1D( int nx )
{
	int i;
	float *buffer;

	if( (buffer=(float *)malloc(nx*sizeof(float *)))== NULL )
	{
		fprintf( stderr, "ERROR in memory allocation\n" );
		return( NULL );
	}

	for( i=0; i<nx; i++ )
		buffer[i] = 0.0;

	return( buffer );
}


float **getmemory2D(int nx, int ny)
{
	int i,j;
	float **buffer;

	if( (buffer=(float **)malloc(nx*sizeof(float *)))== NULL )
	{
		fprintf( stderr, "ERROR in memory allocation\n" );
		return( NULL );
	}

	if( (buffer[0]=(float *)malloc(nx*ny*sizeof(float)))==NULL )
	{
		fprintf( stderr, "ERROR in memory allocation\n" );
		free( buffer );
		return( NULL );
	}

	for( i=1; i<nx; i++ )
	{
		buffer[i] = buffer[i-1] + ny;
	}

	for( i=0; i<nx; i++ )
		for( j=0; j<ny; j++ )
		{
			buffer[i][j] = 0.0;
		}

	return( buffer );
}



/********************************************************************************/
/********************************************************************************/

/*
 * Traspose 2D version
 */
void transpose2D(float **in, float **out, int n)
{
	int i, j;

	for(j=0; j < n; j++) 
		for(i=0; i < n; i++) 
			out[j][i] = in[i][j]; 
}

/*
 * Traspose 1D version
 */
void transpose1D(float *in, float *out, int n)
{
	int i, j;

	for(j=0; j < n; j++) 
		for(i=0; i < n; i++) 
			out[j*n+i] = in[i*n+j]; 
}

/*
 * Traspose CUDA version
 */

#define TILE_DIM 16


__global__ void transpose_device_v3(float *in, float *out, int rows, int cols) 
{
	int i,j;
	__shared__ float tile[TILE_DIM][TILE_DIM];

	i = blockIdx.x * blockDim.x + threadIdx.x; 
	j = blockIdx.y * blockDim.y + threadIdx.y;
	
	if(i < rows && j<cols){
	
		tile[i][j] = in[j * cols + i]; 
		__syncthreads();

		i = threadIdx.x;
		j = threadIdx.y;	

		out [ i * cols + j ] = tile [i][j]; 

	} 
}

int check(float *GPU, float **CPU, int n)
{
	int i,j;

	for (i=0; i<n; i++)
		for(j = 0; j < n; j++)
			if(GPU[i * n + j]!=CPU[i][j])
				return(1);

	return(0);
}


void print_matrix(float *M, int hM, int wM)
{
	int i,j;

	for (i=0; i<hM; i++){
//		printf("Line %i: ", i);
		for (j=0; j<wM; j++)
			printf("%4.1f ", M[i*wM+j]);
		printf("\n");
	}
}

int main(int argc, char **argv)
{
	int n;
	float **array2D, **array2D_trans;
	float *array2D_trans_GPU;
	double t0;
	float size_block = 16;

	if (argc==2)
		n = atoi(argv[1]);
	else {
		n = 4096;
		printf("./exec n (by default n=%i)\n", n);
	}
	
	/* Initizalization */
	init_seed();
	array2D       = getmemory2D(n,n);
	array2D_trans = getmemory2D(n,n);
	init2Drand(array2D, n);

	/* Transpose 2D version */
	t0 = getMicroSeconds();
	transpose2D(array2D, array2D_trans, n);
	printf("Transpose version 2D: %f MB/s\n", n*n*sizeof(float)/((getMicroSeconds()-t0)/1000000)/1024/1024);


	/* CUDA version */
	float *darray2D, *darray2D_trans;
	cudaMalloc((void**)&darray2D, n*n*sizeof(float));
	cudaMemcpy(darray2D, array2D, n*n*sizeof(float), cudaMemcpyHostToDevice);
	cudaMalloc((void**)&darray2D_trans, n*n*sizeof(float));

	dim3 dimBlock(size_block,size_block);
	int blocks = ceil(n/size_block);
	dim3 dimGrid(blocks);

	t0 = getMicroSeconds();
	transpose_device_v3<<<dimGrid,dimBlock>>>(darray2D, darray2D_trans, n, n);	
	array2D_trans_GPU = (float *)malloc(n*n * sizeof(float));
	cudaMemcpy(array2D_trans_GPU, darray2D_trans, n*n*sizeof(float), cudaMemcpyDeviceToHost);
	cudaThreadSynchronize();
	
	printf("Transpose kernel version: %f MB/s\n", n*n*sizeof(float)/((getMicroSeconds()-t0)/1000000)/1024/1024);

	printf("Matriz GPU:\n");	
	print_matrix(array2D_trans_GPU,n,n);

	printf("Matriz CPU\n");
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			printf("%4.1f ",array2D_trans[i][j]);
		}
	printf("\n");
	}

	if (check(array2D_trans_GPU, array2D_trans, n*n))
		printf("Transpose CPU-GPU differs!!\n");


	return(1);
}

	.file	"tmpxft_002a7f3a_00000000-6_transpose.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2039:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2039:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z15getMicroSecondsv
	.type	_Z15getMicroSecondsv, @function
_Z15getMicroSecondsv:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	xorl	%esi, %esi
	leaq	_ZL3tv0(%rip), %rdi
	call	gettimeofday@PLT
	imulq	$1000000, _ZL3tv0(%rip), %rax
	addq	8+_ZL3tv0(%rip), %rax
	cvtsi2sdq	%rax, %xmm0
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z15getMicroSecondsv, .-_Z15getMicroSecondsv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"r"
.LC1:
	.string	"/dev/urandom"
	.text
	.globl	_Z9init_seedv
	.type	_Z9init_seedv, @function
_Z9init_seedv:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	.LC0(%rip), %rsi
	leaq	.LC1(%rip), %rdi
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movl	$1, 4(%rsp)
	call	fopen@PLT
	leaq	4(%rsp), %rdi
	movl	$1, %ecx
	movl	$4, %edx
	movq	%rax, %rbx
	movq	%rax, %r8
	movl	$4, %esi
	call	__fread_chk@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	movl	4(%rsp), %edi
	call	srand@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z9init_seedv, .-_Z9init_seedv
	.globl	_Z10init2DrandPPfi
	.type	_Z10init2DrandPPfi, @function
_Z10init2DrandPPfi:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movslq	%esi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%r14, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	xorl	%ebx, %ebx
.L9:
	cmpl	%ebx, %ebp
	jle	.L14
	xorl	%r12d, %r12d
.L10:
	call	rand@PLT
	movsd	.LC3(%rip), %xmm1
	movq	0(%r13,%rbx,8), %rdx
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC2(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulsd	%xmm1, %xmm0
	subsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%rdx,%r12,4)
	incq	%r12
	cmpq	%r14, %r12
	jne	.L10
	incq	%rbx
	jmp	.L9
.L14:
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z10init2DrandPPfi, .-_Z10init2DrandPPfi
	.section	.rodata.str1.1
.LC4:
	.string	"ERROR in memory allocation\n"
	.text
	.globl	_Z11getmemory1Di
	.type	_Z11getmemory1Di, @function
_Z11getmemory1Di:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movslq	%edi, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbp
	salq	$3, %rdi
	pushq	%rcx
	.cfi_def_cfa_offset 32
	call	malloc@PLT
	movq	%rax, %rbx
	xorl	%eax, %eax
	testq	%rbx, %rbx
	jne	.L16
	movq	stderr(%rip), %rdi
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	jmp	.L15
.L16:
	cmpl	%eax, %ebp
	jle	.L15
	movl	$0x00000000, (%rbx,%rax,4)
	incq	%rax
	jmp	.L16
.L15:
	movq	%rbx, %rax
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z11getmemory1Di, .-_Z11getmemory1Di
	.globl	_Z11getmemory2Dii
	.type	_Z11getmemory2Dii, @function
_Z11getmemory2Dii:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movslq	%edi, %rdi
	movl	%esi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	salq	$3, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	call	malloc@PLT
	testq	%rax, %rax
	jne	.L23
	movq	stderr(%rip), %rdi
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L24
.L23:
	movl	%ebp, %edi
	movq	%rax, %rbx
	imull	%r12d, %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, (%rbx)
	testq	%rax, %rax
	je	.L25
	movslq	%r12d, %rdx
	xorl	%eax, %eax
	salq	$2, %rdx
	jmp	.L26
.L25:
	movq	stderr(%rip), %rdi
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	%rbx, %rdi
	call	free@PLT
.L24:
	xorl	%ebx, %ebx
	jmp	.L22
.L26:
	incq	%rax
	cmpl	%eax, %ebp
	jle	.L34
	movq	-8(%rbx,%rax,8), %rcx
	addq	%rdx, %rcx
	movq	%rcx, (%rbx,%rax,8)
	jmp	.L26
.L34:
	xorl	%eax, %eax
.L29:
	cmpl	%eax, %ebp
	jle	.L22
	xorl	%edx, %edx
.L31:
	cmpl	%edx, %r12d
	jle	.L35
	movq	(%rbx,%rax,8), %rcx
	movl	$0x00000000, (%rcx,%rdx,4)
	incq	%rdx
	jmp	.L31
.L35:
	incq	%rax
	jmp	.L29
.L22:
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z11getmemory2Dii, .-_Z11getmemory2Dii
	.globl	_Z11transpose2DPPfS0_i
	.type	_Z11transpose2DPPfS0_i, @function
_Z11transpose2DPPfS0_i:
.LFB2032:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
.L37:
	cmpl	%eax, %edx
	jle	.L41
	movq	(%rsi,%rax,8), %r8
	leaq	0(,%rax,4), %r9
	xorl	%ecx, %ecx
.L38:
	movq	(%rdi,%rcx,8), %r10
	movss	(%r10,%r9), %xmm0
	movss	%xmm0, (%r8,%rcx,4)
	incq	%rcx
	cmpl	%ecx, %edx
	jg	.L38
	incq	%rax
	jmp	.L37
.L41:
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z11transpose2DPPfS0_i, .-_Z11transpose2DPPfS0_i
	.globl	_Z11transpose1DPfS_i
	.type	_Z11transpose1DPfS_i, @function
_Z11transpose1DPfS_i:
.LFB2033:
	.cfi_startproc
	endbr64
	movslq	%edx, %rax
	xorl	%r8d, %r8d
	salq	$2, %rax
.L43:
	cmpl	%edx, %r8d
	jge	.L47
	movq	%rdi, %r9
	xorl	%ecx, %ecx
.L44:
	movss	(%r9), %xmm0
	addq	%rax, %r9
	movss	%xmm0, (%rsi,%rcx,4)
	incq	%rcx
	cmpl	%ecx, %edx
	jg	.L44
	incl	%r8d
	addq	$4, %rdi
	addq	%rax, %rsi
	jmp	.L43
.L47:
	ret
	.cfi_endproc
.LFE2033:
	.size	_Z11transpose1DPfS_i, .-_Z11transpose1DPfS_i
	.globl	_Z5checkPfPS_i
	.type	_Z5checkPfPS_i, @function
_Z5checkPfPS_i:
.LFB2034:
	.cfi_startproc
	endbr64
	movslq	%edx, %r8
	xorl	%ecx, %ecx
	salq	$2, %r8
.L49:
	cmpl	%ecx, %edx
	jle	.L57
	movq	(%rsi,%rcx,8), %r9
	xorl	%eax, %eax
.L52:
	movss	(%rdi,%rax,4), %xmm0
	ucomiss	(%r9,%rax,4), %xmm0
	jp	.L54
	jne	.L54
	incq	%rax
	cmpl	%eax, %edx
	jg	.L52
	incq	%rcx
	addq	%r8, %rdi
	jmp	.L49
.L57:
	xorl	%eax, %eax
	ret
.L54:
	movl	$1, %eax
	ret
	.cfi_endproc
.LFE2034:
	.size	_Z5checkPfPS_i, .-_Z5checkPfPS_i
	.section	.rodata.str1.1
.LC6:
	.string	"%4.1f "
.LC7:
	.string	"\n"
	.text
	.globl	_Z12print_matrixPfii
	.type	_Z12print_matrixPfii, @function
_Z12print_matrixPfii:
.LFB2035:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%esi, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
.L59:
	cmpl	%r14d, %r13d
	jge	.L58
	movslq	%r12d, %rax
	xorl	%r15d, %r15d
	leaq	0(%rbp,%rax,4), %rcx
.L62:
	cmpl	%r15d, %ebx
	jle	.L64
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	(%rcx,%r15,4), %xmm0
	movq	%rcx, 8(%rsp)
	incq	%r15
	call	__printf_chk@PLT
	movq	8(%rsp), %rcx
	jmp	.L62
.L64:
	leaq	.LC7(%rip), %rsi
	xorl	%eax, %eax
	incl	%r13d
	addl	%ebx, %r12d
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L59
.L58:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2035:
	.size	_Z12print_matrixPfii, .-_Z12print_matrixPfii
	.globl	_Z43__device_stub__Z19transpose_device_v3PfS_iiPfS_ii
	.type	_Z43__device_stub__Z19transpose_device_v3PfS_iiPfS_ii, @function
_Z43__device_stub__Z19transpose_device_v3PfS_iiPfS_ii:
.LFB2061:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L65
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z19transpose_device_v3PfS_ii(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L65:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L67
	call	__stack_chk_fail@PLT
.L67:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2061:
	.size	_Z43__device_stub__Z19transpose_device_v3PfS_iiPfS_ii, .-_Z43__device_stub__Z19transpose_device_v3PfS_iiPfS_ii
	.globl	_Z19transpose_device_v3PfS_ii
	.type	_Z19transpose_device_v3PfS_ii, @function
_Z19transpose_device_v3PfS_ii:
.LFB2062:
	.cfi_startproc
	endbr64
	jmp	_Z43__device_stub__Z19transpose_device_v3PfS_iiPfS_ii
	.cfi_endproc
.LFE2062:
	.size	_Z19transpose_device_v3PfS_ii, .-_Z19transpose_device_v3PfS_ii
	.section	.rodata.str1.1
.LC8:
	.string	"./exec n (by default n=%i)\n"
.LC11:
	.string	"Transpose version 2D: %f MB/s\n"
.LC13:
	.string	"Transpose kernel version: %f MB/s\n"
.LC14:
	.string	"Matriz GPU:\n"
.LC15:
	.string	"Matriz CPU\n"
.LC16:
	.string	"Transpose CPU-GPU differs!!\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2036:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	cmpl	$2, %edi
	jne	.L71
	movq	8(%rsi), %rdi
	call	atoi@PLT
	movl	%eax, %ebx
	jmp	.L72
.L71:
	movl	$4096, %edx
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$4096, %ebx
.L72:
	call	_Z9init_seedv
	movl	%ebx, %r13d
	movl	%ebx, %esi
	movl	%ebx, %edi
	call	_Z11getmemory2Dii
	imull	%ebx, %r13d
	movl	%ebx, %esi
	movl	%ebx, %edi
	movq	%rax, %rbp
	call	_Z11getmemory2Dii
	movl	%ebx, %esi
	movq	%rbp, %rdi
	movq	%rax, %r12
	movslq	%r13d, %r14
	call	_Z10init2DrandPPfi
	salq	$2, %r14
	call	_Z15getMicroSecondsv
	movl	%ebx, %edx
	movq	%r12, %rsi
	movq	%rbp, %rdi
	movsd	%xmm0, (%rsp)
	call	_Z11transpose2DPPfS0_i
	cvtsi2sdq	%r14, %xmm2
	movq	%xmm2, %r15
	call	_Z15getMicroSecondsv
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	movaps	%xmm0, %xmm1
	movq	%r15, %xmm0
	subsd	(%rsp), %xmm1
	divsd	.LC9(%rip), %xmm1
	divsd	%xmm1, %xmm0
	mulsd	.LC10(%rip), %xmm0
	mulsd	.LC10(%rip), %xmm0
	call	__printf_chk@PLT
	leaq	16(%rsp), %rdi
	movq	%r14, %rsi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdi
	movq	%r14, %rdx
	movq	%rbp, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	leaq	24(%rsp), %rdi
	movq	%r14, %rsi
	call	cudaMalloc@PLT
	cvtsi2ssl	%ebx, %xmm0
	mulss	.LC12(%rip), %xmm0
	movabsq	$68719476752, %rax
	movq	%rax, 32(%rsp)
	movl	$1, 40(%rsp)
	call	ceilf@PLT
	cvttss2sil	%xmm0, %eax
	movl	%eax, 44(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	call	_Z15getMicroSecondsv
	movl	40(%rsp), %ecx
	movl	52(%rsp), %esi
	xorl	%r9d, %r9d
	movq	32(%rsp), %rdx
	movq	44(%rsp), %rdi
	xorl	%r8d, %r8d
	movsd	%xmm0, 8(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L73
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdi
	movl	%ebx, %ecx
	movl	%ebx, %edx
	call	_Z43__device_stub__Z19transpose_device_v3PfS_iiPfS_ii
.L73:
	movq	%r14, %rdi
	call	malloc@PLT
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	movq	%r14, %rdx
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	xorl	%r14d, %r14d
	call	cudaMemcpy@PLT
	call	cudaThreadSynchronize@PLT
	call	_Z15getMicroSecondsv
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	movaps	%xmm0, %xmm1
	movq	%r15, %xmm0
	subsd	8(%rsp), %xmm1
	divsd	.LC9(%rip), %xmm1
	divsd	%xmm1, %xmm0
	leaq	.LC6(%rip), %r15
	mulsd	.LC10(%rip), %xmm0
	mulsd	.LC10(%rip), %xmm0
	call	__printf_chk@PLT
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	(%rsp), %rdi
	movl	%ebx, %edx
	movl	%ebx, %esi
	call	_Z12print_matrixPfii
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L74:
	cmpl	%r14d, %ebx
	jle	.L84
	xorl	%ebp, %ebp
.L75:
	movq	(%r12,%r14,8), %rax
	movq	%r15, %rsi
	movl	$2, %edi
	cvtss2sd	(%rax,%rbp,4), %xmm0
	movb	$1, %al
	incq	%rbp
	call	__printf_chk@PLT
	cmpl	%ebp, %ebx
	jg	.L75
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%r14
	call	__printf_chk@PLT
	jmp	.L74
.L84:
	movq	(%rsp), %rdi
	movl	%r13d, %edx
	movq	%r12, %rsi
	call	_Z5checkPfPS_i
	testl	%eax, %eax
	je	.L76
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L76:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L77
	call	__stack_chk_fail@PLT
.L77:
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	movl	$1, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2036:
	.size	main, .-main
	.section	.rodata.str1.1
.LC17:
	.string	"_Z19transpose_device_v3PfS_ii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2064:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC17(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z19transpose_device_v3PfS_ii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2064:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.local	_ZL3tv0
	.comm	_ZL3tv0,16,16
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC2:
	.long	805306368
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC3:
	.long	0
	.long	1082081280
	.align 8
.LC9:
	.long	0
	.long	1093567616
	.align 8
.LC10:
	.long	0
	.long	1062207488
	.section	.rodata.cst4
	.align 4
.LC12:
	.long	1031798784
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include <stdio.h>
#include <stdlib.h>

#include <hip/hip_runtime.h>

/* Time */
#include <sys/time.h>
#include <sys/resource.h>

static struct timeval tv0;
double getMicroSeconds()
{
	double t;
	gettimeofday(&tv0, (struct timezone*)0);
	t = ((tv0.tv_usec) + (tv0.tv_sec)*1000000);

	return (t);
}

void init_seed()
{
	int seedi=1;
	FILE *fd;

	/* Generated random values between 0.00 - 1.00 */
	fd = fopen("/dev/urandom", "r");
	fread( &seedi, sizeof(int), 1, fd);
	fclose (fd);
	srand( seedi );
}

void init2Drand(float **buffer, int n)
{
	int i, j;

	for (i=0; i<n; i++)
		for(j=0; j<n; j++)
			buffer[i][j] = 500.0*(float(rand())/RAND_MAX)-500.0; /* [-500 500]*/
}

float *getmemory1D( int nx )
{
	int i;
	float *buffer;

	if( (buffer=(float *)malloc(nx*sizeof(float *)))== NULL )
	{
		fprintf( stderr, "ERROR in memory allocation\n" );
		return( NULL );
	}

	for( i=0; i<nx; i++ )
		buffer[i] = 0.0;

	return( buffer );
}


float **getmemory2D(int nx, int ny)
{
	int i,j;
	float **buffer;

	if( (buffer=(float **)malloc(nx*sizeof(float *)))== NULL )
	{
		fprintf( stderr, "ERROR in memory allocation\n" );
		return( NULL );
	}

	if( (buffer[0]=(float *)malloc(nx*ny*sizeof(float)))==NULL )
	{
		fprintf( stderr, "ERROR in memory allocation\n" );
		free( buffer );
		return( NULL );
	}

	for( i=1; i<nx; i++ )
	{
		buffer[i] = buffer[i-1] + ny;
	}

	for( i=0; i<nx; i++ )
		for( j=0; j<ny; j++ )
		{
			buffer[i][j] = 0.0;
		}

	return( buffer );
}



/********************************************************************************/
/********************************************************************************/

/*
 * Traspose 2D version
 */
void transpose2D(float **in, float **out, int n)
{
	int i, j;

	for(j=0; j < n; j++) 
		for(i=0; i < n; i++) 
			out[j][i] = in[i][j]; 
}

/*
 * Traspose 1D version
 */
void transpose1D(float *in, float *out, int n)
{
	int i, j;

	for(j=0; j < n; j++) 
		for(i=0; i < n; i++) 
			out[j*n+i] = in[i*n+j]; 
}

/*
 * Traspose CUDA version
 */

#define TILE_DIM 16


__global__ void transpose_device_v3(float *in, float *out, int rows, int cols) 
{
	int i,j;
	__shared__ float tile[TILE_DIM][TILE_DIM];

	i = blockIdx.x * blockDim.x + threadIdx.x; 
	j = blockIdx.y * blockDim.y + threadIdx.y;
	
	if(i < rows && j<cols){
	
		tile[i][j] = in[j * cols + i]; 
		__syncthreads();

		i = threadIdx.x;
		j = threadIdx.y;	

		out [ i * cols + j ] = tile [i][j]; 

	} 
}

int check(float *GPU, float **CPU, int n)
{
	int i,j;

	for (i=0; i<n; i++)
		for(j = 0; j < n; j++)
			if(GPU[i * n + j]!=CPU[i][j])
				return(1);

	return(0);
}


void print_matrix(float *M, int hM, int wM)
{
	int i,j;

	for (i=0; i<hM; i++){
//		printf("Line %i: ", i);
		for (j=0; j<wM; j++)
			printf("%4.1f ", M[i*wM+j]);
		printf("\n");
	}
}

int main(int argc, char **argv)
{
	int n;
	float **array2D, **array2D_trans;
	float *array2D_trans_GPU;
	double t0;
	float size_block = 16;

	if (argc==2)
		n = atoi(argv[1]);
	else {
		n = 4096;
		printf("./exec n (by default n=%i)\n", n);
	}
	
	/* Initizalization */
	init_seed();
	array2D       = getmemory2D(n,n);
	array2D_trans = getmemory2D(n,n);
	init2Drand(array2D, n);

	/* Transpose 2D version */
	t0 = getMicroSeconds();
	transpose2D(array2D, array2D_trans, n);
	printf("Transpose version 2D: %f MB/s\n", n*n*sizeof(float)/((getMicroSeconds()-t0)/1000000)/1024/1024);


	/* CUDA version */
	float *darray2D, *darray2D_trans;
	hipMalloc((void**)&darray2D, n*n*sizeof(float));
	hipMemcpy(darray2D, array2D, n*n*sizeof(float), hipMemcpyHostToDevice);
	hipMalloc((void**)&darray2D_trans, n*n*sizeof(float));

	dim3 dimBlock(size_block,size_block);
	int blocks = ceil(n/size_block);
	dim3 dimGrid(blocks);

	t0 = getMicroSeconds();
	transpose_device_v3<<<dimGrid,dimBlock>>>(darray2D, darray2D_trans, n, n);	
	array2D_trans_GPU = (float *)malloc(n*n * sizeof(float));
	hipMemcpy(array2D_trans_GPU, darray2D_trans, n*n*sizeof(float), hipMemcpyDeviceToHost);
	hipDeviceSynchronize();
	
	printf("Transpose kernel version: %f MB/s\n", n*n*sizeof(float)/((getMicroSeconds()-t0)/1000000)/1024/1024);

	printf("Matriz GPU:\n");	
	print_matrix(array2D_trans_GPU,n,n);

	printf("Matriz CPU\n");
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			printf("%4.1f ",array2D_trans[i][j]);
		}
	printf("\n");
	}

	if (check(array2D_trans_GPU, array2D_trans, n*n))
		printf("Transpose CPU-GPU differs!!\n");


	return(1);
}

	.text
	.file	"transpose.hip"
	.globl	_Z15getMicroSecondsv            # -- Begin function _Z15getMicroSecondsv
	.type	_Z15getMicroSecondsv,@function
_Z15getMicroSecondsv:                   # @_Z15getMicroSecondsv
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$_ZL3tv0, %edi
	xorl	%esi, %esi
	callq	gettimeofday
	imulq	$1000000, _ZL3tv0(%rip), %rax   # imm = 0xF4240
	addq	_ZL3tv0+8(%rip), %rax
	cvtsi2sd	%rax, %xmm0
	popq	%rax
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z15getMicroSecondsv, .Lfunc_end0-_Z15getMicroSecondsv
	.cfi_endproc
                                        # -- End function
	.globl	_Z9init_seedv                   # -- Begin function _Z9init_seedv
	.type	_Z9init_seedv,@function
_Z9init_seedv:                          # @_Z9init_seedv
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	leaq	4(%rsp), %rbx
	movl	$1, (%rbx)
	movl	$.L.str, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, %r14
	movl	$4, %esi
	movl	$1, %edx
	movq	%rbx, %rdi
	movq	%rax, %rcx
	callq	fread
	movq	%r14, %rdi
	callq	fclose
	movl	(%rbx), %edi
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	srand                           # TAILCALL
.Lfunc_end1:
	.size	_Z9init_seedv, .Lfunc_end1-_Z9init_seedv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z10init2DrandPPfi
.LCPI2_0:
	.long	0x30000000                      # float 4.65661287E-10
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI2_1:
	.quad	0x407f400000000000              # double 500
.LCPI2_2:
	.quad	0xc07f400000000000              # double -500
	.text
	.globl	_Z10init2DrandPPfi
	.type	_Z10init2DrandPPfi,@function
_Z10init2DrandPPfi:                     # @_Z10init2DrandPPfi
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB2_6
# %bb.1:                                # %.preheader.lr.ph
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	%esi, %r14d
	xorl	%r15d, %r15d
.LBB2_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_3 Depth 2
	xorl	%r12d, %r12d
.LBB2_3:                                #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	movss	.LCPI2_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	%xmm1, %xmm0
	movsd	.LCPI2_1(%rip), %xmm1           # xmm1 = mem[0],zero
	cvtss2sd	%xmm0, %xmm0
	mulsd	%xmm1, %xmm0
	movsd	.LCPI2_2(%rip), %xmm1           # xmm1 = mem[0],zero
	addsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movq	(%rbx,%r15,8), %rax
	movss	%xmm0, (%rax,%r12,4)
	incq	%r12
	cmpq	%r12, %r14
	jne	.LBB2_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	incq	%r15
	cmpq	%r14, %r15
	jne	.LBB2_2
# %bb.5:
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r12
	.cfi_restore %r14
	.cfi_restore %r15
.LBB2_6:                                # %._crit_edge12
	retq
.Lfunc_end2:
	.size	_Z10init2DrandPPfi, .Lfunc_end2-_Z10init2DrandPPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z11getmemory1Di                # -- Begin function _Z11getmemory1Di
	.type	_Z11getmemory1Di,@function
_Z11getmemory1Di:                       # @_Z11getmemory1Di
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %rbp, -16
	movl	%edi, %ebp
	movslq	%edi, %rdi
	shlq	$3, %rdi
	callq	malloc
	movq	%rax, %rbx
	testq	%rax, %rax
	je	.LBB3_3
# %bb.1:                                # %.preheader
	testl	%ebp, %ebp
	jle	.LBB3_4
# %bb.2:                                # %.lr.ph.preheader
	movl	%ebp, %edx
	shlq	$2, %rdx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
.LBB3_4:                                # %.loopexit
	movq	%rbx, %rax
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB3_3:
	.cfi_def_cfa_offset 32
	movq	stderr(%rip), %rcx
	movl	$.L.str.2, %edi
	movl	$27, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB3_4
.Lfunc_end3:
	.size	_Z11getmemory1Di, .Lfunc_end3-_Z11getmemory1Di
	.cfi_endproc
                                        # -- End function
	.globl	_Z11getmemory2Dii               # -- Begin function _Z11getmemory2Dii
	.type	_Z11getmemory2Dii,@function
_Z11getmemory2Dii:                      # @_Z11getmemory2Dii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebp
	movl	%edi, %r14d
	movslq	%edi, %rdi
	shlq	$3, %rdi
	callq	malloc
	testq	%rax, %rax
	je	.LBB4_11
# %bb.1:
	movq	%rax, %rbx
	movl	%ebp, %eax
	imull	%r14d, %eax
	movslq	%eax, %rdi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, (%rbx)
	testq	%rax, %rax
	je	.LBB4_13
# %bb.2:                                # %.preheader28
	movl	%r14d, %r15d
	cmpl	$2, %r14d
	jl	.LBB4_5
# %bb.3:                                # %.lr.ph
	movslq	%ebp, %rax
	shlq	$2, %rax
	movq	(%rbx), %rcx
	addq	%rax, %rcx
	movl	$1, %edx
.LBB4_4:                                # =>This Inner Loop Header: Depth=1
	movq	%rcx, (%rbx,%rdx,8)
	incq	%rdx
	addq	%rax, %rcx
	cmpq	%rdx, %r15
	jne	.LBB4_4
.LBB4_5:                                # %.preheader27
	testl	%r14d, %r14d
	jle	.LBB4_10
# %bb.6:                                # %.preheader.lr.ph
	movl	%ebp, %r14d
	shlq	$2, %r14
	xorl	%r12d, %r12d
.LBB4_7:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	testl	%ebp, %ebp
	jle	.LBB4_9
# %bb.8:                                # %.lr.ph31
                                        #   in Loop: Header=BB4_7 Depth=1
	movq	(%rbx,%r12,8), %rdi
	xorl	%esi, %esi
	movq	%r14, %rdx
	callq	memset@PLT
.LBB4_9:                                # %._crit_edge
                                        #   in Loop: Header=BB4_7 Depth=1
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB4_7
.LBB4_10:                               # %.loopexit
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB4_11:
	.cfi_def_cfa_offset 48
	movq	stderr(%rip), %rcx
	movl	$.L.str.2, %edi
	movl	$27, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB4_12
.LBB4_13:
	movq	stderr(%rip), %rcx
	movl	$.L.str.2, %edi
	movl	$27, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movq	%rbx, %rdi
	callq	free
.LBB4_12:                               # %.loopexit
	xorl	%ebx, %ebx
	jmp	.LBB4_10
.Lfunc_end4:
	.size	_Z11getmemory2Dii, .Lfunc_end4-_Z11getmemory2Dii
	.cfi_endproc
                                        # -- End function
	.globl	_Z11transpose2DPPfS0_i          # -- Begin function _Z11transpose2DPPfS0_i
	.type	_Z11transpose2DPPfS0_i,@function
_Z11transpose2DPPfS0_i:                 # @_Z11transpose2DPPfS0_i
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB5_5
# %bb.1:                                # %.preheader.lr.ph
	movl	%edx, %eax
	xorl	%ecx, %ecx
.LBB5_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_3 Depth 2
	movq	(%rsi,%rcx,8), %rdx
	xorl	%r8d, %r8d
.LBB5_3:                                #   Parent Loop BB5_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	(%rdi,%r8,8), %r9
	movss	(%r9,%rcx,4), %xmm0             # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%rdx,%r8,4)
	incq	%r8
	cmpq	%r8, %rax
	jne	.LBB5_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB5_2 Depth=1
	incq	%rcx
	cmpq	%rax, %rcx
	jne	.LBB5_2
.LBB5_5:                                # %._crit_edge15
	retq
.Lfunc_end5:
	.size	_Z11transpose2DPPfS0_i, .Lfunc_end5-_Z11transpose2DPPfS0_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z11transpose1DPfS_i            # -- Begin function _Z11transpose1DPfS_i
	.type	_Z11transpose1DPfS_i,@function
_Z11transpose1DPfS_i:                   # @_Z11transpose1DPfS_i
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB6_6
# %bb.1:                                # %.preheader.lr.ph
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	%edx, %eax
	leaq	(,%rax,4), %rcx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
.LBB6_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_3 Depth 2
	movl	%r8d, %r10d
	leaq	(%rsi,%r10,4), %r10
	movq	%rdi, %r11
	xorl	%ebx, %ebx
.LBB6_3:                                #   Parent Loop BB6_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%r11), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%r10,%rbx,4)
	incq	%rbx
	addq	%rcx, %r11
	cmpq	%rbx, %rax
	jne	.LBB6_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB6_2 Depth=1
	incq	%r9
	addl	%edx, %r8d
	addq	$4, %rdi
	cmpq	%rax, %r9
	jne	.LBB6_2
# %bb.5:
	popq	%rbx
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
.LBB6_6:                                # %._crit_edge17
	retq
.Lfunc_end6:
	.size	_Z11transpose1DPfS_i, .Lfunc_end6-_Z11transpose1DPfS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z34__device_stub__transpose_device_v3PfS_ii # -- Begin function _Z34__device_stub__transpose_device_v3PfS_ii
	.type	_Z34__device_stub__transpose_device_v3PfS_ii,@function
_Z34__device_stub__transpose_device_v3PfS_ii: # @_Z34__device_stub__transpose_device_v3PfS_ii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z19transpose_device_v3PfS_ii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end7:
	.size	_Z34__device_stub__transpose_device_v3PfS_ii, .Lfunc_end7-_Z34__device_stub__transpose_device_v3PfS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z5checkPfPS_i                  # -- Begin function _Z5checkPfPS_i
	.type	_Z5checkPfPS_i,@function
_Z5checkPfPS_i:                         # @_Z5checkPfPS_i
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB8_1
# %bb.3:                                # %.preheader.lr.ph
	movl	%edx, %eax
	xorl	%ecx, %ecx
	xorl	%r8d, %r8d
.LBB8_4:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB8_6 Depth 2
	movl	%ecx, %r9d
	leaq	(%rdi,%r9,4), %r9
	movq	(%rsi,%r8,8), %r10
	xorl	%r11d, %r11d
.LBB8_6:                                #   Parent Loop BB8_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%r9,%r11,4), %xmm0             # xmm0 = mem[0],zero,zero,zero
	ucomiss	(%r10,%r11,4), %xmm0
	jne	.LBB8_7
	jp	.LBB8_7
# %bb.5:                                #   in Loop: Header=BB8_6 Depth=2
	incq	%r11
	cmpq	%r11, %rax
	jne	.LBB8_6
# %bb.8:                                # %._crit_edge
                                        #   in Loop: Header=BB8_4 Depth=1
	incq	%r8
	addl	%edx, %ecx
	cmpq	%rax, %r8
	jne	.LBB8_4
.LBB8_1:
	xorl	%eax, %eax
	retq
.LBB8_7:
	movl	$1, %eax
	retq
.Lfunc_end8:
	.size	_Z5checkPfPS_i, .Lfunc_end8-_Z5checkPfPS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z12print_matrixPfii            # -- Begin function _Z12print_matrixPfii
	.type	_Z12print_matrixPfii,@function
_Z12print_matrixPfii:                   # @_Z12print_matrixPfii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdi, 8(%rsp)                   # 8-byte Spill
	testl	%esi, %esi
	jle	.LBB9_6
# %bb.1:                                # %.preheader.lr.ph
	movl	%edx, %ebx
	movl	%esi, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	%edx, %r12d
	xorl	%r13d, %r13d
	xorl	%ebp, %ebp
.LBB9_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB9_4 Depth 2
	testl	%ebx, %ebx
	jle	.LBB9_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB9_2 Depth=1
	movl	%r13d, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,4), %r14
	xorl	%r15d, %r15d
.LBB9_4:                                #   Parent Loop BB9_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%r15,4), %xmm0
	movl	$.L.str.3, %edi
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB9_4
.LBB9_5:                                # %._crit_edge
                                        #   in Loop: Header=BB9_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%rbp
	addl	%ebx, %r13d
	cmpq	16(%rsp), %rbp                  # 8-byte Folded Reload
	jne	.LBB9_2
.LBB9_6:                                # %._crit_edge13
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end9:
	.size	_Z12print_matrixPfii, .Lfunc_end9-_Z12print_matrixPfii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI10_0:
	.quad	0x412e848000000000              # double 1.0E+6
.LCPI10_1:
	.quad	0x3f50000000000000              # double 9.765625E-4
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI10_2:
	.long	0x3d800000                      # float 0.0625
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$2, %edi
	jne	.LBB10_2
# %bb.1:
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %r12d
	jmp	.LBB10_3
.LBB10_2:
	movl	$4096, %r12d                    # imm = 0x1000
	movl	$.L.str.5, %edi
	movl	$4096, %esi                     # imm = 0x1000
	xorl	%eax, %eax
	callq	printf
.LBB10_3:
	callq	_Z9init_seedv
	movl	%r12d, %edi
	movl	%r12d, %esi
	callq	_Z11getmemory2Dii
	movq	%rax, %r14
	movl	%r12d, %edi
	movl	%r12d, %esi
	callq	_Z11getmemory2Dii
	movq	%rax, %rbx
	movq	%r14, %rdi
	movl	%r12d, %esi
	callq	_Z10init2DrandPPfi
	movl	$_ZL3tv0, %edi
	xorl	%esi, %esi
	callq	gettimeofday
	imulq	$1000000, _ZL3tv0(%rip), %rax   # imm = 0xF4240
	addq	_ZL3tv0+8(%rip), %rax
	cvtsi2sd	%rax, %xmm0
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	movl	%r12d, %ebp
	testl	%r12d, %r12d
	jle	.LBB10_8
# %bb.4:                                # %.preheader.lr.ph.i
	xorl	%eax, %eax
.LBB10_5:                               # %.lr.ph.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB10_6 Depth 2
	movq	(%rbx,%rax,8), %rcx
	xorl	%edx, %edx
.LBB10_6:                               #   Parent Loop BB10_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	(%r14,%rdx,8), %rsi
	movss	(%rsi,%rax,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%rcx,%rdx,4)
	incq	%rdx
	cmpq	%rdx, %rbp
	jne	.LBB10_6
# %bb.7:                                # %._crit_edge.i
                                        #   in Loop: Header=BB10_5 Depth=1
	incq	%rax
	cmpq	%rbp, %rax
	jne	.LBB10_5
.LBB10_8:                               # %_Z11transpose2DPPfS0_i.exit
	movl	%r12d, %r13d
	imull	%r13d, %r13d
	leaq	(,%r13,4), %r15
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r15, %xmm0
	movsd	%xmm0, (%rsp)                   # 8-byte Spill
	movl	$_ZL3tv0, %edi
	xorl	%esi, %esi
	callq	gettimeofday
	imulq	$1000000, _ZL3tv0(%rip), %rax   # imm = 0xF4240
	addq	_ZL3tv0+8(%rip), %rax
	cvtsi2sd	%rax, %xmm1
	subsd	8(%rsp), %xmm1                  # 8-byte Folded Reload
	divsd	.LCPI10_0(%rip), %xmm1
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	divsd	%xmm1, %xmm0
	movsd	.LCPI10_1(%rip), %xmm1          # xmm1 = mem[0],zero
	mulsd	%xmm1, %xmm0
	mulsd	%xmm1, %xmm0
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	movl	%r12d, 8(%rsp)                  # 4-byte Spill
	leaq	32(%rsp), %r12
	movq	%r12, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	movq	(%r12), %rdi
	movl	8(%rsp), %r12d                  # 4-byte Reload
	movq	%r14, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	16(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r12d, %xmm0
	mulss	.LCPI10_2(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %r14d
	btsq	$32, %r14
	movl	$_ZL3tv0, %edi
	xorl	%esi, %esi
	callq	gettimeofday
	imulq	$1000000, _ZL3tv0(%rip), %rax   # imm = 0xF4240
	addq	_ZL3tv0+8(%rip), %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	movsd	%xmm0, 24(%rsp)                 # 8-byte Spill
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movq	%r14, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB10_10
# %bb.9:
	movq	32(%rsp), %rdi
	movq	16(%rsp), %rsi
	movl	%r12d, %edx
	movl	%r12d, %ecx
	callq	_Z34__device_stub__transpose_device_v3PfS_ii
.LBB10_10:
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, %r14
	movq	16(%rsp), %rsi
	movq	%rax, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	callq	hipDeviceSynchronize
	movl	$_ZL3tv0, %edi
	xorl	%esi, %esi
	callq	gettimeofday
	imulq	$1000000, _ZL3tv0(%rip), %rax   # imm = 0xF4240
	addq	_ZL3tv0+8(%rip), %rax
	xorps	%xmm1, %xmm1
	cvtsi2sd	%rax, %xmm1
	subsd	24(%rsp), %xmm1                 # 8-byte Folded Reload
	divsd	.LCPI10_0(%rip), %xmm1
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	divsd	%xmm1, %xmm0
	movsd	.LCPI10_1(%rip), %xmm1          # xmm1 = mem[0],zero
	mulsd	%xmm1, %xmm0
	mulsd	%xmm1, %xmm0
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	movl	$.Lstr, %edi
	callq	puts@PLT
	movq	%r14, (%rsp)                    # 8-byte Spill
	movq	%r14, %rdi
	movl	%r12d, %esi
	movl	%r12d, %edx
	callq	_Z12print_matrixPfii
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	testl	%r12d, %r12d
	jle	.LBB10_15
# %bb.11:                               # %.preheader.lr.ph
	xorl	%r15d, %r15d
.LBB10_12:                              # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB10_13 Depth 2
	movq	(%rbx,%r15,8), %r12
	xorl	%r14d, %r14d
.LBB10_13:                              #   Parent Loop BB10_12 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r12,%r14,4), %xmm0
	movl	$.L.str.3, %edi
	movb	$1, %al
	callq	printf
	incq	%r14
	cmpq	%r14, %rbp
	jne	.LBB10_13
# %bb.14:                               # %._crit_edge
                                        #   in Loop: Header=BB10_12 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%r15
	cmpq	%rbp, %r15
	jne	.LBB10_12
.LBB10_15:                              # %._crit_edge77
	cmpl	$0, 8(%rsp)                     # 4-byte Folded Reload
	movq	(%rsp), %r8                     # 8-byte Reload
	je	.LBB10_22
# %bb.16:                               # %.lr.ph.i65.preheader
	xorl	%eax, %eax
	xorl	%ecx, %ecx
.LBB10_17:                              # %.lr.ph.i65
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB10_19 Depth 2
	movl	%eax, %edx
	leaq	(%r8,%rdx,4), %rdx
	movq	(%rbx,%rcx,8), %rsi
	xorl	%edi, %edi
.LBB10_19:                              #   Parent Loop BB10_17 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%rdx,%rdi,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	ucomiss	(%rsi,%rdi,4), %xmm0
	jne	.LBB10_20
	jp	.LBB10_20
# %bb.18:                               #   in Loop: Header=BB10_19 Depth=2
	incq	%rdi
	cmpq	%rdi, %r13
	jne	.LBB10_19
# %bb.21:                               # %._crit_edge.i69
                                        #   in Loop: Header=BB10_17 Depth=1
	incq	%rcx
	addl	%r13d, %eax
	cmpq	%r13, %rcx
	jne	.LBB10_17
	jmp	.LBB10_22
.LBB10_20:                              # %_Z5checkPfPS_i.exit
	movl	$.Lstr.2, %edi
	callq	puts@PLT
.LBB10_22:                              # %_Z5checkPfPS_i.exit.thread
	movl	$1, %eax
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end10:
	.size	main, .Lfunc_end10-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB11_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB11_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z19transpose_device_v3PfS_ii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end11:
	.size	__hip_module_ctor, .Lfunc_end11-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB12_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB12_2:
	retq
.Lfunc_end12:
	.size	__hip_module_dtor, .Lfunc_end12-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_ZL3tv0,@object                 # @_ZL3tv0
	.local	_ZL3tv0
	.comm	_ZL3tv0,16,8
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"/dev/urandom"
	.size	.L.str, 13

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"r"
	.size	.L.str.1, 2

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"ERROR in memory allocation\n"
	.size	.L.str.2, 28

	.type	_Z19transpose_device_v3PfS_ii,@object # @_Z19transpose_device_v3PfS_ii
	.section	.rodata,"a",@progbits
	.globl	_Z19transpose_device_v3PfS_ii
	.p2align	3, 0x0
_Z19transpose_device_v3PfS_ii:
	.quad	_Z34__device_stub__transpose_device_v3PfS_ii
	.size	_Z19transpose_device_v3PfS_ii, 8

	.type	.L.str.3,@object                # @.str.3
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.3:
	.asciz	"%4.1f "
	.size	.L.str.3, 7

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"./exec n (by default n=%i)\n"
	.size	.L.str.5, 28

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Transpose version 2D: %f MB/s\n"
	.size	.L.str.6, 31

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Transpose kernel version: %f MB/s\n"
	.size	.L.str.7, 35

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z19transpose_device_v3PfS_ii"
	.size	.L__unnamed_1, 30

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Matriz GPU:"
	.size	.Lstr, 12

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Matriz CPU"
	.size	.Lstr.1, 11

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Transpose CPU-GPU differs!!"
	.size	.Lstr.2, 28

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z34__device_stub__transpose_device_v3PfS_ii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _ZL3tv0
	.addrsig_sym _Z19transpose_device_v3PfS_ii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z19transpose_device_v3PfS_ii ; -- Begin function _Z19transpose_device_v3PfS_ii
	.globl	_Z19transpose_device_v3PfS_ii
	.p2align	8
	.type	_Z19transpose_device_v3PfS_ii,@function
_Z19transpose_device_v3PfS_ii:          ; @_Z19transpose_device_v3PfS_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x24
	s_load_b64 s[2:3], s[0:1], 0x10
	v_and_b32_e32 v1, 0x3ff, v0
	v_bfe_u32 v0, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s5, s4, 16
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[2:3], null, s14, s4, v[1:2]
	v_mad_u64_u32 v[3:4], null, s15, s5, v[0:1]
	v_cmp_gt_i32_e32 vcc_lo, s2, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_gt_i32_e64 s2, s3, v3
	s_and_b32 s2, vcc_lo, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s4, s2
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b128 s[4:7], s[0:1], 0x0
	v_mad_u64_u32 v[4:5], null, v3, s3, v[2:3]
	v_lshlrev_b32_e32 v3, 2, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshl_add_u32 v6, v2, 6, v3
	v_ashrrev_i32_e32 v5, 31, v4
	v_mad_u64_u32 v[2:3], null, v1, s3, v[0:1]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[4:5], 2, v[4:5]
	v_ashrrev_i32_e32 v3, 31, v2
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v4, vcc_lo, s4, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v5, vcc_lo
	global_load_b32 v4, v[4:5], off
	v_lshlrev_b32_e32 v5, 2, v0
	s_delay_alu instid0(VALU_DEP_1)
	v_lshl_add_u32 v0, v1, 6, v5
	s_waitcnt vmcnt(0)
	ds_store_b32 v6, v4
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	ds_load_b32 v4, v0
	v_lshlrev_b64 v[0:1], 2, v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s6, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v1, vcc_lo
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[0:1], v4, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z19transpose_device_v3PfS_ii
		.amdhsa_group_segment_fixed_size 1024
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 7
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z19transpose_device_v3PfS_ii, .Lfunc_end0-_Z19transpose_device_v3PfS_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 292
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 1024 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 7
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 1024
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z19transpose_device_v3PfS_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z19transpose_device_v3PfS_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
