#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "cuda_runtime.h"

#define CHECK(call) \
{ \
  const cudaError_t error = call; \
  if(error != cudaSuccess) \
  { \
    printf("Error: %s: %d, ", __FILE__, __LINE__); \
    printf("code:%d, reason: %s\n", error, cudaGetErrorString(error)); \
    exit(1); \
  } \
}

extern "C" __global__ void dotp(double* A, double* B, double* out){
  int bx = blockIdx.x;
  int bdx = blockDim.x;
  int gdx = gridDim.x;
  int tx =  threadIdx.x;
  int BLOCK_SIZE = 32;

  double a[20], b[20];

  /*** Global A,B -> Register a,b ***/
#pragma unroll
  for(int i = 0; i < 20; i++){
    a[i] = A[20*BLOCK_SIZE*bx + tx + BLOCK_SIZE*i];
  }

#pragma unroll
  for(int i = 0; i < 20; i++){
    b[i] = B[20*BLOCK_SIZE*bx + tx + BLOCK_SIZE*i];
  }

  /**** dot production ***/
  double o = 0;
  for(int i = 0; i < 20; ++i){
    o += a[i]*b[i];
  }

  /**** Register o -> Global out ***/
  out[bx*BLOCK_SIZE + tx] = o;
}

extern "C" void dot(int size){
  int N = size;
  int T = 32;
//  int T = atoi(argv[2]);

  double * A, *B, *out;
  A = (double*)malloc( N*N*N*20*sizeof(double));
  B = (double*)malloc( N*N*N*20*sizeof(double) );
  out = (double*)malloc( N*N*N*sizeof(double));


  // initialize
  for(int i = 0; i < N*N*N; ++i){
    for(int j = 0; j < 20; ++j){
      A[i*20 + j] = 100*i+j;
      B[i*20 + j] = 1000*i+j;
    }
    out[i] = 0.0;
  }


  double *dA, *dB, *dout;
  cudaMalloc( (void**)&dA, N*N*N*20*sizeof(double));
  cudaMalloc( (void**)&dB, N*N*N*20*sizeof(double));
  cudaMalloc( (void**)&dout, N*N*N*sizeof(double));

  cudaMemcpy(A, dA, N*N*N*20*sizeof(double), cudaMemcpyHostToDevice);
  cudaMemcpy(B, dB, N*N*N*20*sizeof(double), cudaMemcpyHostToDevice);
  cudaMemcpy(out, dout, N*N*N*sizeof(double), cudaMemcpyHostToDevice);

  dim3 grid(N*N*N/T);
  dim3 block(T);

//  StartTimer();
cudaEvent_t start,stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start,0);
  dotp<<<grid,block>>>(dA,dB,dout);
  CHECK(cudaDeviceSynchronize());

cudaEventRecord(stop,0);
cudaEventSynchronize(stop);
float time;
cudaEventElapsedTime(&time, start, stop);

//  double time = GetTimer(); // [ms]
  double flops = 39*N*N*N / (time * 1e-3); // Flop/sec
  printf("%d^3: time %f[ms], flops %f [GFlops]\n", N, time, flops * 1e-9);

  cudaMemcpy(A, dA, N*N*N*20*sizeof(double), cudaMemcpyDeviceToHost);
  cudaMemcpy(B, dB, N*N*N*20*sizeof(double), cudaMemcpyDeviceToHost);
  cudaMemcpy(out, dout, N*N*N*sizeof(double), cudaMemcpyDeviceToHost);

  free(out);
  free(A);
  free(B);

  cudaFree(dout);
  cudaFree(dA);
  cudaFree(dB);
}

	.file	"tmpxft_0022136d_00000000-6_cuda.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2030:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z27__device_stub__Z4dotpPdS_S_PdS_S_
	.type	_Z27__device_stub__Z4dotpPdS_S_PdS_S_, @function
