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

#include <cuda_runtime.h>

#include "kernel.cuh"

#define N 100000
#define BLOCK_SIZE 256

void compareBuffers(const float *a, const float *b, const uint32_t arr_size)
{
  uint32_t total_failed = 0;
  for(uint32_t i = 0; i < arr_size; ++i)
  {
    if(a[i] != b[i]) {
      printf("Failed index %d\n", i);
      total_failed++;
    }
  }
  printf("failed (%d/%d)\n", total_failed, arr_size);
}

void referenceAdd(const float *a, const float *b, float *c, const uint32_t arr_size)
{
  for(uint32_t i = 0; i < arr_size; ++i)
  {
    c[i] = a[i] + b[i];
  }
}

void randomizeFloatArray(float *arr, const uint32_t arr_size, const uint32_t seed)
{
  srand(seed);
  for(uint32_t i = 0; i < arr_size; ++i)
  {
    arr[i] = rand();
  }
}

void initSimpleFloatArray(float *arr, const uint32_t arr_size, const uint32_t offset)
{
  for(uint32_t i = 0; i < arr_size; ++i)
  {
    arr[i] = i + offset;
  }
}

void printFloatArray(float *arr, const uint32_t arr_size)
{
  for(uint32_t i = 0; i < arr_size; ++i)
  {
    printf("%f, ", arr[i]);
  }
  printf("\n");
}

int main()
{
  float *a, *b, *c, *ref_c;
  float *c_in_a, *c_in_b, *c_out_c;

  a = (float*)malloc(sizeof(float) * N);
  b = (float*)malloc(sizeof(float) * N);
  c = (float*)malloc(sizeof(float) * N);
  ref_c = (float*)malloc(sizeof(float) * N);

  initSimpleFloatArray(a, N, 0);
  initSimpleFloatArray(b, N, 43);

  //printFloatArray(a, N);
  //printFloatArray(b, N);

  cudaMalloc((void **) &c_in_a, N * sizeof(float));
  cudaMalloc((void **) &c_in_b, N * sizeof(float));
  cudaMalloc((void **) &c_out_c, N * sizeof(float));

  cudaMemcpy(c_in_a, a, N * sizeof(float), cudaMemcpyHostToDevice);
  cudaMemcpy(c_in_b, b, N * sizeof(float), cudaMemcpyHostToDevice);

  //const uint32_t el_per_thread = (uint32_t)ceil((double)N / (double)BLOCK_SIZE);
  const uint32_t el_per_thread = 1;
  const uint32_t block_count = (uint32_t)ceil(((double)N / el_per_thread) / (double)BLOCK_SIZE);

  printf("el per thread : %d, block_count : %d\n", el_per_thread, block_count);

  kadd<<<block_count, BLOCK_SIZE>>>(c_in_a, c_in_b, c_out_c, el_per_thread);

  cudaMemcpy(c, c_out_c, N * sizeof(float), cudaMemcpyDeviceToHost);

  //printFloatArray(c, N);

  cudaFree(c_in_a);
  cudaFree(c_in_b);
  cudaFree(c_out_c);

  referenceAdd(a, b, ref_c, N);
  compareBuffers(ref_c, c, N);

  free(a);
  free(b);
  free(c);
  free(ref_c);
}

	.file	"tmpxft_00204e38_00000000-6_main.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2035:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2035:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Failed index %d\n"
.LC1:
	.string	"failed (%d/%d)\n"
	.text
	.globl	_Z14compareBuffersPKfS0_j
	.type	_Z14compareBuffersPKfS0_j, @function
_Z14compareBuffersPKfS0_j:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%edx, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rsi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdi, %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	%r15, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	pushq	%r9
	.cfi_def_cfa_offset 64
.L3:
	cmpq	%r15, %rbx
	je	.L10
	movss	0(%r13,%rbx,4), %xmm0
	ucomiss	(%r14,%rbx,4), %xmm0
	jp	.L7
	je	.L4
.L7:
	movl	%ebx, %edx
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	incl	%r12d
.L4:
	incq	%rbx
	jmp	.L3
