#include <stdio.h>
#include <cuda_runtime.h>

// Define block size
#define BLOCK_DIM 32

// CUDA kernel for matrix transposition with coalesced memory access
__global__ void transposeCoalesced(float *input, float *output, int width, int height) {
    // Use shared memory to avoid bank conflicts
    __shared__ float tile[BLOCK_DIM][BLOCK_DIM+1]; // +1 to avoid bank conflicts
    
    // Calculate input and output indices
    int x = blockIdx.x * BLOCK_DIM + threadIdx.x;
    int y = blockIdx.y * BLOCK_DIM + threadIdx.y;
    
    // Boundary check for input
    if (x < width && y < height) {
        // Load data from global memory to shared memory in a coalesced manner
        tile[threadIdx.y][threadIdx.x] = input[y * width + x];
    }
    
    // Ensure all threads finish loading into shared memory
    __syncthreads();
    
    // Calculate transposed indices
    int out_x = blockIdx.y * BLOCK_DIM + threadIdx.x;
    int out_y = blockIdx.x * BLOCK_DIM + threadIdx.y;
    
    // Boundary check for output
    if (out_x < height && out_y < width) {
        // Write from shared memory to global memory in a coalesced manner
        output[out_y * height + out_x] = tile[threadIdx.x][threadIdx.y];
    }
}

// Helper function to check for CUDA errors
void checkCudaError(cudaError_t err, const char* msg) {
    if (err != cudaSuccess) {
        fprintf(stderr, "%s: %s\n", msg, cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }
}

int main(int argc, char **argv) {
    // Matrix dimensions
    int width = 4096;  // Feel free to change these
    int height = 4096;
    
    size_t size = width * height * sizeof(float);
    
    // Host memory allocation
    float *h_input = (float*)malloc(size);
    float *h_output = (float*)malloc(size);
    
    // Initialize input matrix
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            h_input[i * width + j] = (float)(i * width + j);
        }
    }
    
    // Device memory allocation
    float *d_input, *d_output;
    cudaMalloc((void**)&d_input, size);
    cudaMalloc((void**)&d_output, size);
    
    // Copy input data from host to device
    cudaMemcpy(d_input, h_input, size, cudaMemcpyHostToDevice);
    
    // Define grid and block dimensions
    dim3 blockDim(BLOCK_DIM, BLOCK_DIM);
    dim3 gridDim((width + BLOCK_DIM - 1) / BLOCK_DIM, (height + BLOCK_DIM - 1) / BLOCK_DIM);
    
    // Launch kernel
    transposeCoalesced<<<gridDim, blockDim>>>(d_input, d_output, width, height);
    
    // Check for kernel launch errors
    checkCudaError(cudaGetLastError(), "Kernel launch failed");
    
    // Wait for GPU to finish
    checkCudaError(cudaDeviceSynchronize(), "Kernel execution failed");
    
    // Copy result back to host
    cudaMemcpy(h_output, d_output, size, cudaMemcpyDeviceToHost);
    
    // Verify result (optional)
    bool success = true;
    for (int i = 0; i < height && success; i++) {
        for (int j = 0; j < width && success; j++) {
            if (h_output[j * height + i] != h_input[i * width + j]) {
                printf("Verification failed at i=%d, j=%d: %f != %f\n", 
                       i, j, h_output[j * height + i], h_input[i * width + j]);
                success = false;
                break;
            }
        }
    }
    
    if (success) {
        printf("Transpose successful!\n");
    }
    
    // Free memory
    free(h_input);
    free(h_output);
    cudaFree(d_input);
    cudaFree(d_output);
    
    return 0;
}
	.file	"tmpxft_00047c54_00000000-6_12.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB1983:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE1983:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%s: %s\n"
	.text
	.globl	_Z14checkCudaError9cudaErrorPKc
	.type	_Z14checkCudaError9cudaErrorPKc, @function