_Z27__device_stub__Z4dotpPdS_S_PdS_S_:
.LFB2052:
	.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
	movq	%rdx, 8(%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	8(%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	.L2
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	dotp(%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
.L2:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2052:
	.size	_Z27__device_stub__Z4dotpPdS_S_PdS_S_, .-_Z27__device_stub__Z4dotpPdS_S_PdS_S_
	.globl	dotp
	.type	dotp, @function
dotp:
.LFB2053:
	.cfi_startproc
	endbr64
	jmp	_Z27__device_stub__Z4dotpPdS_S_PdS_S_
	.cfi_endproc
.LFE2053:
	.size	dotp, .-dotp
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/ecofighter/ghc-cuda-test/master/cbits/cuda.cu"
.LC2:
	.string	"Error: %s: %d, "
.LC3:
	.string	"code:%d, reason: %s\n"
.LC6:
	.string	"%d^3: time %f[ms], flops %f [GFlops]\n"
	.text
	.globl	dot
	.type	dot, @function
dot:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%edi, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edi, %ebx
	imull	%edi, %ebx
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	imull	%edi, %ebx
	imull	$20, %ebx, %eax
	cltq
	salq	$3, %rax
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	call	malloc@PLT
	movq	(%rsp), %rdi
	movq	%rax, %r12
	call	malloc@PLT
	movq	%rax, %rbp
	movslq	%ebx, %rax
	salq	$3, %rax
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movq	%rax, %r13
	xorl	%eax, %eax
.L9:
	cmpl	%eax, %ebx
	jle	.L17
	imulq	$160, %rax, %rcx
	xorl	%edx, %edx
	imull	$100, %eax, %r8d
	imull	$1000, %eax, %edi
.L10:
	leal	(%rdx,%r8), %esi
	cvtsi2sdl	%esi, %xmm0
	leal	(%rdx,%rdi), %esi
	incl	%edx
	movsd	%xmm0, (%r12,%rcx)
	cvtsi2sdl	%esi, %xmm0
	movsd	%xmm0, 0(%rbp,%rcx)
	addq	$8, %rcx
	cmpl	$20, %edx
	jne	.L10
	movq	$0x000000000, 0(%r13,%rax,8)
	incq	%rax
	jmp	.L9
.L17:
	movq	(%rsp), %rsi
	leaq	24(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rsi
	leaq	32(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rsi
	leaq	40(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdx
	movq	24(%rsp), %rsi
	movq	%r12, %rdi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	(%rsp), %rdx
	movq	32(%rsp), %rsi
	movq	%rbp, %rdi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	40(%rsp), %rsi
	movq	8(%rsp), %rdx
	movq	%r13, %rdi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	%ebx, %eax
	movl	$32, %ecx
	leaq	48(%rsp), %rdi
	cltd
	movl	$1, 84(%rsp)
	idivl	%ecx
	movl	%eax, 64(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 68(%rsp)
	addq	$31, %rax
	movq	%rax, 76(%rsp)
	call	cudaEventCreate@PLT
	leaq	56(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	84(%rsp), %ecx
	movl	72(%rsp), %esi
	xorl	%r9d, %r9d
	movq	76(%rsp), %rdx
	movq	64(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L12
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z27__device_stub__Z4dotpPdS_S_PdS_S_
.L12:
	call	cudaDeviceSynchronize@PLT
	movl	%eax, %r15d
	testl	%eax, %eax
	je	.L13
	movl	$86, %ecx
	leaq	.LC1(%rip), %rdx
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	%r15d, %edi
	call	cudaGetErrorString@PLT
	movl	$2, %edi
	movl	%r15d, %edx
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L13:
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	imull	$39, %ebx, %ebx
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	leaq	20(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	cvtss2sd	20(%rsp), %xmm0
	cvtsi2sdl	%ebx, %xmm1
	movsd	.LC4(%rip), %xmm2
	movl	%r14d, %edx
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	movb	$2, %al
	mulsd	%xmm0, %xmm2
	divsd	%xmm2, %xmm1
	mulsd	.LC5(%rip), %xmm1
	call	__printf_chk@PLT
	movq	(%rsp), %rdx
	movq	24(%rsp), %rsi
	movq	%r12, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movq	(%rsp), %rdx
	movq	32(%rsp), %rsi
	movq	%rbp, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	40(%rsp), %rsi
	movq	%r13, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	addq	$104, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	dot, .-dot
	.section	.rodata.str1.1
.LC7:
	.string	"dotp"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2055:
	.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	.LC7(%rip), %rdx
	movq	%rax, %rdi
	leaq	dotp(%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
.LFE2055:
	.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
.LC4:
	.long	-755914244
	.long	1062232653
	.align 8
.LC5:
	.long	-400107883
	.long	1041313291
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "hip/hip_runtime.h"

#define CHECK(call) \
{ \
  const hipError_t error = call; \
  if(error != hipSuccess) \
  { \
    printf("Error: %s: %d, ", __FILE__, __LINE__); \
    printf("code:%d, reason: %s\n", error, hipGetErrorString(error)); \
    exit(1); \
  } \
}

extern "C" __global__ void dotp(double* A, double* B, double* out){
  int bx = blockIdx.x;
  int bdx = blockDim.x;
  int gdx = gridDim.x;
  int tx =  threadIdx.x;
  int BLOCK_SIZE = 32;

  double a[20], b[20];

  /*** Global A,B -> Register a,b ***/
#pragma unroll
  for(int i = 0; i < 20; i++){
    a[i] = A[20*BLOCK_SIZE*bx + tx + BLOCK_SIZE*i];
  }

#pragma unroll
  for(int i = 0; i < 20; i++){
    b[i] = B[20*BLOCK_SIZE*bx + tx + BLOCK_SIZE*i];
  }

  /**** dot production ***/
  double o = 0;
  for(int i = 0; i < 20; ++i){
    o += a[i]*b[i];
  }

  /**** Register o -> Global out ***/
  out[bx*BLOCK_SIZE + tx] = o;
}

extern "C" void dot(int size){
  int N = size;
  int T = 32;
//  int T = atoi(argv[2]);

  double * A, *B, *out;
  A = (double*)malloc( N*N*N*20*sizeof(double));
  B = (double*)malloc( N*N*N*20*sizeof(double) );
  out = (double*)malloc( N*N*N*sizeof(double));


  // initialize
  for(int i = 0; i < N*N*N; ++i){
    for(int j = 0; j < 20; ++j){
      A[i*20 + j] = 100*i+j;
      B[i*20 + j] = 1000*i+j;
    }
    out[i] = 0.0;
  }


  double *dA, *dB, *dout;
  hipMalloc( (void**)&dA, N*N*N*20*sizeof(double));
  hipMalloc( (void**)&dB, N*N*N*20*sizeof(double));
  hipMalloc( (void**)&dout, N*N*N*sizeof(double));

  hipMemcpy(A, dA, N*N*N*20*sizeof(double), hipMemcpyHostToDevice);
  hipMemcpy(B, dB, N*N*N*20*sizeof(double), hipMemcpyHostToDevice);
  hipMemcpy(out, dout, N*N*N*sizeof(double), hipMemcpyHostToDevice);

  dim3 grid(N*N*N/T);
  dim3 block(T);

//  StartTimer();
hipEvent_t start,stop;
hipEventCreate(&start);
hipEventCreate(&stop);
hipEventRecord(start,0);
  dotp<<<grid,block>>>(dA,dB,dout);
  CHECK(hipDeviceSynchronize());

hipEventRecord(stop,0);
hipEventSynchronize(stop);
float time;
hipEventElapsedTime(&time, start, stop);

//  double time = GetTimer(); // [ms]
  double flops = 39*N*N*N / (time * 1e-3); // Flop/sec
  printf("%d^3: time %f[ms], flops %f [GFlops]\n", N, time, flops * 1e-9);

  hipMemcpy(A, dA, N*N*N*20*sizeof(double), hipMemcpyDeviceToHost);
  hipMemcpy(B, dB, N*N*N*20*sizeof(double), hipMemcpyDeviceToHost);
  hipMemcpy(out, dout, N*N*N*sizeof(double), hipMemcpyDeviceToHost);

  free(out);
  free(A);
  free(B);

  hipFree(dout);
  hipFree(dA);
  hipFree(dB);
}

	.text
	.file	"cuda.hip"
	.globl	__device_stub__dotp             # -- Begin function __device_stub__dotp
	.type	__device_stub__dotp,@function
__device_stub__dotp:                    # @__device_stub__dotp
	.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	24(%rsp), %rsi
	movq	%rdx, (%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	16(%rsp), %r12
	leaq	8(%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	$dotp, %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	__device_stub__dotp, .Lfunc_end0-__device_stub__dotp
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function dot
.LCPI1_0:
	.quad	0x3f50624dd2f1a9fc              # double 0.001
.LCPI1_1:
	.quad	0x3e112e0be826d695              # double 1.0000000000000001E-9
	.text
	.globl	dot
	.type	dot,@function
dot:                                    # @dot
	.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
	movl	%edi, %r12d
	imull	%r12d, %r12d
	movl	%edi, 60(%rsp)                  # 4-byte Spill
	imull	%edi, %r12d
	leal	(,%r12,4), %eax
	leal	(%rax,%rax,4), %eax
	movslq	%eax, %r15
	shlq	$3, %r15
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movslq	%r12d, %rbx
	leaq	(,%rbx,8), %rdi
	movq	%rdi, 64(%rsp)                  # 8-byte Spill
	callq	malloc
	movq	%rax, %r13
	testl	%ebx, %ebx
	jle	.LBB1_5
# %bb.1:                                # %.preheader.preheader
	movl	%r12d, %eax
	xorl	%ecx, %ecx
	movl	$160, %edx
	movq	24(%rsp), %rsi                  # 8-byte Reload
	movq	16(%rsp), %rdi                  # 8-byte Reload
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
.LBB1_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_3 Depth 2
	xorl	%r10d, %r10d
.LBB1_3:                                #   Parent Loop BB1_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	leal	(%rcx,%r10), %r11d
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r11d, %xmm0
	leal	(%r8,%r10), %r11d
	xorps	%xmm1, %xmm1
	cvtsi2sd	%r11d, %xmm1
	movsd	%xmm0, (%rsi,%r10,8)
	movsd	%xmm1, (%rdi,%r10,8)
	incq	%r10
	cmpq	$20, %r10
	jne	.LBB1_3
# %bb.4:                                #   in Loop: Header=BB1_2 Depth=1
	movq	$0, (%r13,%r9,8)
	incq	%r9
	addq	$1000, %r8                      # imm = 0x3E8
	addq	%rdx, %rdi
	addq	%rdx, %rsi
	addq	$100, %rcx
	cmpq	%rax, %r9
	jne	.LBB1_2
.LBB1_5:                                # %._crit_edge
	leaq	48(%rsp), %rbp
	movq	%rbp, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	40(%rsp), %rbx
	movq	%rbx, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movq	64(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rsi
	callq	hipMalloc
	movq	(%rbp), %rsi
	movq	24(%rsp), %rdi                  # 8-byte Reload
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%rbx), %rsi
	movq	16(%rsp), %rdi                  # 8-byte Reload
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	8(%rsp), %rax
	movq	(%rax), %rsi
	movq	%r13, %rdi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leal	31(%r12), %ebp
	testl	%r12d, %r12d
	cmovnsl	%r12d, %ebp
	sarl	$5, %ebp
	btsq	$32, %rbp
	leaq	72(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventCreate
	leaq	32(%rsp), %rdi
	callq	hipEventCreate
	movq	(%rbx), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$32, %rdx
	movq	%rbp, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_7
# %bb.6:
	movq	48(%rsp), %rdi
	movq	40(%rsp), %rsi
	movq	8(%rsp), %rdx
	callq	__device_stub__dotp
.LBB1_7:
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB1_9
# %bb.8:
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	32(%rsp), %rdi
	callq	hipEventSynchronize
	movq	72(%rsp), %rsi
	movq	32(%rsp), %rdx
	leaq	84(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	imull	$39, %r12d, %eax
	cvtsi2sd	%eax, %xmm1
	cvtss2sd	(%rbx), %xmm0
	movsd	.LCPI1_0(%rip), %xmm2           # xmm2 = mem[0],zero
	mulsd	%xmm0, %xmm2
	divsd	%xmm2, %xmm1
	mulsd	.LCPI1_1(%rip), %xmm1
	movl	$.L.str.3, %edi
	movl	60(%rsp), %esi                  # 4-byte Reload
	movb	$2, %al
	callq	printf
	movq	48(%rsp), %rsi
	movq	24(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	40(%rsp), %rsi
	movq	16(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rsi
	movq	%r13, %rdi
	movq	64(%rsp), %rdx                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	movq	%r13, %rdi
	callq	free
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	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
.LBB1_9:
	.cfi_def_cfa_offset 144
	movl	%eax, %ebp
	movl	$.L.str, %edi
	movl	$.L.str.1, %esi
	movl	$86, %edx
	xorl	%eax, %eax
	callq	printf
	movl	%ebp, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %edi
	movl	%ebp, %esi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	dot, .Lfunc_end1-dot
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$dotp, %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_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__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	.LBB3_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
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	dotp,@object                    # @dotp
	.section	.rodata,"a",@progbits
	.globl	dotp
	.p2align	3, 0x0
dotp:
	.quad	__device_stub__dotp
	.size	dotp, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Error: %s: %d, "
	.size	.L.str, 16

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/ecofighter/ghc-cuda-test/master/cbits/cuda.hip"
	.size	.L.str.1, 109

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"code:%d, reason: %s\n"
	.size	.L.str.2, 21

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"%d^3: time %f[ms], flops %f [GFlops]\n"
	.size	.L.str.3, 38

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"dotp"
	.size	.L__unnamed_1, 5

	.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

	.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 __device_stub__dotp
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym dotp
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	dotp                    ; -- Begin function dotp
	.globl	dotp
	.p2align	8
	.type	dotp,@function
dotp:                                   ; @dotp
; %bb.0:                                ; %.preheader33
	s_load_b128 s[4:7], s[0:1], 0x0
	v_mad_u64_u32 v[1:2], null, 0x280, s15, v[0:1]
	s_load_b64 s[0:1], s[0:1], 0x10
	s_mov_b32 s2, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v2, 31, v1
	v_lshlrev_b64 v[1:2], 3, v[1:2]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v35, vcc_lo, s4, v1
	v_add_co_ci_u32_e32 v36, vcc_lo, s5, v2, vcc_lo
	s_clause 0xf
	global_load_b64 v[3:4], v[35:36], off
	global_load_b64 v[5:6], v[35:36], off offset:256
	global_load_b64 v[7:8], v[35:36], off offset:512
	global_load_b64 v[9:10], v[35:36], off offset:768
	global_load_b64 v[11:12], v[35:36], off offset:1024
	global_load_b64 v[13:14], v[35:36], off offset:1280
	global_load_b64 v[15:16], v[35:36], off offset:1536
	global_load_b64 v[17:18], v[35:36], off offset:1792
	global_load_b64 v[19:20], v[35:36], off offset:2048
	global_load_b64 v[21:22], v[35:36], off offset:2304
	global_load_b64 v[23:24], v[35:36], off offset:2560
	global_load_b64 v[25:26], v[35:36], off offset:2816
	global_load_b64 v[27:28], v[35:36], off offset:3072
	global_load_b64 v[29:30], v[35:36], off offset:3328
	global_load_b64 v[31:32], v[35:36], off offset:3584
	global_load_b64 v[33:34], v[35:36], off offset:3840
	v_add_co_u32 v41, vcc_lo, 0x1000, v35
	v_add_co_ci_u32_e32 v42, vcc_lo, 0, v36, vcc_lo
	v_add_co_u32 v1, vcc_lo, s6, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s7, v2, vcc_lo
	s_clause 0x3
	global_load_b64 v[35:36], v[41:42], off
	global_load_b64 v[37:38], v[41:42], off offset:256
	global_load_b64 v[39:40], v[41:42], off offset:512
	global_load_b64 v[41:42], v[41:42], off offset:768
	s_clause 0xb
	global_load_b64 v[43:44], v[1:2], off
	global_load_b64 v[45:46], v[1:2], off offset:256
	global_load_b64 v[47:48], v[1:2], off offset:512
	global_load_b64 v[49:50], v[1:2], off offset:768
	global_load_b64 v[51:52], v[1:2], off offset:1024
	global_load_b64 v[53:54], v[1:2], off offset:1280
	global_load_b64 v[55:56], v[1:2], off offset:1536
	global_load_b64 v[57:58], v[1:2], off offset:1792
	global_load_b64 v[59:60], v[1:2], off offset:2048
	global_load_b64 v[61:62], v[1:2], off offset:2304
	global_load_b64 v[63:64], v[1:2], off offset:2560
	global_load_b64 v[65:66], v[1:2], off offset:2816
	v_add_co_u32 v81, vcc_lo, 0x1000, v1
	v_add_co_ci_u32_e32 v82, vcc_lo, 0, v2, vcc_lo
	s_clause 0x7
	global_load_b64 v[67:68], v[1:2], off offset:3072
	global_load_b64 v[69:70], v[1:2], off offset:3328
	global_load_b64 v[71:72], v[1:2], off offset:3584
	global_load_b64 v[73:74], v[1:2], off offset:3840
	global_load_b64 v[75:76], v[81:82], off
	global_load_b64 v[77:78], v[81:82], off offset:256
	global_load_b64 v[79:80], v[81:82], off offset:512
	global_load_b64 v[81:82], v[81:82], off offset:768
	v_mov_b32_e32 v1, 0
	v_mov_b32_e32 v2, 0
	s_waitcnt vmcnt(38)
	scratch_store_b128 off, v[3:6], off offset:16
	s_waitcnt vmcnt(36)
	scratch_store_b128 off, v[7:10], off offset:32
	s_waitcnt vmcnt(34)
	scratch_store_b128 off, v[11:14], off offset:48
	s_waitcnt vmcnt(32)
	scratch_store_b128 off, v[15:18], off offset:64
	s_waitcnt vmcnt(30)
	scratch_store_b128 off, v[19:22], off offset:80
	s_waitcnt vmcnt(28)
	scratch_store_b128 off, v[23:26], off offset:96
	s_waitcnt vmcnt(26)
	scratch_store_b128 off, v[27:30], off offset:112
	s_waitcnt vmcnt(24)
	scratch_store_b128 off, v[31:34], off offset:128
	s_waitcnt vmcnt(18)
	scratch_store_b128 off, v[43:46], off offset:176
	s_waitcnt vmcnt(16)
	scratch_store_b128 off, v[47:50], off offset:192
	s_waitcnt vmcnt(14)
	scratch_store_b128 off, v[51:54], off offset:208
	s_waitcnt vmcnt(12)
	scratch_store_b128 off, v[55:58], off offset:224
	s_waitcnt vmcnt(10)
	scratch_store_b128 off, v[59:62], off offset:240
	s_waitcnt vmcnt(8)
	scratch_store_b128 off, v[63:66], off offset:256
	s_waitcnt vmcnt(6)
	scratch_store_b128 off, v[67:70], off offset:272
	s_waitcnt vmcnt(4)
	s_clause 0x2
	scratch_store_b128 off, v[71:74], off offset:288
	scratch_store_b128 off, v[35:38], off offset:144
	scratch_store_b128 off, v[39:42], off offset:160
	s_waitcnt vmcnt(2)
	scratch_store_b128 off, v[75:78], off offset:304
	s_waitcnt vmcnt(0)
	scratch_store_b128 off, v[79:82], off offset:320
.LBB0_1:                                ; %.preheader
                                        ; =>This Inner Loop Header: Depth=1
	s_add_i32 s3, s2, 16
	s_add_i32 s4, s2, 0xb0
	scratch_load_b64 v[3:4], off, s3
	scratch_load_b64 v[5:6], off, s4
	s_add_i32 s2, s2, 8
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmpk_eq_i32 s2, 0xa0
	s_waitcnt vmcnt(0)
	v_fma_f64 v[1:2], v[3:4], v[5:6], v[1:2]
	s_cbranch_scc0 .LBB0_1
; %bb.2:
	v_lshl_add_u32 v3, s15, 5, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v4, 31, v3
	v_lshlrev_b64 v[3:4], 3, v[3:4]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v3, vcc_lo, s0, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v4, vcc_lo
	global_store_b64 v[3:4], v[1:2], off
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel dotp
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 336
		.amdhsa_kernarg_size 24
		.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 1
		.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 83
		.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	dotp, .Lfunc_end0-dotp
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 800
; NumSgprs: 18
; NumVgprs: 83
; ScratchSize: 336
; MemoryBound: 1
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 10
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 83
; Occupancy: 16
; WaveLimiterHint : 1
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 1
; 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
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 24
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           dotp
    .private_segment_fixed_size: 336
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         dotp.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     83
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