.L10:
	popq	%r8
	.cfi_def_cfa_offset 56
	movl	%ebp, %ecx
	popq	%rbx
	.cfi_def_cfa_offset 48
	movl	%r12d, %edx
	popq	%rbp
	.cfi_def_cfa_offset 40
	leaq	.LC1(%rip), %rsi
	popq	%r12
	.cfi_def_cfa_offset 32
	movl	$2, %edi
	popq	%r13
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2027:
	.size	_Z14compareBuffersPKfS0_j, .-_Z14compareBuffersPKfS0_j
	.globl	_Z12referenceAddPKfS0_Pfj
	.type	_Z12referenceAddPKfS0_Pfj, @function
_Z12referenceAddPKfS0_Pfj:
.LFB2028:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
.L12:
	cmpl	%ecx, %eax
	jnb	.L14
	movss	(%rdi,%rax,4), %xmm0
	addss	(%rsi,%rax,4), %xmm0
	movss	%xmm0, (%rdx,%rax,4)
	incq	%rax
	jmp	.L12
.L14:
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z12referenceAddPKfS0_Pfj, .-_Z12referenceAddPKfS0_Pfj
	.globl	_Z19randomizeFloatArrayPfjj
	.type	_Z19randomizeFloatArrayPfjj, @function
_Z19randomizeFloatArrayPfjj:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	movl	%edx, %edi
	pushq	%rcx
	.cfi_def_cfa_offset 32
	leaq	(%rbx,%rbp,4), %rbp
	call	srand@PLT
.L16:
	cmpq	%rbp, %rbx
	je	.L19
	call	rand@PLT
	addq	$4, %rbx
	cvtsi2ssl	%eax, %xmm0
	movss	%xmm0, -4(%rbx)
	jmp	.L16
.L19:
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z19randomizeFloatArrayPfjj, .-_Z19randomizeFloatArrayPfjj
	.globl	_Z20initSimpleFloatArrayPfjj
	.type	_Z20initSimpleFloatArrayPfjj, @function
_Z20initSimpleFloatArrayPfjj:
.LFB2030:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
.L21:
	cmpl	%esi, %eax
	jnb	.L25
	leal	(%rdx,%rax), %ecx
	cvtsi2ssq	%rcx, %xmm0
	movss	%xmm0, (%rdi,%rax,4)
	incq	%rax
	jmp	.L21
.L25:
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z20initSimpleFloatArrayPfjj, .-_Z20initSimpleFloatArrayPfjj
	.section	.rodata.str1.1
.LC2:
	.string	"%f, "
.LC3:
	.string	"\n"
	.text
	.globl	_Z15printFloatArrayPfj
	.type	_Z15printFloatArrayPfj, @function
