#include <math.h>
#include <stdio.h>

#define BDIM 256

__global__ void fast_transpose(double *a, double *b, int N) {
  // buffer
  __shared__ double buffer[BDIM];
  int y = blockIdx.y * blockDim.y + threadIdx.y;
  int x = blockIdx.x * blockDim.x + threadIdx.x;
  // doing the transposition on the shared memory
  buffer[threadIdx.y * blockDim.x + threadIdx.x] = a[y * N + x];
  __syncthreads();
  // copy back on global memory
  b[x * N + y] = buffer[threadIdx.y * blockDim.x + threadIdx.x];
}

// naive transpose
__global__ void transpose(double *a, double *b, int N) {
  int row = (blockIdx.x * blockDim.x + threadIdx.x) / N;
  int col = (blockIdx.x * blockDim.x + threadIdx.x) % N;
  b[col * N + row] = a[row * N + col];
}

// just randomlly fill the matrix
void random_fill(double *mat, int N) {
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      mat[i * N + j] = (double)rand() / (double)RAND_MAX * 100.;
}

// Used for error-checking
void transpose_cpu(double *a, double *b, int N) {
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      b[j * N + i] = a[i * N + j];
}

// check if two matrix are equals
int is_equal(double *a, double *b, int N) {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++)
      if (b[i * N + j] != a[i * N + j])
        return 0;
  }
  return 1;
}

void print_mat(double *a, int N) {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      printf("%.1f ", a[i * N + j]);
    }
    printf("\n");
  }
  printf("\n");
}

int main(int argc, char *argv[]) {

  double *a, *b, *c, *d; // host copies of a, b, c
  const int N = 8192;
  double *dev_a, *dev_b, *dev_c;     // device copies of a, b, c
  int size = N * N * sizeof(double); // we need space for 512
  // Get the number of block dimensions (dim1*dim2 = number of threads)
  if (argc < 3) {
    printf("Insert the dimensions, first x, second y\n");
    return -1;
  }
  // get block dimensions from command line
  const int dim1 = atoi(argv[1]);
  const int dim2 = atoi(argv[2]);
  const int Nblocks = (N * N) / 1024;
  if (dim1 * dim2 != BDIM) {
    printf("Give rigth dimensions\n");
    return -2;
  }
  dim3 grid, block;
  block.x = dim1;
  block.y = dim2;
  grid.x = N / block.x;
  grid.y = N / block.y;

  // allocate device copies of a, b, c
  cudaMalloc((void **)&dev_a, size);
  cudaMalloc((void **)&dev_b, size);
  a = (double *)malloc(size);
  b = (double *)malloc(size);
  d = (double *)malloc(size);
  // fill the matrix with random numbers
  random_fill(a, N);
  cudaMemcpy(dev_a, a, size, cudaMemcpyHostToDevice);
  // cuda event for timing
  cudaEvent_t start, stop;
  cudaEventCreate(&start);
  cudaEventCreate(&stop);

  cudaEventRecord(start);
  fast_transpose<<<grid, block>>>(dev_a, dev_b, N);
  cudaEventRecord(stop);
  cudaEventSynchronize(stop);
  float milliseconds = 0;
  cudaEventElapsedTime(&milliseconds, start, stop);
  cudaMemcpy(b, dev_b, size, cudaMemcpyDeviceToHost);
  //    print_mat(b,N);
  transpose_cpu(a, d, N);
  int equal = is_equal(b, d, N);
  if (equal)
    printf("Correct fast\n");
  else
    printf("Uncorrect fast\n");
  // Bandwith for reading from matrix a + writing on matrix b
  printf("Time fast= %f\n", milliseconds);
  printf("Bandwidth fast= %f\n", N * N * 2 * 8 / milliseconds / 1e6);
  free(b);
  cudaFree(dev_b);
  c = (double *)malloc(size);
  cudaMalloc((void **)&dev_c, size);

  cudaEventRecord(start);
  transpose<<<Nblocks, 1024>>>(dev_a, dev_c, N);
  cudaEventRecord(stop);
  cudaEventSynchronize(stop);
  cudaEventElapsedTime(&milliseconds, start, stop);
  cudaMemcpy(c, dev_c, size, cudaMemcpyDeviceToHost);
  equal = is_equal(c, d, N);
  if (equal)
    printf("Correct naive\n");
  else
    printf("Uncorrect naive\n");
  printf("Time naive = %f\n", milliseconds);
  printf("Bandwidth naive= %f\n", N * N * 2 * 8 / milliseconds / 1e6);
  free(a);
  free(c);
  free(d);
  cudaFree(dev_a);
  cudaFree(dev_c);
  return 0;
}

	.file	"tmpxft_002634fc_00000000-6_fast_transpose_256.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z11random_fillPdi
	.type	_Z11random_fillPdi, @function
_Z11random_fillPdi:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movslq	%esi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rbp, %r12
	movq	%rdi, %rbx
	salq	$3, %rbp
.L3:
	cmpl	%r12d, %r13d
	jge	.L9
	leaq	(%rbx,%rbp), %r14
.L4:
	call	rand@PLT
	addq	$8, %rbx
	cvtsi2sdl	%eax, %xmm0
	divsd	.LC0(%rip), %xmm0
	mulsd	.LC1(%rip), %xmm0
	movsd	%xmm0, -8(%rbx)
	cmpq	%r14, %rbx
	jne	.L4
	incl	%r13d
	jmp	.L3
