#include "stdio.h"

void generateData(int a,float **b); 

typedef struct {
  int  id;
  int  binId1;
  int  binId2;
  float *price;
    } Security; 

void generateData(int totalCount,float **ptr) {
  *ptr = NULL; 
  *ptr = (float *) malloc(totalCount * sizeof(float));
  for(int i = 0;i < totalCount; i++) {
    *((*ptr) + i) = 20.0+((double)rand()/(double)(RAND_MAX-1))*100;
  }
}

void generateSecurityData(int perBin,int bins,Security **securities) {
  int total = 1;
  *securities = NULL;
  *securities = (Security *)malloc(perBin*bins*sizeof(Security));
  for(int i =0;i < bins; i++) {
    for(int q = 0; q < perBin; q++) {
      Security sec;
      sec.id = total+1;
      sec.binId1 = (i+1); 
      generateData(2048,&sec.price);
      *((*securities + total)) = sec;
      total++;
    }
  }
}   

int main() { 
  Security *securities;
  generateSecurityData(256,32,&securities);
  printf("Id for %d\n",securities[10].id);
  return 0;
} 

	.file	"tmpxft_001fdb11_00000000-6_reduce.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z12generateDataiPPf
	.type	_Z12generateDataiPPf, @function
_Z12generateDataiPPf:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movslq	%edi, %rdi
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, (%r12)
.L3:
	cmpl	%ebp, %ebx
	jle	.L7
	call	rand@PLT
	movq	(%r12), %rdx
	cvtsi2sdl	%eax, %xmm0
	divsd	.LC0(%rip), %xmm0
	mulsd	.LC1(%rip), %xmm0
	addsd	.LC2(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%rdx,%rbp,4)
	incq	%rbp
	jmp	.L3
.L7:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z12generateDataiPPf, .-_Z12generateDataiPPf
	.globl	_Z20generateSecurityDataiiPP8Security
	.type	_Z20generateSecurityDataiiPP8Security, @function
_Z20generateSecurityDataiiPP8Security:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%edi, %r15d
	imull	%esi, %edi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movslq	%edi, %rdi
	movl	%esi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	imulq	$24, %rdi, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	leaq	32(%rsp), %rdx
	movl	$1, %ecx
	movq	%rdx, (%rsp)
	movq	%rax, 0(%r13)
	xorl	%eax, %eax
.L9:
	cmpl	%r12d, %eax
	jge	.L8
	movslq	%ecx, %rbp
	xorl	%r14d, %r14d
	leal	1(%rax), %ebx
	imulq	$24, %rbp, %rbp
.L12:
	cmpl	%r15d, %r14d
	jge	.L15
	movq	(%rsp), %rsi
	leal	1(%rcx,%r14), %eax
	movl	$2048, %edi
	incl	%r14d
	movl	%ecx, 12(%rsp)
	movl	%eax, 16(%rsp)
	movl	%ebx, 20(%rsp)
	call	_Z12generateDataiPPf
	movq	0(%r13), %rax
	movups	16(%rsp), %xmm0
	movq	32(%rsp), %rsi
	movl	12(%rsp), %ecx
	movups	%xmm0, (%rax,%rbp)
	movq	%rsi, 16(%rax,%rbp)
	addq	$24, %rbp
	jmp	.L12
.L15:
	xorl	%eax, %eax
	testl	%r15d, %r15d
	cmovns	%r15d, %eax
	addl	%eax, %ecx
	movl	%ebx, %eax
	jmp	.L9
.L8:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	addq	$56, %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
.LFE2028:
	.size	_Z20generateSecurityDataiiPP8Security, .-_Z20generateSecurityDataiiPP8Security
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC3:
	.string	"Id for %d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$32, %esi
	movl	$256, %edi
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rdx
	call	_Z20generateSecurityDataiiPP8Security
	movq	(%rsp), %rax
	movl	$2, %edi
	leaq	.LC3(%rip), %rsi
	movl	240(%rax), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	xorl	%eax, %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	main, .-main
	.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
	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
.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
.LC0:
	.long	-8388608
	.long	1105199103
	.align 8
.LC1:
	.long	0
	.long	1079574528
	.align 8
.LC2:
	.long	0
	.long	1077149696
	.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 "stdio.h"

void generateData(int a,float **b); 

typedef struct {
  int  id;
  int  binId1;
  int  binId2;
  float *price;
    } Security; 

void generateData(int totalCount,float **ptr) {
  *ptr = NULL; 
  *ptr = (float *) malloc(totalCount * sizeof(float));
  for(int i = 0;i < totalCount; i++) {
    *((*ptr) + i) = 20.0+((double)rand()/(double)(RAND_MAX-1))*100;
  }
}