_Z15printFloatArrayPfj:
.LFB2031:
	.cfi_startproc
	endbr64
	movl	%esi, %esi
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC2(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	leaq	(%rdi,%rsi,4), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
.L27:
	cmpq	%rbp, %rbx
	je	.L30
	movq	%r12, %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	(%rbx), %xmm0
	call	__printf_chk@PLT
	addq	$4, %rbx
	jmp	.L27
.L30:
	popq	%rbx
	.cfi_def_cfa_offset 24
	leaq	.LC3(%rip), %rsi
	popq	%rbp
	.cfi_def_cfa_offset 16
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2031:
	.size	_Z15printFloatArrayPfj, .-_Z15printFloatArrayPfj
	.section	.rodata.str1.1
.LC4:
	.string	"el per thread : %d, block_count : %d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$400000, %edi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$72, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movl	$400000, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movl	$400000, %edi
	movq	%rax, %rbx
	call	malloc@PLT
	movl	$400000, %edi
	movq	%rax, %r13
	call	malloc@PLT
	xorl	%edx, %edx
	movl	$100000, %esi
	movq	%rbp, %rdi
	movq	%rax, %r12
	call	_Z20initSimpleFloatArrayPfjj
	movl	$43, %edx
	movq	%rbx, %rdi
	call	_Z20initSimpleFloatArrayPfjj
	leaq	8(%rsp), %rdi
	movl	$400000, %esi
	call	cudaMalloc@PLT
	leaq	16(%rsp), %rdi
	movl	$400000, %esi
	call	cudaMalloc@PLT
	leaq	24(%rsp), %rdi
	movl	$400000, %esi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$400000, %edx
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$400000, %edx
	call	cudaMemcpy@PLT
	movl	$391, %ecx
	movl	$1, %edx
	xorl	%eax, %eax
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	$16777217, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$8, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	movabsq	$4294967687, %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L32
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	movl	$1, %ecx
	movq	8(%rsp), %rdi
	call	_Z4kaddPfS_S_j@PLT
.L32:
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	movl	$400000, %edx
	movq	%r13, %rdi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movl	$100000, %ecx
	movq	%r12, %rdx
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	call	_Z12referenceAddPKfS0_Pfj
	movl	$100000, %edx
	movq	%r13, %rsi
	movq	%r12, %rdi
	call	_Z14compareBuffersPKfS0_j
	movq	%rbp, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L33
	call	__stack_chk_fail@PLT
.L33:
	addq	$72, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2058:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2058:
	.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 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 <inttypes.h>

#include <hip/hip_runtime.h>

#include "kernel.cuh"

#define N 100000
#define BLOCK_SIZE 256

void compareBuffers(const float *a, const float *b, const uint32_t arr_size)
{
  uint32_t total_failed = 0;
  for(uint32_t i = 0; i < arr_size; ++i)
  {
    if(a[i] != b[i]) {
      printf("Failed index %d\n", i);
      total_failed++;
    }
  }
  printf("failed (%d/%d)\n", total_failed, arr_size);
}

void referenceAdd(const float *a, const float *b, float *c, const uint32_t arr_size)
{
  for(uint32_t i = 0; i < arr_size; ++i)
  {
    c[i] = a[i] + b[i];
  }
}

void randomizeFloatArray(float *arr, const uint32_t arr_size, const uint32_t seed)
{
  srand(seed);
  for(uint32_t i = 0; i < arr_size; ++i)
  {
    arr[i] = rand();
  }
}

void initSimpleFloatArray(float *arr, const uint32_t arr_size, const uint32_t offset)
{
  for(uint32_t i = 0; i < arr_size; ++i)
  {
    arr[i] = i + offset;
  }
}

void printFloatArray(float *arr, const uint32_t arr_size)
{
  for(uint32_t i = 0; i < arr_size; ++i)
  {
    printf("%f, ", arr[i]);
  }
  printf("\n");
}

int main()
{
  float *a, *b, *c, *ref_c;
  float *c_in_a, *c_in_b, *c_out_c;

  a = (float*)malloc(sizeof(float) * N);
  b = (float*)malloc(sizeof(float) * N);
  c = (float*)malloc(sizeof(float) * N);
  ref_c = (float*)malloc(sizeof(float) * N);

  initSimpleFloatArray(a, N, 0);
  initSimpleFloatArray(b, N, 43);

  //printFloatArray(a, N);
  //printFloatArray(b, N);

  hipMalloc((void **) &c_in_a, N * sizeof(float));
  hipMalloc((void **) &c_in_b, N * sizeof(float));
  hipMalloc((void **) &c_out_c, N * sizeof(float));

  hipMemcpy(c_in_a, a, N * sizeof(float), hipMemcpyHostToDevice);
  hipMemcpy(c_in_b, b, N * sizeof(float), hipMemcpyHostToDevice);

  //const uint32_t el_per_thread = (uint32_t)ceil((double)N / (double)BLOCK_SIZE);
  const uint32_t el_per_thread = 1;
  const uint32_t block_count = (uint32_t)ceil(((double)N / el_per_thread) / (double)BLOCK_SIZE);

  printf("el per thread : %d, block_count : %d\n", el_per_thread, block_count);

  kadd<<<block_count, BLOCK_SIZE>>>(c_in_a, c_in_b, c_out_c, el_per_thread);

  hipMemcpy(c, c_out_c, N * sizeof(float), hipMemcpyDeviceToHost);

  //printFloatArray(c, N);

  hipFree(c_in_a);
  hipFree(c_in_b);
  hipFree(c_out_c);

  referenceAdd(a, b, ref_c, N);
  compareBuffers(ref_c, c, N);

  free(a);
  free(b);
  free(c);
  free(ref_c);
}

	.text
	.file	"main.hip"
	.globl	_Z14compareBuffersPKfS0_j       # -- Begin function _Z14compareBuffersPKfS0_j
	.type	_Z14compareBuffersPKfS0_j,@function
_Z14compareBuffersPKfS0_j:              # @_Z14compareBuffersPKfS0_j
	.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
	movl	%edx, %ebx
	testl	%edx, %edx
	je	.LBB0_1
# %bb.3:                                # %.lr.ph.preheader
	movq	%rsi, %r14
	movq	%rdi, %r15
	movl	%ebx, %r13d
	xorl	%r12d, %r12d
	xorl	%ebp, %ebp
.LBB0_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movss	(%r15,%r12,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	ucomiss	(%r14,%r12,4), %xmm0
	jne	.LBB0_5
	jnp	.LBB0_6
.LBB0_5:                                #   in Loop: Header=BB0_4 Depth=1
	movl	$.L.str, %edi
	movl	%r12d, %esi
	xorl	%eax, %eax
	callq	printf
	incl	%ebp
.LBB0_6:                                #   in Loop: Header=BB0_4 Depth=1
	incq	%r12
	cmpq	%r12, %r13
	jne	.LBB0_4
	jmp	.LBB0_2
.LBB0_1:
	xorl	%ebp, %ebp
.LBB0_2:                                # %._crit_edge
	movl	$.L.str.1, %edi
	movl	%ebp, %esi
	movl	%ebx, %edx
	xorl	%eax, %eax
	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	printf                          # TAILCALL
.Lfunc_end0:
	.size	_Z14compareBuffersPKfS0_j, .Lfunc_end0-_Z14compareBuffersPKfS0_j
	.cfi_endproc
                                        # -- End function
	.globl	_Z12referenceAddPKfS0_Pfj       # -- Begin function _Z12referenceAddPKfS0_Pfj
	.type	_Z12referenceAddPKfS0_Pfj,@function
_Z12referenceAddPKfS0_Pfj:              # @_Z12referenceAddPKfS0_Pfj
	.cfi_startproc
# %bb.0:
	testl	%ecx, %ecx
	je	.LBB1_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%ecx, %eax
	xorl	%ecx, %ecx
.LBB1_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movss	(%rdi,%rcx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	addss	(%rsi,%rcx,4), %xmm0
	movss	%xmm0, (%rdx,%rcx,4)
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB1_2
.LBB1_3:                                # %._crit_edge
	retq
.Lfunc_end1:
	.size	_Z12referenceAddPKfS0_Pfj, .Lfunc_end1-_Z12referenceAddPKfS0_Pfj
	.cfi_endproc
                                        # -- End function
	.globl	_Z19randomizeFloatArrayPfjj     # -- Begin function _Z19randomizeFloatArrayPfjj
	.type	_Z19randomizeFloatArrayPfjj,@function
_Z19randomizeFloatArrayPfjj:            # @_Z19randomizeFloatArrayPfjj
	.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	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebp
	movq	%rdi, %rbx
	movl	%edx, %edi
	callq	srand
	testl	%ebp, %ebp
	je	.LBB2_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%ebp, %r14d
	xorl	%r15d, %r15d
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%rbx,%r15,4)
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB2_2
.LBB2_3:                                # %._crit_edge
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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	_Z19randomizeFloatArrayPfjj, .Lfunc_end2-_Z19randomizeFloatArrayPfjj
	.cfi_endproc
                                        # -- End function
	.globl	_Z20initSimpleFloatArrayPfjj    # -- Begin function _Z20initSimpleFloatArrayPfjj
	.type	_Z20initSimpleFloatArrayPfjj,@function
_Z20initSimpleFloatArrayPfjj:           # @_Z20initSimpleFloatArrayPfjj
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	je	.LBB3_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%esi, %eax
	movl	%edx, %ecx
	xorl	%edx, %edx
.LBB3_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	leal	(%rcx,%rdx), %esi
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rsi, %xmm0
	movss	%xmm0, (%rdi,%rdx,4)
	incq	%rdx
	cmpq	%rdx, %rax
	jne	.LBB3_2
.LBB3_3:                                # %._crit_edge
	retq
.Lfunc_end3:
	.size	_Z20initSimpleFloatArrayPfjj, .Lfunc_end3-_Z20initSimpleFloatArrayPfjj
	.cfi_endproc
                                        # -- End function
	.globl	_Z15printFloatArrayPfj          # -- Begin function _Z15printFloatArrayPfj
	.type	_Z15printFloatArrayPfj,@function
_Z15printFloatArrayPfj:                 # @_Z15printFloatArrayPfj
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	je	.LBB4_4
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	%esi, %r14d
	xorl	%r15d, %r15d
.LBB4_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%r15,4), %xmm0
	movl	$.L.str.2, %edi
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB4_2
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB4_4:                                # %._crit_edge
	movl	$10, %edi
	jmp	putchar@PLT                     # TAILCALL
.Lfunc_end4:
	.size	_Z15printFloatArrayPfj, .Lfunc_end4-_Z15printFloatArrayPfj
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function 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	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$400000, %edi                   # imm = 0x61A80
	callq	malloc
	movq	%rax, %rbx
	movl	$400000, %edi                   # imm = 0x61A80
	callq	malloc
	movq	%rax, %r14
	movl	$400000, %edi                   # imm = 0x61A80
	callq	malloc
	movq	%rax, %r15
	movl	$400000, %edi                   # imm = 0x61A80
	callq	malloc
	movq	%rax, %r12
	xorl	%eax, %eax
.LBB5_1:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	movl	%eax, %ecx
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rcx, %xmm0
	movss	%xmm0, (%rbx,%rax,4)
	incq	%rax
	cmpq	$100000, %rax                   # imm = 0x186A0
	jne	.LBB5_1
# %bb.2:                                # %.lr.ph.i18.preheader
	xorl	%eax, %eax
.LBB5_3:                                # %.lr.ph.i18
                                        # =>This Inner Loop Header: Depth=1
	leal	43(%rax), %ecx
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rcx, %xmm0
	movss	%xmm0, (%r14,%rax,4)
	incq	%rax
	cmpq	$100000, %rax                   # imm = 0x186A0
	jne	.LBB5_3
# %bb.4:                                # %_Z20initSimpleFloatArrayPfjj.exit22
	leaq	16(%rsp), %r13
	movl	$400000, %esi                   # imm = 0x61A80
	movq	%r13, %rdi
	callq	hipMalloc
	leaq	8(%rsp), %rbp
	movl	$400000, %esi                   # imm = 0x61A80
	movq	%rbp, %rdi
	callq	hipMalloc
	movq	%rsp, %rdi
	movl	$400000, %esi                   # imm = 0x61A80
	callq	hipMalloc
	movq	(%r13), %rdi
	movl	$400000, %edx                   # imm = 0x61A80
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%rbp), %rdi
	movl	$400000, %edx                   # imm = 0x61A80
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$.L.str.4, %edi
	movl	$1, %esi
	movl	$391, %edx                      # imm = 0x187
	xorl	%eax, %eax
	callq	printf
	movabsq	$4294967552, %rdx               # imm = 0x100000100
	leaq	135(%rdx), %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_6
# %bb.5:
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	movl	$1, %ecx
	callq	_Z19__device_stub__kaddPfS_S_j
.LBB5_6:
	movq	(%rsp), %rsi
	movl	$400000, %edx                   # imm = 0x61A80
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
.LBB5_7:                                # %.lr.ph.i23
                                        # =>This Inner Loop Header: Depth=1
	movss	(%rbx,%rax,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	addss	(%r14,%rax,4), %xmm0
	movss	%xmm0, (%r12,%rax,4)
	incq	%rax
	cmpq	$100000, %rax                   # imm = 0x186A0
	jne	.LBB5_7
# %bb.8:                                # %_Z12referenceAddPKfS0_Pfj.exit
	movq	%r12, %rdi
	movq	%r15, %rsi
	movl	$100000, %edx                   # imm = 0x186A0
	callq	_Z14compareBuffersPKfS0_j
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	%r12, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	main, .Lfunc_end5-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Failed index %d\n"
	.size	.L.str, 17

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"failed (%d/%d)\n"
	.size	.L.str.1, 16

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"%f, "
	.size	.L.str.2, 5

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"el per thread : %d, block_count : %d\n"
	.size	.L.str.4, 38

	.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 __hip_cuid_

	.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_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