.L9:
	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
.LFE2027:
	.size	_Z11random_fillPdi, .-_Z11random_fillPdi
	.globl	_Z13transpose_cpuPdS_i
	.type	_Z13transpose_cpuPdS_i, @function
_Z13transpose_cpuPdS_i:
.LFB2028:
	.cfi_startproc
	endbr64
	movslq	%edx, %rax
	xorl	%r8d, %r8d
	salq	$3, %rax
.L11:
	cmpl	%edx, %r8d
	jge	.L15
	movq	%rsi, %r9
	xorl	%ecx, %ecx
.L12:
	movsd	(%rdi,%rcx,8), %xmm0
	incq	%rcx
	movsd	%xmm0, (%r9)
	addq	%rax, %r9
	cmpl	%ecx, %edx
	jg	.L12
	incl	%r8d
	addq	$8, %rsi
	addq	%rax, %rdi
	jmp	.L11
.L15:
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z13transpose_cpuPdS_i, .-_Z13transpose_cpuPdS_i
	.globl	_Z8is_equalPdS_i
	.type	_Z8is_equalPdS_i, @function
_Z8is_equalPdS_i:
.LFB2029:
	.cfi_startproc
	endbr64
	movslq	%edx, %r8
	xorl	%r9d, %r9d
	xorl	%ecx, %ecx
	salq	$3, %r8
.L17:
	cmpl	%edx, %ecx
	jge	.L25
	movq	%r9, %rax
	xorl	%r10d, %r10d
.L20:
	movsd	(%rsi,%rax), %xmm0
	ucomisd	(%rdi,%rax), %xmm0
	jp	.L21
	jne	.L21
	incl	%r10d
	addq	$8, %rax
	cmpl	%r10d, %edx
	jne	.L20
	incl	%ecx
	addq	%r8, %r9
	jmp	.L17
.L25:
	movl	$1, %eax
	ret
.L21:
	xorl	%eax, %eax
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z8is_equalPdS_i, .-_Z8is_equalPdS_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"%.1f "
.LC3:
	.string	"\n"
	.text
	.globl	_Z9print_matPdi
	.type	_Z9print_matPdi, @function