void generateSecurityData(int perBin,int bins,Security **securities) {
  int total = 1;
  *securities = NULL;
  *securities = (Security *)malloc(perBin*bins*sizeof(Security));
  for(int i =0;i < bins; i++) {
    for(int q = 0; q < perBin; q++) {
      Security sec;
      sec.id = total+1;
      sec.binId1 = (i+1); 
      generateData(2048,&sec.price);
      *((*securities + total)) = sec;
      total++;
    }
  }
}   

int main() { 
  Security *securities;
  generateSecurityData(256,32,&securities);
  printf("Id for %d\n",securities[10].id);
  return 0;
} 

	.text
	.file	"reduce.hip"
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z12generateDataiPPf
.LCPI0_0:
	.quad	0x41dfffffff800000              # double 2147483646
.LCPI0_1:
	.quad	0x4059000000000000              # double 100
.LCPI0_2:
	.quad	0x4034000000000000              # double 20
	.text
	.globl	_Z12generateDataiPPf
	.type	_Z12generateDataiPPf,@function
_Z12generateDataiPPf:                   # @_Z12generateDataiPPf
	.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
	movq	%rsi, %rbx
	movl	%edi, %ebp
	movslq	%edi, %r14
	leaq	(,%r14,4), %rdi
	callq	malloc
	movq	%rax, (%rbx)
	testl	%r14d, %r14d
	jle	.LBB0_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%ebp, %r14d
	xorl	%r15d, %r15d
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI0_0(%rip), %xmm0
	mulsd	.LCPI0_1(%rip), %xmm0
	addsd	.LCPI0_2(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movq	(%rbx), %rax
	movss	%xmm0, (%rax,%r15,4)
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB0_2
.LBB0_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_end0:
	.size	_Z12generateDataiPPf, .Lfunc_end0-_Z12generateDataiPPf
	.cfi_endproc
                                        # -- End function
	.globl	_Z20generateSecurityDataiiPP8Security # -- Begin function _Z20generateSecurityDataiiPP8Security
	.type	_Z20generateSecurityDataiiPP8Security,@function
_Z20generateSecurityDataiiPP8Security:  # @_Z20generateSecurityDataiiPP8Security
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdx, %rbx
	movl	%esi, %ebp
	movl	%edi, %r14d
	movl	%esi, %eax
	imull	%edi, %eax
	cltq
	shlq	$3, %rax
	leaq	(%rax,%rax,2), %rdi
	callq	malloc
	movq	%rax, (%rbx)
	movl	%ebp, 12(%rsp)                  # 4-byte Spill
	testl	%ebp, %ebp
	jle	.LBB1_6
# %bb.1:                                # %.preheader.lr.ph
	movl	$1, %r12d
	xorl	%r13d, %r13d
	leaq	32(%rsp), %r15
	movl	%r14d, 8(%rsp)                  # 4-byte Spill
.LBB1_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_4 Depth 2
	incl	%r13d
	testl	%r14d, %r14d
	jle	.LBB1_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB1_2 Depth=1
	movslq	%r12d, %rax
	shlq	$3, %rax
	leaq	(%rax,%rax,2), %rbp
.LBB1_4:                                #   Parent Loop BB1_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	incl	%r12d
	movl	%r12d, 16(%rsp)
	movl	%r13d, 20(%rsp)
	movl	$2048, %edi                     # imm = 0x800
	movq	%r15, %rsi
	callq	_Z12generateDataiPPf
	movq	(%rbx), %rax
	movq	32(%rsp), %rcx
	movq	%rcx, 16(%rax,%rbp)
	movups	16(%rsp), %xmm0
	movups	%xmm0, (%rax,%rbp)
	addq	$24, %rbp
	decl	%r14d
	jne	.LBB1_4
.LBB1_5:                                # %._crit_edge
                                        #   in Loop: Header=BB1_2 Depth=1
	cmpl	12(%rsp), %r13d                 # 4-byte Folded Reload
	movl	8(%rsp), %r14d                  # 4-byte Reload
	jne	.LBB1_2
.LBB1_6:                                # %._crit_edge20
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z20generateSecurityDataiiPP8Security, .Lfunc_end1-_Z20generateSecurityDataiiPP8Security
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	leaq	8(%rsp), %rbx
	movl	$256, %edi                      # imm = 0x100
	movl	$32, %esi
	movq	%rbx, %rdx
	callq	_Z20generateSecurityDataiiPP8Security
	movq	(%rbx), %rax
	movl	240(%rax), %esi
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	xorl	%eax, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Id for %d\n"
	.size	.L.str, 11

	.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