_Z14checkCudaError9cudaErrorPKc:
.LFB1979:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L2
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rsi, %r12
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movq	%r12, %rcx
	leaq	.LC0(%rip), %rdx
	movq	%rax, %r8
	movl	$1, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L2:
	.cfi_def_cfa_offset 8
	.cfi_restore 12
	ret
	.cfi_endproc
.LFE1979:
	.size	_Z14checkCudaError9cudaErrorPKc, .-_Z14checkCudaError9cudaErrorPKc
	.globl	_Z42__device_stub__Z18transposeCoalescedPfS_iiPfS_ii
	.type	_Z42__device_stub__Z18transposeCoalescedPfS_iiPfS_ii, @function
_Z42__device_stub__Z18transposeCoalescedPfS_iiPfS_ii:
.LFB2005:
	.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	.L8
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z18transposeCoalescedPfS_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
.L8:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2005:
	.size	_Z42__device_stub__Z18transposeCoalescedPfS_iiPfS_ii, .-_Z42__device_stub__Z18transposeCoalescedPfS_iiPfS_ii
	.globl	_Z18transposeCoalescedPfS_ii
	.type	_Z18transposeCoalescedPfS_ii, @function
_Z18transposeCoalescedPfS_ii:
.LFB2006:
	.cfi_startproc
	endbr64
	jmp	_Z42__device_stub__Z18transposeCoalescedPfS_iiPfS_ii
	.cfi_endproc
.LFE2006:
	.size	_Z18transposeCoalescedPfS_ii, .-_Z18transposeCoalescedPfS_ii
	.section	.rodata.str1.1
.LC1:
	.string	"Kernel launch failed"
.LC2:
	.string	"Kernel execution failed"
.LC3:
	.string	"Verification failed at i=%d, j=%d: %f != %f\n"
.LC4:
	.string	"Transpose successful!\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB1980:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	$67108864, %edi
	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	$48, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movl	$67108864, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movq	%rbp, %rcx
	xorl	%edx, %edx
	movq	%rax, %r12
.L14:
	xorl	%eax, %eax
.L15:
	leal	(%rdx,%rax), %esi
	cvtsi2ssl	%esi, %xmm0
	movss	%xmm0, (%rcx,%rax,4)
	incq	%rax
	cmpq	$4096, %rax
	jne	.L15
	addl	$4096, %edx
	addq	$16384, %rcx
	cmpl	$16777216, %edx
	jne	.L14
	movq	%rsp, %rdi
	movl	$67108864, %esi
	call	cudaMalloc@PLT
	leaq	8(%rsp), %rdi
	movl	$67108864, %esi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$67108864, %edx
	call	cudaMemcpy@PLT
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movabsq	$137438953504, %rdx
	movl	$1, %esi
	movabsq	$549755814016, %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L17
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdi
	movl	$4096, %ecx
	movl	$4096, %edx
	call	_Z42__device_stub__Z18transposeCoalescedPfS_iiPfS_ii
.L17:
	call	cudaGetLastError@PLT
	leaq	.LC1(%rip), %rsi
	xorl	%ebx, %ebx
	leaq	.LC3(%rip), %r14
	movl	%eax, %edi
	call	_Z14checkCudaError9cudaErrorPKc
	call	cudaDeviceSynchronize@PLT
	leaq	.LC2(%rip), %rsi
	movl	%eax, %edi
	call	_Z14checkCudaError9cudaErrorPKc
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movq	%r12, %rdi
	movl	$67108864, %edx
	call	cudaMemcpy@PLT
.L18:
	movq	%rbx, %rdx
	movl	%ebx, %r13d
	movl	%ebx, %r8d
	xorl	%eax, %eax
	salq	$14, %rdx
	leaq	(%r12,%rbx,4), %rcx
	addq	%rbp, %rdx
.L22:
	movss	(%rcx), %xmm0
	movss	(%rdx,%rax,4), %xmm1
	movl	%eax, %r9d
	ucomiss	%xmm1, %xmm0
	jp	.L26
	je	.L19