_Z9print_matPdi:
.LFB2030:
	.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
	leaq	.LC2(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movslq	%esi, %r13
	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	%r13, %rbp
	salq	$3, %r13
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 64
.L27:
	cmpl	%ebp, %r12d
	jge	.L32
	leaq	(%rbx,%r13), %r15
.L28:
	movsd	(%rbx), %xmm0
	movq	%r14, %rsi
	movl	$2, %edi
	movb	$1, %al
	addq	$8, %rbx
	call	__printf_chk@PLT
	cmpq	%r15, %rbx
	jne	.L28
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incl	%r12d
	call	__printf_chk@PLT
	jmp	.L27
.L32:
	popq	%rdx
	.cfi_def_cfa_offset 56
	leaq	.LC3(%rip), %rsi
	popq	%rbx
	.cfi_def_cfa_offset 48
	movl	$2, %edi
	popq	%rbp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	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
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2030:
	.size	_Z9print_matPdi, .-_Z9print_matPdi
	.globl	_Z37__device_stub__Z14fast_transposePdS_iPdS_i
	.type	_Z37__device_stub__Z14fast_transposePdS_iPdS_i, @function
_Z37__device_stub__Z14fast_transposePdS_iPdS_i:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L33
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z14fast_transposePdS_i(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L33:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z37__device_stub__Z14fast_transposePdS_iPdS_i, .-_Z37__device_stub__Z14fast_transposePdS_iPdS_i
	.globl	_Z14fast_transposePdS_i
	.type	_Z14fast_transposePdS_i, @function
_Z14fast_transposePdS_i:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z37__device_stub__Z14fast_transposePdS_iPdS_i
	.cfi_endproc
.LFE2057:
	.size	_Z14fast_transposePdS_i, .-_Z14fast_transposePdS_i
	.globl	_Z31__device_stub__Z9transposePdS_iPdS_i
	.type	_Z31__device_stub__Z9transposePdS_iPdS_i, @function
_Z31__device_stub__Z9transposePdS_iPdS_i:
.LFB2058:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L38
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z9transposePdS_i(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L38:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L40
	call	__stack_chk_fail@PLT
.L40:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z31__device_stub__Z9transposePdS_iPdS_i, .-_Z31__device_stub__Z9transposePdS_iPdS_i
	.globl	_Z9transposePdS_i
	.type	_Z9transposePdS_i, @function
_Z9transposePdS_i:
.LFB2059:
	.cfi_startproc
	endbr64
	jmp	_Z31__device_stub__Z9transposePdS_iPdS_i
	.cfi_endproc
.LFE2059:
	.size	_Z9transposePdS_i, .-_Z9transposePdS_i
	.section	.rodata.str1.1
.LC4:
	.string	"Insert the dimensions, first x, second y\n"
.LC5:
	.string	"Give rigth dimensions\n"
.LC7:
	.string	"Correct fast\n"
.LC8:
	.string	"Uncorrect fast\n"
.LC9:
	.string	"Time fast= %f\n"
.LC12:
	.string	"Bandwidth fast= %f\n"
.LC13:
	.string	"Correct naive\n"
.LC14:
	.string	"Uncorrect naive\n"
.LC15:
	.string	"Time naive = %f\n"
.LC16:
	.string	"Bandwidth naive= %f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	cmpl	$2, %edi
	jg	.L44
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	orl	$-1, %eax
	jmp	.L43
.L44:
	movq	8(%rsi), %rdi
	movq	%rsi, %rbx
	call	atoi@PLT
	movq	16(%rbx), %rdi
	movl	%eax, %r13d
	call	atoi@PLT
	movl	%eax, %r12d
	movl	%r13d, %eax
	imull	%r12d, %eax
	cmpl	$256, %eax
	je	.L46
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$-2, %eax
	jmp	.L43
.L46:
	movl	$8192, %ecx
	xorl	%edx, %edx
	leaq	16(%rsp), %rdi
	movl	$536870912, %esi
	movl	%ecx, %eax
	movl	$1, 64(%rsp)
	divl	%r13d
	movl	$1, 76(%rsp)
	xorl	%edx, %edx
	movl	%eax, 56(%rsp)
	movl	%ecx, %eax
	divl	%r12d
	movl	%eax, 60(%rsp)
	call	cudaMalloc@PLT
	movl	$536870912, %esi
	leaq	24(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	$536870912, %edi
	call	malloc@PLT
	movl	$536870912, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movl	$536870912, %edi
	movq	%rax, %r14
	call	malloc@PLT
	movl	$8192, %esi
	movq	%rbp, %rdi
	movq	%rax, %rbx
	call	_Z11random_fillPdi
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$536870912, %edx
	call	cudaMemcpy@PLT
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	48(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%r13d, 68(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	76(%rsp), %ecx
	movq	56(%rsp), %rdi
	movl	%r12d, 72(%rsp)
	movl	64(%rsp), %esi
	movq	68(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L47
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdi
	movl	$8192, %edx
	call	_Z37__device_stub__Z14fast_transposePdS_iPdS_i
.L47:
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	leaq	12(%rsp), %r13
	call	cudaEventRecord@PLT
	movq	48(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	48(%rsp), %rdx
	movq	%r13, %rdi
	movq	40(%rsp), %rsi
	movl	$0x00000000, 12(%rsp)
	call	cudaEventElapsedTime@PLT
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	movq	%r14, %rdi
	movl	$536870912, %edx
	call	cudaMemcpy@PLT
	movl	$8192, %edx
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	call	_Z13transpose_cpuPdS_i
	movq	%rbx, %rsi
	movq	%r14, %rdi
	call	_Z8is_equalPdS_i
	leaq	.LC7(%rip), %rsi
	testl	%eax, %eax
	jne	.L55
	leaq	.LC8(%rip), %rsi
.L55:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	12(%rsp), %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC12(%rip), %rsi
	movss	.LC10(%rip), %xmm0
	divss	12(%rsp), %xmm0
	cvtss2sd	%xmm0, %xmm0
	divsd	.LC11(%rip), %xmm0
	call	__printf_chk@PLT
	movq	%r14, %rdi
	call	free@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movl	$536870912, %edi
	call	malloc@PLT
	leaq	32(%rsp), %rdi
	movl	$536870912, %esi
	movq	%rax, %r12
	call	cudaMalloc@PLT
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$65537, %edi
	salq	$10, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	salq	$16, %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L50
	movq	32(%rsp), %rsi
	movq	16(%rsp), %rdi
	movl	$8192, %edx
	call	_Z31__device_stub__Z9transposePdS_iPdS_i
.L50:
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	48(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	48(%rsp), %rdx
	movq	40(%rsp), %rsi
	movq	%r13, %rdi
	call	cudaEventElapsedTime@PLT
	movq	32(%rsp), %rsi
	movl	$2, %ecx
	movq	%r12, %rdi
	movl	$536870912, %edx
	call	cudaMemcpy@PLT
	movq	%rbx, %rsi
	movl	$8192, %edx
	movq	%r12, %rdi
	call	_Z8is_equalPdS_i
	leaq	.LC13(%rip), %rsi
	testl	%eax, %eax
	jne	.L56
	leaq	.LC14(%rip), %rsi
.L56:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	12(%rsp), %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC16(%rip), %rsi
	movss	.LC10(%rip), %xmm0
	divss	12(%rsp), %xmm0
	cvtss2sd	%xmm0, %xmm0
	divsd	.LC11(%rip), %xmm0
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	xorl	%eax, %eax
.L43:
	movq	104(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L53
	call	__stack_chk_fail@PLT
.L53:
	addq	$112, %rsp
	.cfi_def_cfa_offset 48
	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
.LFE2031:
	.size	main, .-main
	.section	.rodata.str1.1
.LC17:
	.string	"_Z9transposePdS_i"
.LC18:
	.string	"_Z14fast_transposePdS_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2061:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -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
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z9transposePdS_i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC18(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z14fast_transposePdS_i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	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	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2061:
	.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
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	-4194304
	.long	1105199103
	.align 8
.LC1:
	.long	0
	.long	1079574528
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC10:
	.long	1317011456
	.section	.rodata.cst8
	.align 8
.LC11:
	.long	0
	.long	1093567616
	.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 <hip/hip_runtime.h>
#include <math.h>
#include <stdio.h>

#define BDIM 256

__global__ void fast_transpose(double *a, double *b, int N) {
  // buffer
  __shared__ double buffer[BDIM];
  int y = blockIdx.y * blockDim.y + threadIdx.y;
  int x = blockIdx.x * blockDim.x + threadIdx.x;
  // doing the transposition on the shared memory
  buffer[threadIdx.y * blockDim.x + threadIdx.x] = a[y * N + x];
  __syncthreads();
  // copy back on global memory
  b[x * N + y] = buffer[threadIdx.y * blockDim.x + threadIdx.x];
}

// naive transpose
__global__ void transpose(double *a, double *b, int N) {
  int row = (blockIdx.x * blockDim.x + threadIdx.x) / N;
  int col = (blockIdx.x * blockDim.x + threadIdx.x) % N;
  b[col * N + row] = a[row * N + col];
}

// just randomlly fill the matrix
void random_fill(double *mat, int N) {
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      mat[i * N + j] = (double)rand() / (double)RAND_MAX * 100.;
}

// Used for error-checking
void transpose_cpu(double *a, double *b, int N) {
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      b[j * N + i] = a[i * N + j];
}

// check if two matrix are equals
int is_equal(double *a, double *b, int N) {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++)
      if (b[i * N + j] != a[i * N + j])
        return 0;
  }
  return 1;
}

void print_mat(double *a, int N) {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      printf("%.1f ", a[i * N + j]);
    }
    printf("\n");
  }
  printf("\n");
}

int main(int argc, char *argv[]) {

  double *a, *b, *c, *d; // host copies of a, b, c
  const int N = 8192;
  double *dev_a, *dev_b, *dev_c;     // device copies of a, b, c
  int size = N * N * sizeof(double); // we need space for 512
  // Get the number of block dimensions (dim1*dim2 = number of threads)
  if (argc < 3) {
    printf("Insert the dimensions, first x, second y\n");
    return -1;
  }
  // get block dimensions from command line
  const int dim1 = atoi(argv[1]);
  const int dim2 = atoi(argv[2]);
  const int Nblocks = (N * N) / 1024;
  if (dim1 * dim2 != BDIM) {
    printf("Give rigth dimensions\n");
    return -2;
  }
  dim3 grid, block;
  block.x = dim1;
  block.y = dim2;
  grid.x = N / block.x;
  grid.y = N / block.y;

  // allocate device copies of a, b, c
  hipMalloc((void **)&dev_a, size);
  hipMalloc((void **)&dev_b, size);
  a = (double *)malloc(size);
  b = (double *)malloc(size);
  d = (double *)malloc(size);
  // fill the matrix with random numbers
  random_fill(a, N);
  hipMemcpy(dev_a, a, size, hipMemcpyHostToDevice);
  // cuda event for timing
  hipEvent_t start, stop;
  hipEventCreate(&start);
  hipEventCreate(&stop);

  hipEventRecord(start);
  fast_transpose<<<grid, block>>>(dev_a, dev_b, N);
  hipEventRecord(stop);
  hipEventSynchronize(stop);
  float milliseconds = 0;
  hipEventElapsedTime(&milliseconds, start, stop);
  hipMemcpy(b, dev_b, size, hipMemcpyDeviceToHost);
  //    print_mat(b,N);
  transpose_cpu(a, d, N);
  int equal = is_equal(b, d, N);
  if (equal)
    printf("Correct fast\n");
  else
    printf("Uncorrect fast\n");
  // Bandwith for reading from matrix a + writing on matrix b
  printf("Time fast= %f\n", milliseconds);
  printf("Bandwidth fast= %f\n", N * N * 2 * 8 / milliseconds / 1e6);
  free(b);
  hipFree(dev_b);
  c = (double *)malloc(size);
  hipMalloc((void **)&dev_c, size);

  hipEventRecord(start);
  transpose<<<Nblocks, 1024>>>(dev_a, dev_c, N);
  hipEventRecord(stop);
  hipEventSynchronize(stop);
  hipEventElapsedTime(&milliseconds, start, stop);
  hipMemcpy(c, dev_c, size, hipMemcpyDeviceToHost);
  equal = is_equal(c, d, N);
  if (equal)
    printf("Correct naive\n");
  else
    printf("Uncorrect naive\n");
  printf("Time naive = %f\n", milliseconds);
  printf("Bandwidth naive= %f\n", N * N * 2 * 8 / milliseconds / 1e6);
  free(a);
  free(c);
  free(d);
  hipFree(dev_a);
  hipFree(dev_c);
  return 0;
}

	.text
	.file	"fast_transpose_256.hip"
	.globl	_Z29__device_stub__fast_transposePdS_i # -- Begin function _Z29__device_stub__fast_transposePdS_i
	.type	_Z29__device_stub__fast_transposePdS_i,@function
_Z29__device_stub__fast_transposePdS_i: # @_Z29__device_stub__fast_transposePdS_i
	.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), %rcx
	movq	%rsi, (%rcx)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%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	$_Z14fast_transposePdS_i, %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_end0:
	.size	_Z29__device_stub__fast_transposePdS_i, .Lfunc_end0-_Z29__device_stub__fast_transposePdS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z24__device_stub__transposePdS_i # -- Begin function _Z24__device_stub__transposePdS_i
	.type	_Z24__device_stub__transposePdS_i,@function
_Z24__device_stub__transposePdS_i:      # @_Z24__device_stub__transposePdS_i
	.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), %rcx
	movq	%rsi, (%rcx)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%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	$_Z9transposePdS_i, %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_end1:
	.size	_Z24__device_stub__transposePdS_i, .Lfunc_end1-_Z24__device_stub__transposePdS_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z11random_fillPdi
.LCPI2_0:
	.quad	0x41dfffffffc00000              # double 2147483647
.LCPI2_1:
	.quad	0x4059000000000000              # double 100
	.text
	.globl	_Z11random_fillPdi
	.type	_Z11random_fillPdi,@function
_Z11random_fillPdi:                     # @_Z11random_fillPdi
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.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, (%rsp)                    # 8-byte Spill
	testl	%esi, %esi
	jle	.LBB2_5
# %bb.1:                                # %.preheader.lr.ph
	movl	%esi, %ebx
	movl	%esi, %r15d
	xorl	%r12d, %r12d
	xorl	%r13d, %r13d
.LBB2_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_3 Depth 2
	movl	%r12d, %eax
	movq	(%rsp), %rcx                    # 8-byte Reload
	leaq	(%rcx,%rax,8), %rbp
	xorl	%r14d, %r14d
.LBB2_3:                                #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	movsd	.LCPI2_0(%rip), %xmm1           # xmm1 = mem[0],zero
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	%xmm1, %xmm0
	movsd	.LCPI2_1(%rip), %xmm1           # xmm1 = mem[0],zero
	mulsd	%xmm1, %xmm0
	movsd	%xmm0, (%rbp,%r14,8)
	incq	%r14
	cmpq	%r14, %r15
	jne	.LBB2_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	incq	%r13
	addl	%ebx, %r12d
	cmpq	%r15, %r13
	jne	.LBB2_2
.LBB2_5:                                # %._crit_edge13
	addq	$8, %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_end2:
	.size	_Z11random_fillPdi, .Lfunc_end2-_Z11random_fillPdi
	.cfi_endproc
                                        # -- End function
	.globl	_Z13transpose_cpuPdS_i          # -- Begin function _Z13transpose_cpuPdS_i
	.type	_Z13transpose_cpuPdS_i,@function
_Z13transpose_cpuPdS_i:                 # @_Z13transpose_cpuPdS_i
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB3_6
# %bb.1:                                # %.preheader.lr.ph
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	%edx, %eax
	leaq	(,%rax,8), %rcx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
.LBB3_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_3 Depth 2
	movl	%r8d, %r10d
	leaq	(%rdi,%r10,8), %r10
	movq	%rsi, %r11
	xorl	%ebx, %ebx
.LBB3_3:                                #   Parent Loop BB3_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%r10,%rbx,8), %xmm0            # xmm0 = mem[0],zero
	movsd	%xmm0, (%r11)
	incq	%rbx
	addq	%rcx, %r11
	cmpq	%rbx, %rax
	jne	.LBB3_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB3_2 Depth=1
	incq	%r9
	addl	%edx, %r8d
	addq	$8, %rsi
	cmpq	%rax, %r9
	jne	.LBB3_2
# %bb.5:
	popq	%rbx
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
.LBB3_6:                                # %._crit_edge17
	retq
.Lfunc_end3:
	.size	_Z13transpose_cpuPdS_i, .Lfunc_end3-_Z13transpose_cpuPdS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z8is_equalPdS_i                # -- Begin function _Z8is_equalPdS_i
	.type	_Z8is_equalPdS_i,@function
_Z8is_equalPdS_i:                       # @_Z8is_equalPdS_i
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB4_1
# %bb.3:                                # %.preheader.lr.ph
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	%edx, %eax
	xorl	%ecx, %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
.LBB4_4:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_6 Depth 2
	movl	%ecx, %r11d
	leaq	(%rdi,%r11,8), %r10
	leaq	(%rsi,%r11,8), %r11
	xorl	%ebx, %ebx
.LBB4_6:                                #   Parent Loop BB4_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%r11,%rbx,8), %xmm0            # xmm0 = mem[0],zero
	ucomisd	(%r10,%rbx,8), %xmm0
	jne	.LBB4_8
	jp	.LBB4_8
# %bb.5:                                #   in Loop: Header=BB4_6 Depth=2
	incq	%rbx
	cmpq	%rbx, %rax
	jne	.LBB4_6
# %bb.7:                                # %._crit_edge
                                        #   in Loop: Header=BB4_4 Depth=1
	incq	%r9
	cmpq	%rax, %r9
	setae	%r8b
	addl	%edx, %ecx
	cmpq	%rax, %r9
	jne	.LBB4_4
.LBB4_8:
	popq	%rbx
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	jmp	.LBB4_2
.LBB4_1:
	movb	$1, %r8b
.LBB4_2:                                # %.thread
	movzbl	%r8b, %eax
	andl	$1, %eax
	retq
.Lfunc_end4:
	.size	_Z8is_equalPdS_i, .Lfunc_end4-_Z8is_equalPdS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z9print_matPdi                 # -- Begin function _Z9print_matPdi
	.type	_Z9print_matPdi,@function
_Z9print_matPdi:                        # @_Z9print_matPdi
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.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, (%rsp)                    # 8-byte Spill
	testl	%esi, %esi
	jle	.LBB5_5
# %bb.1:                                # %.preheader.lr.ph
	movl	%esi, %ebx
	movl	%esi, %r15d
	xorl	%r12d, %r12d
	xorl	%r13d, %r13d
.LBB5_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_3 Depth 2
	movl	%r12d, %eax
	movq	(%rsp), %rcx                    # 8-byte Reload
	leaq	(%rcx,%rax,8), %rbp
	xorl	%r14d, %r14d
.LBB5_3:                                #   Parent Loop BB5_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rbp,%r14,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str, %edi
	movb	$1, %al
	callq	printf
	incq	%r14
	cmpq	%r14, %r15
	jne	.LBB5_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB5_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%r13
	addl	%ebx, %r12d
	cmpq	%r15, %r13
	jne	.LBB5_2
.LBB5_5:                                # %._crit_edge14
	movl	$10, %edi
	addq	$8, %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
	jmp	putchar@PLT                     # TAILCALL
.Lfunc_end5:
	.size	_Z9print_matPdi, .Lfunc_end5-_Z9print_matPdi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI6_0:
	.quad	0x41dfffffffc00000              # double 2147483647
.LCPI6_1:
	.quad	0x4059000000000000              # double 100
.LCPI6_3:
	.quad	0x412e848000000000              # double 1.0E+6
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI6_2:
	.long	0x4e800000                      # float 1.07374182E+9
	.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	$88, %rsp
	.cfi_def_cfa_offset 144
	.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
	jg	.LBB6_2
# %bb.1:
	movl	$.Lstr.5, %edi
	callq	puts@PLT
	movl	$-1, %eax
	jmp	.LBB6_27
.LBB6_2:
	movq	%rsi, %rbx
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %ebp
	movq	16(%rbx), %rdi
	callq	atoi
	movl	%eax, %ecx
	imull	%ebp, %eax
	cmpl	$256, %eax                      # imm = 0x100
	jne	.LBB6_3
# %bb.4:
	movq	%rcx, %r12
	shlq	$32, %r12
	xorl	%r14d, %r14d
	movl	$8192, %eax                     # imm = 0x2000
	xorl	%edx, %edx
	divl	%ebp
	movl	%eax, 60(%rsp)                  # 4-byte Spill
	movl	$8192, %eax                     # imm = 0x2000
	xorl	%edx, %edx
	divl	%ecx
	movl	%eax, %r13d
	shlq	$32, %r13
	leaq	24(%rsp), %rdi
	movl	$536870912, %esi                # imm = 0x20000000
	callq	hipMalloc
	leaq	48(%rsp), %rdi
	movl	$536870912, %esi                # imm = 0x20000000
	callq	hipMalloc
	movl	$536870912, %edi                # imm = 0x20000000
	callq	malloc
	movq	%rax, %r15
	movl	$536870912, %edi                # imm = 0x20000000
	callq	malloc
	movq	%rax, 64(%rsp)                  # 8-byte Spill
	movl	$536870912, %edi                # imm = 0x20000000
	callq	malloc
	movq	%rax, 72(%rsp)                  # 8-byte Spill
	movq	%r15, 80(%rsp)                  # 8-byte Spill
.LBB6_5:                                # %.lr.ph.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_6 Depth 2
	xorl	%ebx, %ebx
.LBB6_6:                                #   Parent Loop BB6_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	movsd	.LCPI6_0(%rip), %xmm1           # xmm1 = mem[0],zero
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	%xmm1, %xmm0
	movsd	.LCPI6_1(%rip), %xmm1           # xmm1 = mem[0],zero
	mulsd	%xmm1, %xmm0
	movsd	%xmm0, (%r15,%rbx,8)
	incq	%rbx
	cmpq	$8192, %rbx                     # imm = 0x2000
	jne	.LBB6_6
# %bb.7:                                # %._crit_edge.i
                                        #   in Loop: Header=BB6_5 Depth=1
	incq	%r14
	addq	$65536, %r15                    # imm = 0x10000
	cmpq	$8192, %r14                     # imm = 0x2000
	jne	.LBB6_5
# %bb.8:                                # %_Z11random_fillPdi.exit
	movl	%ebp, %eax
	orq	%rax, %r12
	movl	60(%rsp), %eax                  # 4-byte Reload
	orq	%rax, %r13
	movq	24(%rsp), %rdi
	movl	$536870912, %edx                # imm = 0x20000000
	movq	80(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	32(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventCreate
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	movq	(%rbx), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_10
# %bb.9:
	movq	24(%rsp), %rdi
	movq	48(%rsp), %rsi
	movl	$8192, %edx                     # imm = 0x2000
	callq	_Z29__device_stub__fast_transposePdS_i
.LBB6_10:
	movq	16(%rsp), %rdi
	xorl	%ebx, %ebx
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	leaq	12(%rsp), %rdi
	movl	$0, (%rdi)
	movq	32(%rsp), %rsi
	movq	16(%rsp), %rdx
	callq	hipEventElapsedTime
	movq	48(%rsp), %rsi
	movl	$536870912, %edx                # imm = 0x20000000
	movq	64(%rsp), %r15                  # 8-byte Reload
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	%r14, %rax
	movq	72(%rsp), %r12                  # 8-byte Reload
	movq	%r12, %rcx
.LBB6_11:                               # %.lr.ph.i52
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_12 Depth 2
	movq	%rcx, %rdx
	xorl	%esi, %esi
.LBB6_12:                               #   Parent Loop BB6_11 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rax,%rsi,8), %xmm0            # xmm0 = mem[0],zero
	movsd	%xmm0, (%rdx)
	incq	%rsi
	addq	$65536, %rdx                    # imm = 0x10000
	cmpq	$8192, %rsi                     # imm = 0x2000
	jne	.LBB6_12
# %bb.13:                               # %._crit_edge.i58
                                        #   in Loop: Header=BB6_11 Depth=1
	incq	%rbx
	addq	$8, %rcx
	addq	$65536, %rax                    # imm = 0x10000
	cmpq	$8192, %rbx                     # imm = 0x2000
	jne	.LBB6_11
# %bb.14:                               # %.lr.ph.i59.preheader
	xorl	%edi, %edi
	movl	$65536, %eax                    # imm = 0x10000
	movq	%r12, %rcx
	movq	%r15, %rsi
	xorl	%edx, %edx
.LBB6_15:                               # %.lr.ph.i59
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_17 Depth 2
	xorl	%r8d, %r8d
.LBB6_17:                               #   Parent Loop BB6_15 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rcx,%r8,8), %xmm0             # xmm0 = mem[0],zero
	ucomisd	(%rsi,%r8,8), %xmm0
	jne	.LBB6_19
	jp	.LBB6_19
# %bb.16:                               #   in Loop: Header=BB6_17 Depth=2
	incq	%r8
	cmpq	$8192, %r8                      # imm = 0x2000
	jne	.LBB6_17
# %bb.18:                               # %._crit_edge.i63
                                        #   in Loop: Header=BB6_15 Depth=1
	cmpq	$8191, %rdi                     # imm = 0x1FFF
	leaq	1(%rdi), %r8
	setae	%dl
	addq	%rax, %rsi
	addq	%rax, %rcx
	movq	%r8, %rdi
	cmpq	$8192, %r8                      # imm = 0x2000
	jne	.LBB6_15
.LBB6_19:                               # %_Z8is_equalPdS_i.exit
	movl	$.Lstr.1, %eax
	movl	$.Lstr, %edi
	testb	$1, %dl
	cmovneq	%rax, %rdi
	callq	puts@PLT
	xorps	%xmm0, %xmm0
	cvtss2sd	12(%rsp), %xmm0
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	movss	.LCPI6_2(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	divss	12(%rsp), %xmm0
	cvtss2sd	%xmm0, %xmm0
	divsd	.LCPI6_3(%rip), %xmm0
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	movq	%r15, %rdi
	callq	free
	movq	48(%rsp), %rdi
	callq	hipFree
	movl	$536870912, %edi                # imm = 0x20000000
	callq	malloc
	movq	%rax, %r15
	leaq	40(%rsp), %rdi
	movl	$536870912, %esi                # imm = 0x20000000
	callq	hipMalloc
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movabsq	$4294968320, %rdx               # imm = 0x100000400
	leaq	64512(%rdx), %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_21
# %bb.20:
	movq	24(%rsp), %rdi
	movq	40(%rsp), %rsi
	movl	$8192, %edx                     # imm = 0x2000
	callq	_Z24__device_stub__transposePdS_i
.LBB6_21:
	movq	16(%rsp), %rdi
	xorl	%ebx, %ebx
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	movq	32(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	12(%rsp), %rdi
	callq	hipEventElapsedTime
	movq	40(%rsp), %rsi
	movl	$536870912, %edx                # imm = 0x20000000
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$65536, %eax                    # imm = 0x10000
	movq	%r12, %rcx
	movq	%r15, %rsi
	xorl	%edx, %edx
.LBB6_22:                               # %.lr.ph.i64
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_24 Depth 2
	xorl	%edi, %edi
.LBB6_24:                               #   Parent Loop BB6_22 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rcx,%rdi,8), %xmm0            # xmm0 = mem[0],zero
	ucomisd	(%rsi,%rdi,8), %xmm0
	jne	.LBB6_26
	jp	.LBB6_26
# %bb.23:                               #   in Loop: Header=BB6_24 Depth=2
	incq	%rdi
	cmpq	$8192, %rdi                     # imm = 0x2000
	jne	.LBB6_24
# %bb.25:                               # %._crit_edge.i70
                                        #   in Loop: Header=BB6_22 Depth=1
	cmpq	$8191, %rbx                     # imm = 0x1FFF
	leaq	1(%rbx), %rdi
	setae	%dl
	addq	%rax, %rsi
	addq	%rax, %rcx
	movq	%rdi, %rbx
	cmpq	$8192, %rdi                     # imm = 0x2000
	jne	.LBB6_22
.LBB6_26:                               # %_Z8is_equalPdS_i.exit76
	movl	$.Lstr.3, %eax
	movl	$.Lstr.2, %edi
	testb	$1, %dl
	cmovneq	%rax, %rdi
	callq	puts@PLT
	xorps	%xmm0, %xmm0
	cvtss2sd	12(%rsp), %xmm0
	movl	$.L.str.10, %edi
	movb	$1, %al
	callq	printf
	movss	.LCPI6_2(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	divss	12(%rsp), %xmm0
	cvtss2sd	%xmm0, %xmm0
	divsd	.LCPI6_3(%rip), %xmm0
	movl	$.L.str.11, %edi
	movb	$1, %al
	callq	printf
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	%r12, %rdi
	callq	free
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	jmp	.LBB6_27
.LBB6_3:
	movl	$.Lstr.4, %edi
	callq	puts@PLT
	movl	$-2, %eax
.LBB6_27:
	addq	$88, %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_end6:
	.size	main, .Lfunc_end6-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:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14fast_transposePdS_i, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9transposePdS_i, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__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	.LBB8_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
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z14fast_transposePdS_i,@object # @_Z14fast_transposePdS_i
	.section	.rodata,"a",@progbits
	.globl	_Z14fast_transposePdS_i
	.p2align	3, 0x0
_Z14fast_transposePdS_i:
	.quad	_Z29__device_stub__fast_transposePdS_i
	.size	_Z14fast_transposePdS_i, 8

	.type	_Z9transposePdS_i,@object       # @_Z9transposePdS_i
	.globl	_Z9transposePdS_i
	.p2align	3, 0x0
_Z9transposePdS_i:
	.quad	_Z24__device_stub__transposePdS_i
	.size	_Z9transposePdS_i, 8

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

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Time fast= %f\n"
	.size	.L.str.6, 15

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Bandwidth fast= %f\n"
	.size	.L.str.7, 20

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Time naive = %f\n"
	.size	.L.str.10, 17

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Bandwidth naive= %f\n"
	.size	.L.str.11, 21

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z14fast_transposePdS_i"
	.size	.L__unnamed_1, 24

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z9transposePdS_i"
	.size	.L__unnamed_2, 18

	.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	"Uncorrect fast"
	.size	.Lstr, 15

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Correct fast"
	.size	.Lstr.1, 13

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Uncorrect naive"
	.size	.Lstr.2, 16

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Correct naive"
	.size	.Lstr.3, 14

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"Give rigth dimensions"
	.size	.Lstr.4, 22

	.type	.Lstr.5,@object                 # @str.5
.Lstr.5:
	.asciz	"Insert the dimensions, first x, second y"
	.size	.Lstr.5, 41

	.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 _Z29__device_stub__fast_transposePdS_i
	.addrsig_sym _Z24__device_stub__transposePdS_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z14fast_transposePdS_i
	.addrsig_sym _Z9transposePdS_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14fast_transposePdS_i ; -- Begin function _Z14fast_transposePdS_i
	.globl	_Z14fast_transposePdS_i
	.p2align	8
	.type	_Z14fast_transposePdS_i,@function
_Z14fast_transposePdS_i:                ; @_Z14fast_transposePdS_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x24
	s_load_b32 s4, s[0:1], 0x10
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v0, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s5, s2, 0xffff
	v_mad_u64_u32 v[2:3], null, s15, s3, v[1:2]
	v_mad_u64_u32 v[3:4], null, s14, s5, v[0:1]
	s_load_b128 s[0:3], s[0:1], 0x0
	v_mul_u32_u24_e32 v1, s5, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_lshl_u32 v6, v1, v0, 3
	v_mad_u64_u32 v[4:5], null, v2, s4, v[3:4]
	v_mad_u64_u32 v[0:1], null, v3, s4, v[2:3]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v5, 31, v4
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[4:5], 3, v[4:5]
	v_lshlrev_b64 v[0:1], 3, v[0:1]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v4, vcc_lo, s0, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s1, v5, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v0, vcc_lo, s2, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	global_load_b64 v[4:5], v[4:5], off
	s_waitcnt vmcnt(0)
	ds_store_b64 v6, v[4:5]
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	ds_load_b64 v[2:3], v6
	s_waitcnt lgkmcnt(0)
	global_store_b64 v[0:1], v[2:3], off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14fast_transposePdS_i
		.amdhsa_group_segment_fixed_size 2048
		.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	_Z14fast_transposePdS_i, .Lfunc_end0-_Z14fast_transposePdS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 244
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 2048 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
	.protected	_Z9transposePdS_i       ; -- Begin function _Z9transposePdS_i
	.globl	_Z9transposePdS_i
	.p2align	8
	.type	_Z9transposePdS_i,@function
_Z9transposePdS_i:                      ; @_Z9transposePdS_i
; %bb.0:
	s_clause 0x2
	s_load_b32 s2, s[0:1], 0x24
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b32 s0, s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_sub_i32 s1, 0, s0
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	v_cvt_f32_u32_e32 v0, s0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_rcp_iflag_f32_e32 v0, v0
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[2:3], 3, v[1:2]
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v0, 0x4f7ffffe, v0
	v_add_co_u32 v2, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
	v_cvt_u32_f32_e32 v0, v0
	global_load_b64 v[2:3], v[2:3], off
	v_mul_lo_u32 v4, s1, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_hi_u32 v4, v0, v4
	v_add_nc_u32_e32 v0, v0, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_hi_u32 v0, v1, v0
	v_mul_lo_u32 v4, v0, s0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v4, v1, v4
	v_subrev_nc_u32_e32 v6, s0, v4
	v_cmp_le_u32_e32 vcc_lo, s0, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_cndmask_b32 v4, v4, v6 :: v_dual_add_nc_u32 v5, 1, v0
	v_cndmask_b32_e32 v0, v0, v5, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_le_u32_e32 vcc_lo, s0, v4
	v_add_nc_u32_e32 v5, 1, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v0, v0, v5, vcc_lo
	v_mul_lo_u32 v4, v0, s0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v1, v1, v4
	v_mad_u64_u32 v[4:5], null, v1, s0, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v5, 31, v4
	v_lshlrev_b64 v[0:1], 3, v[4:5]
	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 vmcnt(0)
	global_store_b64 v[0:1], v[2:3], off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9transposePdS_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 15
		.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 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.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_end1:
	.size	_Z9transposePdS_i, .Lfunc_end1-_Z9transposePdS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 292
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 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: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.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:         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: 2048
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14fast_transposePdS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z14fast_transposePdS_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .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:         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: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z9transposePdS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z9transposePdS_i.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