.L26:
	movl	%r9d, %ecx
	movl	%r8d, %edx
	movq	%r14, %rsi
	movl	$1, %edi
	movb	$2, %al
	cvtss2sd	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm1
	call	__printf_chk@PLT
	xorl	%eax, %eax
	jmp	.L21
.L19:
	incq	%rax
	addq	$16384, %rcx
	cmpq	$4096, %rax
	jne	.L22
	movb	$1, %al
.L21:
	incl	%r13d
	incq	%rbx
	cmpl	$4095, %r13d
	jg	.L27
	testb	%al, %al
	jne	.L18
	jmp	.L24
.L27:
	testb	%al, %al
	je	.L24
	leaq	.LC4(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L24:
	movq	%rbp, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	addq	$48, %rsp
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	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
.LFE1980:
	.size	main, .-main
	.section	.rodata.str1.1
.LC5:
	.string	"_Z18transposeCoalescedPfS_ii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2008:
	.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	.LC5(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z18transposeCoalescedPfS_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
.LFE2008:
	.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
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.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 <hip/hip_runtime.h>

// Define block size
#define BLOCK_DIM 32

// HIP kernel for matrix transposition with coalesced memory access
__global__ void transposeCoalesced(float *input, float *output, int width, int height) {
    // Use shared memory to avoid bank conflicts
    __shared__ float tile[BLOCK_DIM][BLOCK_DIM+1]; // +1 to avoid bank conflicts
    
    // Calculate input and output indices
    int x = hipBlockIdx_x * BLOCK_DIM + hipThreadIdx_x;
    int y = hipBlockIdx_y * BLOCK_DIM + hipThreadIdx_y;
    
    // Boundary check for input
    if (x < width && y < height) {
        // Load data from global memory to shared memory in a coalesced manner
        tile[hipThreadIdx_y][hipThreadIdx_x] = input[y * width + x];
    }
    
    // Ensure all threads finish loading into shared memory
    __syncthreads();
    
    // Calculate transposed indices
    int out_x = hipBlockIdx_y * BLOCK_DIM + hipThreadIdx_x;
    int out_y = hipBlockIdx_x * BLOCK_DIM + hipThreadIdx_y;
    
    // Boundary check for output
    if (out_x < height && out_y < width) {
        // Write from shared memory to global memory in a coalesced manner
        output[out_y * height + out_x] = tile[hipThreadIdx_x][hipThreadIdx_y];
    }
}

// Helper function to check for HIP errors
void checkHipError(hipError_t err, const char* msg) {
    if (err != hipSuccess) {
        fprintf(stderr, "%s: %s\n", msg, hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }
}

int main(int argc, char **argv) {
    // Matrix dimensions
    int width = 4096;  // Feel free to change these
    int height = 4096;
    
    size_t size = width * height * sizeof(float);
    
    // Host memory allocation
    float *h_input = (float*)malloc(size);
    float *h_output = (float*)malloc(size);
    
    // Initialize input matrix
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            h_input[i * width + j] = (float)(i * width + j);
        }
    }
    
    // Device memory allocation
    float *d_input, *d_output;
    hipMalloc((void**)&d_input, size);
    hipMalloc((void**)&d_output, size);
    
    // Copy input data from host to device
    hipMemcpy(d_input, h_input, size, hipMemcpyHostToDevice);
    
    // Define grid and block dimensions
    dim3 blockDim(BLOCK_DIM, BLOCK_DIM);
    dim3 gridDim((width + BLOCK_DIM - 1) / BLOCK_DIM, (height + BLOCK_DIM - 1) / BLOCK_DIM);
    
    // Launch kernel
    hipLaunchKernelGGL(transposeCoalesced, gridDim, blockDim, 0, 0, d_input, d_output, width, height);
    
    // Check for kernel launch errors
    checkHipError(hipGetLastError(), "Kernel launch failed");
    
    // Wait for GPU to finish
    checkHipError(hipDeviceSynchronize(), "Kernel execution failed");
    
    // Copy result back to host
    hipMemcpy(h_output, d_output, size, hipMemcpyDeviceToHost);
    
    // Verify result (optional)
    bool success = true;
    for (int i = 0; i < height && success; i++) {
        for (int j = 0; j < width && success; j++) {
            if (h_output[j * height + i] != h_input[i * width + j]) {
                printf("Verification failed at i=%d, j=%d: %f != %f\n", 
                       i, j, h_output[j * height + i], h_input[i * width + j]);
                success = false;
                break;
            }
        }
    }
    
    if (success) {
        printf("Transpose successful!\n");
    }
    
    // Free memory
    free(h_input);
    free(h_output);
    hipFree(d_input);
    hipFree(d_output);
    
    return 0;
}
	.text
	.file	"12.cpp"
	.globl	_Z33__device_stub__transposeCoalescedPfS_ii # -- Begin function _Z33__device_stub__transposeCoalescedPfS_ii
	.p2align	4, 0x90
	.type	_Z33__device_stub__transposeCoalescedPfS_ii,@function
_Z33__device_stub__transposeCoalescedPfS_ii: # @_Z33__device_stub__transposeCoalescedPfS_ii
	.cfi_startproc
# %bb.0:
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 72(%rsp)
	movq	%rsi, 64(%rsp)
	movl	%edx, 12(%rsp)
	movl	%ecx, 8(%rsp)
	leaq	72(%rsp), %rax
	movq	%rax, 80(%rsp)
	leaq	64(%rsp), %rax
	movq	%rax, 88(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 96(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	48(%rsp), %rdi
	leaq	32(%rsp), %rsi
	leaq	24(%rsp), %rdx
	leaq	16(%rsp), %rcx
	callq	__hipPopCallConfiguration
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	movq	32(%rsp), %rcx
	movl	40(%rsp), %r8d
	leaq	80(%rsp), %r9
	movl	$_Z18transposeCoalescedPfS_ii, %edi
	pushq	16(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	32(%rsp)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$136, %rsp
	.cfi_adjust_cfa_offset -136
	retq
.Lfunc_end0:
	.size	_Z33__device_stub__transposeCoalescedPfS_ii, .Lfunc_end0-_Z33__device_stub__transposeCoalescedPfS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z13checkHipError10hipError_tPKc # -- Begin function _Z13checkHipError10hipError_tPKc
	.p2align	4, 0x90
	.type	_Z13checkHipError10hipError_tPKc,@function
_Z13checkHipError10hipError_tPKc:       # @_Z13checkHipError10hipError_tPKc
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jne	.LBB1_2
# %bb.1:
	retq
.LBB1_2:
	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
	movq	stderr(%rip), %rbx
	movq	%rsi, %r14
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movq	%rbx, %rdi
	movq	%r14, %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z13checkHipError10hipError_tPKc, .Lfunc_end1-_Z13checkHipError10hipError_tPKc
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.p2align	4, 0x90
	.type	main,@function
main:                                   # @main
	.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	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	$67108864, %edi                 # imm = 0x4000000
	callq	malloc
	movq	%rax, %rbx
	movl	$67108864, %edi                 # imm = 0x4000000
	callq	malloc
	movq	%rax, %r14
	xorl	%eax, %eax
	xorl	%ecx, %ecx
	.p2align	4, 0x90
.LBB2_1:                                # %.preheader72
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_2 Depth 2
	movl	$4096, %edx                     # imm = 0x1000
	movq	%rax, %rsi
	.p2align	4, 0x90
.LBB2_2:                                #   Parent Loop BB2_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtsi2ss	%esi, %xmm0
	movss	%xmm0, (%rbx,%rsi,4)
	incq	%rsi
	decq	%rdx
	jne	.LBB2_2
# %bb.3:                                #   in Loop: Header=BB2_1 Depth=1
	incq	%rcx
	addq	$4096, %rax                     # imm = 0x1000
	cmpq	$4096, %rcx                     # imm = 0x1000
	jne	.LBB2_1
# %bb.4:
	leaq	16(%rsp), %rdi
	movl	$67108864, %esi                 # imm = 0x4000000
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movl	$67108864, %esi                 # imm = 0x4000000
	callq	hipMalloc
	movq	16(%rsp), %rdi
	movl	$67108864, %edx                 # imm = 0x4000000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movabsq	$549755814016, %rdi             # imm = 0x8000000080
	movabsq	$137438953504, %rdx             # imm = 0x2000000020
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_6
# %bb.5:
	movq	16(%rsp), %rax
	movq	8(%rsp), %rcx
	movq	%rax, 88(%rsp)
	movq	%rcx, 80(%rsp)
	movl	$4096, 28(%rsp)                 # imm = 0x1000
	movl	$4096, 24(%rsp)                 # imm = 0x1000
	leaq	88(%rsp), %rax
	movq	%rax, 96(%rsp)
	leaq	80(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	28(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	64(%rsp), %rdi
	leaq	48(%rsp), %rsi
	leaq	40(%rsp), %rdx
	leaq	32(%rsp), %rcx
	callq	__hipPopCallConfiguration
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	movq	48(%rsp), %rcx
	movl	56(%rsp), %r8d
	leaq	96(%rsp), %r9
	movl	$_Z18transposeCoalescedPfS_ii, %edi
	pushq	32(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	48(%rsp)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
.LBB2_6:
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB2_7
# %bb.9:                                # %_Z13checkHipError10hipError_tPKc.exit
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB2_10
# %bb.11:                               # %_Z13checkHipError10hipError_tPKc.exit69
	movq	8(%rsp), %rsi
	movl	$67108864, %edx                 # imm = 0x4000000
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movb	$1, %al
	xorl	%r15d, %r15d
	movq	%r14, %r12
	movq	%rbx, %r13
	.p2align	4, 0x90
.LBB2_12:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_13 Depth 2
	movq	%r12, %rcx
	xorl	%edx, %edx
	.p2align	4, 0x90
.LBB2_13:                               #   Parent Loop BB2_12 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%rcx), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	movss	(%r13,%rdx,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm1, %xmm0
	jne	.LBB2_14
	jp	.LBB2_14
# %bb.15:                               #   in Loop: Header=BB2_13 Depth=2
	incq	%rdx
	addq	$16384, %rcx                    # imm = 0x4000
	cmpq	$4096, %rdx                     # imm = 0x1000
	jne	.LBB2_13
# %bb.16:                               # %.loopexit
                                        #   in Loop: Header=BB2_12 Depth=1
	cmpq	$4094, %r15                     # imm = 0xFFE
	jbe	.LBB2_17
	jmp	.LBB2_18
	.p2align	4, 0x90
.LBB2_14:                               #   in Loop: Header=BB2_12 Depth=1
	cvtss2sd	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm1
	movl	$.L.str.3, %edi
	movl	%r15d, %esi
                                        # kill: def $edx killed $edx killed $rdx
	movb	$2, %al
	callq	printf
	xorl	%eax, %eax
	cmpq	$4094, %r15                     # imm = 0xFFE
	ja	.LBB2_18
.LBB2_17:                               # %.loopexit
                                        #   in Loop: Header=BB2_12 Depth=1
	incq	%r15
	movl	%eax, %ecx
	andb	$1, %cl
	addq	$16384, %r13                    # imm = 0x4000
	addq	$4, %r12
	testb	%cl, %cl
	jne	.LBB2_12
.LBB2_18:
	testb	$1, %al
	je	.LBB2_20
# %bb.19:
	movl	$.Lstr, %edi
	callq	puts@PLT
.LBB2_20:
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$128, %rsp
	.cfi_def_cfa_offset 48
	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
.LBB2_7:
	.cfi_def_cfa_offset 176
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	jmp	.LBB2_8
.LBB2_10:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.2, %edx
.LBB2_8:
	movq	%rbx, %rdi
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end2:
	.size	main, .Lfunc_end2-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
	cmpq	$0, __hip_gpubin_handle(%rip)
	jne	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	movq	__hip_gpubin_handle(%rip), %rdi
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z18transposeCoalescedPfS_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_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__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	.LBB4_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
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z18transposeCoalescedPfS_ii,@object # @_Z18transposeCoalescedPfS_ii
	.section	.rodata,"a",@progbits
	.globl	_Z18transposeCoalescedPfS_ii
	.p2align	3, 0x0
_Z18transposeCoalescedPfS_ii:
	.quad	_Z33__device_stub__transposeCoalescedPfS_ii
	.size	_Z18transposeCoalescedPfS_ii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%s: %s\n"
	.size	.L.str, 8

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Kernel launch failed"
	.size	.L.str.1, 21

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Kernel execution failed"
	.size	.L.str.2, 24

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Verification failed at i=%d, j=%d: %f != %f\n"
	.size	.L.str.3, 45

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z18transposeCoalescedPfS_ii"
	.size	.L__unnamed_1, 29

	.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	"Transpose successful!"
	.size	.Lstr, 22

	.section	".linker-options","e",@llvm_linker_options
	.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 _Z33__device_stub__transposeCoalescedPfS_ii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z18transposeCoalescedPfS_ii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z18transposeCoalescedPfS_ii ; -- Begin function _Z18transposeCoalescedPfS_ii
	.globl	_Z18transposeCoalescedPfS_ii
	.p2align	8
	.type	_Z18transposeCoalescedPfS_ii,@function
_Z18transposeCoalescedPfS_ii:           ; @_Z18transposeCoalescedPfS_ii
; %bb.0:
	s_load_b64 s[4:5], s[0:1], 0x10
	v_and_b32_e32 v1, 0x3ff, v0
	v_bfe_u32 v2, v0, 10, 10
	s_lshl_b32 s3, s14, 5
	s_lshl_b32 s6, s15, 5
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v0, s3, v1
	v_add_nc_u32_e32 v3, s6, v2
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_i32_e32 vcc_lo, s4, v0
	v_cmp_gt_i32_e64 s2, s5, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s7, vcc_lo, s2
	s_and_saveexec_b32 s2, s7
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b64 s[8:9], s[0:1], 0x0
	v_mad_u64_u32 v[4:5], null, v3, s4, 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[3:4], 2, v[4:5]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v3, vcc_lo, s8, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s9, v4, vcc_lo
	global_load_b32 v0, v[3:4], off
	v_lshlrev_b32_e32 v3, 2, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_mad_u32_u24 v3, v2, 0x84, v3
	s_waitcnt vmcnt(0)
	ds_store_b32 v3, v0
.LBB0_2:
	s_or_b32 exec_lo, exec_lo, s2
	v_add_nc_u32_e32 v0, s6, v1
	v_add_nc_u32_e32 v3, s3, v2
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_cmp_gt_i32_e32 vcc_lo, s5, v0
	v_cmp_gt_i32_e64 s2, s4, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, s2, vcc_lo
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_4
; %bb.3:
	v_lshlrev_b32_e32 v2, 2, v2
	s_load_b64 s[0:1], s[0:1], 0x8
	v_mad_u64_u32 v[4:5], null, v3, s5, v[0:1]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mad_u32_u24 v0, v1, 0x84, v2
	v_ashrrev_i32_e32 v5, 31, v4
	ds_load_b32 v2, v0
	v_lshlrev_b64 v[0:1], 2, v[4:5]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_store_b32 v[0:1], v2, off
.LBB0_4:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z18transposeCoalescedPfS_ii
		.amdhsa_group_segment_fixed_size 4224
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 24
		.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 6
		.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	_Z18transposeCoalescedPfS_ii, .Lfunc_end0-_Z18transposeCoalescedPfS_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 324
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 4224 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 6
; 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
    .group_segment_fixed_size: 4224
    .kernarg_segment_align: 8
    .kernarg_segment_size: 24
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z18transposeCoalescedPfS_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z18transposeCoalescedPfS_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
