#include <stdio.h>
#include <math.h>
#include <iostream>
#include <inttypes.h>
#include <vector>
#include <fstream> // I/O

//struct DataFrame
struct DataFrame
{
  int w;
  int h;
  float* e;
};


//Thread block size
#define BLOCK_SIZE 16 //number of threads for each block
#define GRID_SIZE 128 //dimension of entire space
//warning GRID_SIZE must be multiple of 16
#define BIN_SIZE 4 //size of a hisogram bin
#define TH 30 //threshold for triggering the histogram

__global__ void GridKernel(const DataFrame, DataFrame, unsigned int*); //aggiungere i parametri



//------------------------------------------------------------
//Histogram algorithm HOST CODE
float CircleFit(const DataFrame data, DataFrame circles)
{
  //load data to device memory
  DataFrame d_data;
  d_data.w = data.w;
  d_data.h = data.h;
  size_t size = data.w * data.h * sizeof(float);
  cudaError_t err = cudaMalloc(&d_data.e, size);
  if(err)
    printf("CUDA malloc data DataFrame: %s\n",cudaGetErrorString(err));
  cudaMemcpy(d_data.e, data.e, size, cudaMemcpyHostToDevice);

  //allocate circles
  DataFrame d_circles;
  d_circles.w = circles.w;
  d_circles.h = circles.h;
  size = circles.w * circles.h * sizeof(float);
  err = cudaMalloc(&d_circles.e, size);
  if(err)
    printf("CUDA malloc circles DataFrame: %s\n",cudaGetErrorString(err));

  //allocate variable for counting circles found  
  unsigned int *d_counter;
  unsigned int  h_counter;

  cudaMallocManaged(&d_counter, sizeof(unsigned int));
    if(err)
    printf("CUDA malloc counter variable: %s\n",cudaGetErrorString(err));

  // printf("initialized counter : %u\n", *counter);
  // Hai assegnato al puntatore l'indirizzo di memoria da utilizzare, ma e' memoria della GPU, non puoi accedere da qui
  // ma il valore nella cella puntata non e' inizializzato
  cudaMemset(d_counter, 0, sizeof(unsigned int));
  cudaMemcpy(&h_counter, d_counter, sizeof(unsigned int), cudaMemcpyDeviceToHost);

  printf("initialized counter : %u\n", h_counter);



  // 

  float time;
  cudaEvent_t start,stop;
  cudaEventCreate(&start);
  cudaEventCreate(&stop);
  //start time
  cudaEventRecord(start);

   // Define the geometry
  dim3 dimBlock(BLOCK_SIZE, BLOCK_SIZE);
  dim3 dimGrid(GRID_SIZE/ dimBlock.x, GRID_SIZE/ dimBlock.y);
      //warning GRID_SIZE must be multiple of 16

  // Invoke kernel
  GridKernel<<<dimGrid, dimBlock>>>(d_data, d_circles, d_counter);
  err = cudaDeviceSynchronize();

  //stop time
  cudaEventRecord(stop);
  cudaEventSynchronize(stop);
  cudaEventElapsedTime(&time, start, stop);

  if(err)
    printf("Run kernel: %s\n", cudaGetErrorString(err));

  printf("Time: %3.5f ms\n",time);

  // Read C from device memory
  size = circles.w * circles.h * sizeof(float);
  err = cudaMemcpy(circles.e, d_circles.e, size, cudaMemcpyDeviceToHost);
  if(err)
    printf("Copy circles off of device: %s\n",cudaGetErrorString(err));

  cudaMemcpy(&h_counter, d_counter, sizeof(unsigned int), cudaMemcpyDeviceToHost);
  printf("counter : %u\n", h_counter);


  // Free device memory
  cudaFree(d_data.e);
  cudaFree(d_circles.e);
  cudaFree(d_counter);

  return time;
} //END HOST FUNCTION



//---------------------------------------------------------

// thread aware log function
__device__ void log_msg(const char * message)
{
  printf("%d.%d.%d.%d-%s", blockIdx.x, blockIdx.y, threadIdx.x, threadIdx.y, message);
}

//Device function to calculate distance
__device__ float Distance2(float x, float y, float xd, float yd)
{
  return (x-xd)*(x-xd)+(y-yd)*(y-yd);
}


//---------------------------------------------------------
//Device function to Get Element from data
__device__ float GetElement(const DataFrame D, int row, int col)
{
  if ( (row < D.h ) && (col < D.w ) )
    return D.e[row * D.w + col];
  else 
    return 0.0;
}


//---------------------------------------------------------------
//Device function to Set Element of data
__device__ void SetElement(DataFrame D, int row, int col, float value) 
{
  if ( (row < D.h ) && (col < D.w ) )
   D.e[row * D.w + col] = value;
}


//---------------------------------------------------------
//Device function to fill histo
// __device__ void HistoFill(int x, int y, DataFrame data,int *h, DataFrame circles, unsigned int *counter)
__device__ void HstFill(int x, int y, DataFrame data,DataFrame circles, unsigned int *counter)
{
  const size_t HST_SIZE = GRID_SIZE*GRID_SIZE/BIN_SIZE;
  int 	       hst[HST_SIZE] = {0}; // va inizializzato
  int 	       i, idx;

  // log_id(); printf("HstFill\n");

  // atomicAdd(counter,1);

  for ( i=0; i<data.h; i++)
  {
    // float xd, yd, d;
    float xd, yd;
    int d;
    
    xd = GetElement(data, i, 0);
    yd = GetElement(data, i, 1);
    d  = __float2int_rn(  Distance2( __int2float_rn(x), __int2float_rn(y),xd,yd) ) / BIN_SIZE ;

    if (d < HST_SIZE) hst[d] +=1; // questo if serve per evitare errori di accesso alla memoria nel caso di valori "strani"

    
    // potrebbero lavorare piu' thread sullo stesso elemento 
    // va implementato un meccanismo di locking per evitarlo
    // in piu' questo blocco va eseguito solo al termine del ciclo for, quando hai ormai analizzato tutti i punti
    // altrimenti crei (n - TH)  volte lo stesso cerchio

    /*
    if(hst[bin]>TH)
    {
      idx = atomicAdd(counter,1); // garantisce che l'incremento avvenga un thread alla volta, quindi idx puo' essere usato solo dal thread in esecuzione

      SetElement(circles, idx,0,x);
      SetElement(circles, idx,1,y);
      // float r2=d;
      // SetElement(circles, idx,2,r2);
      SetElement(circles, idx,2,d);
    }
    */
  }


  // dopo aver riempito l'array hst, scandisce tutti gli elementi e aggiunge alla lista dei cerchi il cerchio trovato
  for ( i=0; i < HST_SIZE; i++)
  {
    if(hst[i]>TH)
    {
      idx = atomicAdd(counter,1); // garantisce che l'incremento avvenga un thread alla volta, quindi idx puo' essere usato solo dal thread in esecuzione

      //log_msg(""); printf("counter: %d, x %f, y %f, radius: %f\n", idx, __int2float_rn(x), __int2float_rn(y),  sqrt( __int2float_rn(i*BIN_SIZE) ) );

      SetElement(circles, idx,0, __int2float_rn(x));
      SetElement(circles, idx,1, __int2float_rn(y));
      // float r2=d;
      // SetElement(circles, idx,2,r2);
      SetElement(circles, idx,2, sqrt( __int2float_rn(i*BIN_SIZE) ) );
    }

  }
}




//---------------------------------------------------------
//Histogram algorithm kernel
__global__ void GridKernel(DataFrame data, DataFrame circles,unsigned int *counter)
{
  //x and y indexes
  int x = blockIdx.x * blockDim.x+ threadIdx.x - (GRID_SIZE / 2);
  int y = blockIdx.y * blockDim.y +threadIdx.y - (GRID_SIZE / 2);

//  const size_t histo_size = GRID_SIZE*GRID_SIZE/BIN_SIZE;
//  int histo[histo_size];
//  se con histo non ci fai niente, e' inutile definirla qui e passarla alla funzione
//  in piu' il contenuto non e' inizializzato

//  HistoFill(x,y, data, histo, circles, counter);
  HstFill(x,y, data, circles, counter);


}


//------------------------------------------------------------
//dump dataframe function
void dump(DataFrame m)
{
  for (int i = 0; i< m.h; i++)     // Loop sulle righe
  {
    for (int j = 0; j< m.w; j++)    // Loop sulle colonne
      printf("%3.1f\t", m.e[i*m.w + j]);
    printf("\n");  // A capo di fine riga
  }
  printf("\n");
}



//------------------------------------------------------------
//read floats from file.dat
void readBin(std::vector<float> buf)
{
}



//-------------------------------------------------------------
int main(int argc, char** argv)
{
  std::vector<float> buf;
  std::ifstream in("file.dat",std::ios::binary); //open the input file
  while(!in.eof())
  {
    float w;
    in.read( (char*) &w, sizeof(w));
    buf.push_back(w);
  }

  in.close(); //close the input file .... ormai i dati sono letti, puoi chiudere il file

  DataFrame data, circles;

  data.h = buf.size()>>1;
  data.w = 2;
  data.e = (float*) malloc(data.w * data.h * sizeof(float));

  circles.h = 15;
  circles.w = 3;
  circles.e = (float*) malloc(circles.w * circles.h * sizeof(float));

  data.e = &buf[0]; //copy imported floats from buf to data .... non stai copiando i dati, se fai cosi' non ti serve la memoria che hai allocato prima

  float a = CircleFit(data, circles);

//  dump(data);
  dump(circles);

  // in.close(); //close the input file
  return 0;
}

	.file	"tmpxft_00245959_00000000-6_reticolo.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4150:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4150:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z7log_msgPKc
	.type	_Z7log_msgPKc, @function
_Z7log_msgPKc:
.LFB4130:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE4130:
	.size	_Z7log_msgPKc, .-_Z7log_msgPKc
	.globl	_Z9Distance2ffff
	.type	_Z9Distance2ffff, @function
_Z9Distance2ffff:
.LFB4131:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE4131:
	.size	_Z9Distance2ffff, .-_Z9Distance2ffff
	.globl	_Z10GetElement9DataFrameii
	.type	_Z10GetElement9DataFrameii, @function
_Z10GetElement9DataFrameii:
.LFB4132:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE4132:
	.size	_Z10GetElement9DataFrameii, .-_Z10GetElement9DataFrameii
	.globl	_Z10SetElement9DataFrameiif
	.type	_Z10SetElement9DataFrameiif, @function
_Z10SetElement9DataFrameiif:
.LFB4133:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE4133:
	.size	_Z10SetElement9DataFrameiif, .-_Z10SetElement9DataFrameiif
	.globl	_Z7HstFillii9DataFrameS_Pj
	.type	_Z7HstFillii9DataFrameS_Pj, @function
_Z7HstFillii9DataFrameS_Pj:
.LFB4134:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE4134:
	.size	_Z7HstFillii9DataFrameS_Pj, .-_Z7HstFillii9DataFrameS_Pj
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%3.1f\t"
.LC1:
	.string	"\n"
	.text
	.globl	_Z4dump9DataFrame
	.type	_Z4dump9DataFrame, @function
_Z4dump9DataFrame:
.LFB4135:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%edi, %r15d
	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
	movq	%rsi, %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
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdi, %rbx
	sarq	$32, %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
.L13:
	cmpl	%ebx, %r12d
	jge	.L15
	movslq	%ebp, %rdx
	xorl	%ecx, %ecx
	salq	$2, %rdx
.L16:
	cmpl	%r14d, %ecx
	jge	.L19
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	movl	%ecx, 12(%rsp)
	movq	%rdx, (%rsp)
	cvtss2sd	(%rdx,%r13), %xmm0
	call	__printf_chk@PLT
	movl	12(%rsp), %ecx
	movq	(%rsp), %rdx
	incl	%ecx
	addq	$4, %rdx
	jmp	.L16
.L19:
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	incl	%r12d
	addl	%r15d, %ebp
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L13
.L15:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	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
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE4135:
	.size	_Z4dump9DataFrame, .-_Z4dump9DataFrame
	.globl	_Z7readBinSt6vectorIfSaIfEE
	.type	_Z7readBinSt6vectorIfSaIfEE, @function
_Z7readBinSt6vectorIfSaIfEE:
.LFB4136:
	.cfi_startproc
	endbr64
	ret
	.cfi_endproc
.LFE4136:
	.size	_Z7readBinSt6vectorIfSaIfEE, .-_Z7readBinSt6vectorIfSaIfEE
	.globl	_Z42__device_stub__Z10GridKernel9DataFrameS_PjR9DataFrameS0_Pj
	.type	_Z42__device_stub__Z10GridKernel9DataFrameS_PjR9DataFrameS0_Pj, @function
_Z42__device_stub__Z10GridKernel9DataFrameS_PjR9DataFrameS0_Pj:
.LFB4172:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdx, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movq	%rdi, 80(%rsp)
	leaq	32(%rsp), %rdi
	movq	%rsi, 88(%rsp)
	leaq	44(%rsp), %rsi
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movl	$1, 40(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L21
	pushq	24(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z10GridKernel9DataFrameS_Pj(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 144
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L21:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4172:
	.size	_Z42__device_stub__Z10GridKernel9DataFrameS_PjR9DataFrameS0_Pj, .-_Z42__device_stub__Z10GridKernel9DataFrameS_PjR9DataFrameS0_Pj
	.globl	_Z10GridKernel9DataFrameS_Pj
	.type	_Z10GridKernel9DataFrameS_Pj, @function
_Z10GridKernel9DataFrameS_Pj:
.LFB4173:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	%rdi, 16(%rsp)
	leaq	16(%rsp), %rdi
	movq	%rsi, 24(%rsp)
	movq	%rsp, %rsi
	movq	%rdx, (%rsp)
	movq	%r8, %rdx
	movq	%rcx, 8(%rsp)
	call	_Z42__device_stub__Z10GridKernel9DataFrameS_PjR9DataFrameS0_Pj
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4173:
	.size	_Z10GridKernel9DataFrameS_Pj, .-_Z10GridKernel9DataFrameS_Pj
	.section	.rodata.str1.1
.LC2:
	.string	"CUDA malloc data DataFrame: %s\n"
.LC3:
	.string	"CUDA malloc circles DataFrame: %s\n"
.LC4:
	.string	"CUDA malloc counter variable: %s\n"
.LC5:
	.string	"initialized counter : %u\n"
.LC6:
	.string	"Run kernel: %s\n"
.LC7:
	.string	"Time: %3.5f ms\n"
.LC8:
	.string	"Copy circles off of device: %s\n"
.LC9:
	.string	"counter : %u\n"
	.text
	.globl	_Z9CircleFit9DataFrameS_
	.type	_Z9CircleFit9DataFrameS_, @function
_Z9CircleFit9DataFrameS_:
.LFB4129:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movq	%rdx, %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%rsi, %r13
	sarq	$32, %r14
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rcx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rdx, %rbx
	addq	$-128, %rsp
	.cfi_def_cfa_offset 176
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	movq	%rdi, %rax
	movl	%edi, 56(%rsp)
	sarq	$32, %rax
	imull	%eax, %edi
	movl	%eax, 60(%rsp)
	movslq	%edi, %rbp
	leaq	64(%rsp), %rdi
	salq	$2, %rbp
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L28
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L28:
	movq	64(%rsp), %rdi
	movq	%rbp, %rdx
	movl	$1, %ecx
	movq	%r13, %rsi
	call	cudaMemcpy@PLT
	movl	%ebx, 72(%rsp)
	imull	%r14d, %ebx
	leaq	80(%rsp), %rdi
	movl	%r14d, 76(%rsp)
	movslq	%ebx, %rbx
	salq	$2, %rbx
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %ebp
	testl	%eax, %eax
	je	.L29
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L29:
	leaq	8(%rsp), %rdi
	movl	$1, %edx
	movl	$4, %esi
	call	cudaMallocManaged@PLT
	testl	%ebp, %ebp
	je	.L30
	movl	%ebp, %edi
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L30:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	movl	$4, %edx
	leaq	4(%rsp), %r13
	leaq	104(%rsp), %r14
	call	cudaMemset@PLT
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movq	%r13, %rdi
	movl	$4, %edx
	call	cudaMemcpy@PLT
	movl	4(%rsp), %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC5(%rip), %rsi
	call	__printf_chk@PLT
	leaq	16(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	24(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movabsq	$68719476752, %rdx
	movl	$1, %esi
	movabsq	$34359738376, %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L31
	movups	56(%rsp), %xmm1
	movups	72(%rsp), %xmm2
	leaq	88(%rsp), %rdi
	movq	%r14, %rsi
	movq	8(%rsp), %rdx
	movups	%xmm1, 88(%rsp)
	movups	%xmm2, 104(%rsp)
	call	_Z42__device_stub__Z10GridKernel9DataFrameS_PjR9DataFrameS0_Pj
.L31:
	call	cudaDeviceSynchronize@PLT
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	movl	%eax, %ebp
	call	cudaEventRecord@PLT
	movq	24(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	movq	%r14, %rdi
	call	cudaEventElapsedTime@PLT
	testl	%ebp, %ebp
	je	.L32
	movl	%ebp, %edi
	call	cudaGetErrorString@PLT
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L32:
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	104(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	80(%rsp), %rsi
	movq	%r12, %rdi
	movq	%rbx, %rdx
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L33
	call	cudaGetErrorString@PLT
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L33:
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movl	$4, %edx
	movq	%r13, %rdi
	call	cudaMemcpy@PLT
	movl	4(%rsp), %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC9(%rip), %rsi
	call	__printf_chk@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	80(%rsp), %rdi
	call	cudaFree@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movss	104(%rsp), %xmm0
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L34
	call	__stack_chk_fail@PLT
.L34:
	subq	$-128, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4129:
	.size	_Z9CircleFit9DataFrameS_, .-_Z9CircleFit9DataFrameS_
	.section	.rodata.str1.1
.LC10:
	.string	"_Z10GridKernel9DataFrameS_Pj"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4175:
	.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	.LC10(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z10GridKernel9DataFrameS_Pj(%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
.LFE4175:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text._ZNSt12_Vector_baseIfSaIfEED2Ev,"axG",@progbits,_ZNSt12_Vector_baseIfSaIfEED5Ev,comdat
	.align 2
	.weak	_ZNSt12_Vector_baseIfSaIfEED2Ev
	.type	_ZNSt12_Vector_baseIfSaIfEED2Ev, @function
_ZNSt12_Vector_baseIfSaIfEED2Ev:
.LFB4500:
	.cfi_startproc
	endbr64
	movq	(%rdi), %rax
	testq	%rax, %rax
	je	.L53
	movq	16(%rdi), %rsi
	movq	%rax, %rdi
	subq	%rax, %rsi
	jmp	_ZdlPvm@PLT
.L53:
	ret
	.cfi_endproc
.LFE4500:
	.size	_ZNSt12_Vector_baseIfSaIfEED2Ev, .-_ZNSt12_Vector_baseIfSaIfEED2Ev
	.weak	_ZNSt12_Vector_baseIfSaIfEED1Ev
	.set	_ZNSt12_Vector_baseIfSaIfEED1Ev,_ZNSt12_Vector_baseIfSaIfEED2Ev
	.section	.rodata._ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_.str1.1,"aMS",@progbits,1
.LC11:
	.string	"vector::_M_realloc_insert"
	.section	.text._ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_,"axG",@progbits,_ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_,comdat
	.align 2
	.weak	_ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_
	.type	_ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_, @function
_ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_:
.LFB4695:
	.cfi_startproc
	endbr64
	movabsq	$2305843009213693951, %rcx
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	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
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	8(%rdi), %rax
	movq	(%rdi), %r14
	movq	%rax, %rbx
	movq	%rax, (%rsp)
	subq	%r14, %rbx
	sarq	$2, %rbx
	cmpq	%rcx, %rbx
	jne	.L56
	leaq	.LC11(%rip), %rdi
	call	_ZSt20__throw_length_errorPKc@PLT
.L56:
	cmpq	%r14, (%rsp)
	movl	$1, %eax
	movq	%rsi, %r15
	movq	%rdi, %r13
	cmovne	%rbx, %rax
	movq	%rsi, %rbp
	addq	%rax, %rbx
	setc	%al
	subq	%r14, %r15
	movzbl	%al, %eax
	testq	%rax, %rax
	jne	.L66
	xorl	%r12d, %r12d
	testq	%rbx, %rbx
	je	.L61
	movabsq	$2305843009213693951, %rax
	cmpq	%rax, %rbx
	cmova	%rax, %rbx
	jmp	.L60
.L66:
	movq	%rcx, %rbx
.L60:
	leaq	0(,%rbx,4), %rdi
	movq	%rdx, 8(%rsp)
	call	_Znwm@PLT
	movq	8(%rsp), %rdx
	movq	%rax, %r12
.L61:
	movss	(%rdx), %xmm0
	movss	%xmm0, (%r12,%r15)
	testq	%r15, %r15
	jle	.L62
	movq	%r15, %rdx
	movq	%r14, %rsi
	movq	%r12, %rdi
	call	memmove@PLT
.L62:
	movq	(%rsp), %rax
	leaq	4(%r12,%r15), %rdx
	subq	%rbp, %rax
	testq	%rax, %rax
	jle	.L63
	movq	%rdx, %rdi
	movq	%rbp, %rsi
	movq	%rax, %rcx
	rep movsb
.L63:
	leaq	(%rdx,%rax), %rbp
	testq	%r14, %r14
	je	.L64
	movq	16(%r13), %rsi
	movq	%r14, %rdi
	subq	%r14, %rsi
	call	_ZdlPvm@PLT
.L64:
	leaq	(%r12,%rbx,4), %rax
	movq	%r12, 0(%r13)
	movq	%rbp, 8(%r13)
	movq	%rax, 16(%r13)
	addq	$24, %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
.LFE4695:
	.size	_ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_, .-_ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_
	.section	.rodata.str1.1
.LC12:
	.string	"file.dat"
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB4137:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4137
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$4, %edx
	leaq	.LC12(%rip), %rsi
	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	$568, %rsp
	.cfi_def_cfa_offset 608
	movq	%fs:40, %rax
	movq	%rax, 552(%rsp)
	xorl	%eax, %eax
	leaq	32(%rsp), %rbp
	xorl	%eax, %eax
	movq	%rbp, %rdi
	movq	%rax, 8(%rsp)
	movq	%rax, 16(%rsp)
	movq	%rax, 24(%rsp)
.LEHB0:
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode@PLT
.LEHE0:
	leaq	4(%rsp), %rbx
.L74:
	testb	$2, 320(%rsp)
	jne	.L86
	movl	$4, %edx
	movq	%rbx, %rsi
	movq	%rbp, %rdi
.LEHB1:
	call	_ZNSi4readEPcl@PLT
	movq	16(%rsp), %rsi
	cmpq	24(%rsp), %rsi
	je	.L75
	movss	4(%rsp), %xmm0
	addq	$4, %rsi
	movss	%xmm0, -4(%rsi)
	movq	%rsi, 16(%rsp)
	jmp	.L74
.L75:
	leaq	8(%rsp), %rdi
	movq	%rbx, %rdx
	call	_ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_
	jmp	.L74
.L86:
	movq	%rbp, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEE5closeEv@PLT
	movq	8(%rsp), %r13
	movq	16(%rsp), %rbx
	movl	$180, %edi
	call	malloc@PLT
	subq	%r13, %rbx
	movq	%rax, %rcx
	movq	%r13, %rsi
	movq	%rax, %r12
	sarq	$2, %rbx
	shrq	%rbx
	salq	$32, %rbx
	movq	%rbx, %rdi
	movabsq	$64424509443, %rbx
	orq	$2, %rdi
	movq	%rbx, %rdx
	call	_Z9CircleFit9DataFrameS_
	movq	%rbx, %rdi
	movq	%r12, %rsi
	call	_Z4dump9DataFrame
.LEHE1:
	movq	%rbp, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	leaq	8(%rsp), %rdi
	call	_ZNSt12_Vector_baseIfSaIfEED2Ev
	movq	552(%rsp), %rax
	subq	%fs:40, %rax
	je	.L81
	jmp	.L84
.L83:
	endbr64
	movq	%rax, %rbx
.L78:
	movq	%rbp, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	jmp	.L79
.L82:
	endbr64
	movq	%rax, %rbx
.L79:
	leaq	8(%rsp), %rdi
	call	_ZNSt12_Vector_baseIfSaIfEED2Ev
	movq	552(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L84
	movq	%rbx, %rdi
.LEHB2:
	call	_Unwind_Resume@PLT
.LEHE2:
.L84:
	call	__stack_chk_fail@PLT
.L81:
	addq	$568, %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
.LFE4137:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA4137:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4137-.LLSDACSB4137
.LLSDACSB4137:
	.uleb128 .LEHB0-.LFB4137
	.uleb128 .LEHE0-.LEHB0
	.uleb128 .L82-.LFB4137
	.uleb128 0
	.uleb128 .LEHB1-.LFB4137
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L83-.LFB4137
	.uleb128 0
	.uleb128 .LEHB2-.LFB4137
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
.LLSDACSE4137:
	.section	.text.startup
	.size	main, .-main
	.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
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.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>
#include <math.h>
#include <iostream>
#include <inttypes.h>
#include <vector>
#include <fstream> // I/O

//struct DataFrame
struct DataFrame
{
  int w;
  int h;
  float* e;
};


//Thread block size
#define BLOCK_SIZE 16 //number of threads for each block
#define GRID_SIZE 128 //dimension of entire space
//warning GRID_SIZE must be multiple of 16
#define BIN_SIZE 4 //size of a hisogram bin
#define TH 30 //threshold for triggering the histogram

__global__ void GridKernel(const DataFrame, DataFrame, unsigned int*); //aggiungere i parametri



//------------------------------------------------------------
//Histogram algorithm HOST CODE
float CircleFit(const DataFrame data, DataFrame circles)
{
  //load data to device memory
  DataFrame d_data;
  d_data.w = data.w;
  d_data.h = data.h;
  size_t size = data.w * data.h * sizeof(float);
  hipError_t err = hipMalloc(&d_data.e, size);
  if(err)
    printf("CUDA malloc data DataFrame: %s\n",hipGetErrorString(err));
  hipMemcpy(d_data.e, data.e, size, hipMemcpyHostToDevice);

  //allocate circles
  DataFrame d_circles;
  d_circles.w = circles.w;
  d_circles.h = circles.h;
  size = circles.w * circles.h * sizeof(float);
  err = hipMalloc(&d_circles.e, size);
  if(err)
    printf("CUDA malloc circles DataFrame: %s\n",hipGetErrorString(err));

  //allocate variable for counting circles found  
  unsigned int *d_counter;
  unsigned int  h_counter;

  hipMallocManaged(&d_counter, sizeof(unsigned int));
    if(err)
    printf("CUDA malloc counter variable: %s\n",hipGetErrorString(err));

  // printf("initialized counter : %u\n", *counter);
  // Hai assegnato al puntatore l'indirizzo di memoria da utilizzare, ma e' memoria della GPU, non puoi accedere da qui
  // ma il valore nella cella puntata non e' inizializzato
  hipMemset(d_counter, 0, sizeof(unsigned int));
  hipMemcpy(&h_counter, d_counter, sizeof(unsigned int), hipMemcpyDeviceToHost);

  printf("initialized counter : %u\n", h_counter);



  // 

  float time;
  hipEvent_t start,stop;
  hipEventCreate(&start);
  hipEventCreate(&stop);
  //start time
  hipEventRecord(start);

   // Define the geometry
  dim3 dimBlock(BLOCK_SIZE, BLOCK_SIZE);
  dim3 dimGrid(GRID_SIZE/ dimBlock.x, GRID_SIZE/ dimBlock.y);
      //warning GRID_SIZE must be multiple of 16

  // Invoke kernel
  GridKernel<<<dimGrid, dimBlock>>>(d_data, d_circles, d_counter);
  err = hipDeviceSynchronize();

  //stop time
  hipEventRecord(stop);
  hipEventSynchronize(stop);
  hipEventElapsedTime(&time, start, stop);

  if(err)
    printf("Run kernel: %s\n", hipGetErrorString(err));

  printf("Time: %3.5f ms\n",time);

  // Read C from device memory
  size = circles.w * circles.h * sizeof(float);
  err = hipMemcpy(circles.e, d_circles.e, size, hipMemcpyDeviceToHost);
  if(err)
    printf("Copy circles off of device: %s\n",hipGetErrorString(err));

  hipMemcpy(&h_counter, d_counter, sizeof(unsigned int), hipMemcpyDeviceToHost);
  printf("counter : %u\n", h_counter);


  // Free device memory
  hipFree(d_data.e);
  hipFree(d_circles.e);
  hipFree(d_counter);

  return time;
} //END HOST FUNCTION



//---------------------------------------------------------

// thread aware log function
__device__ void log_msg(const char * message)
{
  printf("%d.%d.%d.%d-%s", blockIdx.x, blockIdx.y, threadIdx.x, threadIdx.y, message);
}

//Device function to calculate distance
__device__ float Distance2(float x, float y, float xd, float yd)
{
  return (x-xd)*(x-xd)+(y-yd)*(y-yd);
}


//---------------------------------------------------------
//Device function to Get Element from data
__device__ float GetElement(const DataFrame D, int row, int col)
{
  if ( (row < D.h ) && (col < D.w ) )
    return D.e[row * D.w + col];
  else 
    return 0.0;
}


//---------------------------------------------------------------
//Device function to Set Element of data
__device__ void SetElement(DataFrame D, int row, int col, float value) 
{
  if ( (row < D.h ) && (col < D.w ) )
   D.e[row * D.w + col] = value;
}


//---------------------------------------------------------
//Device function to fill histo
// __device__ void HistoFill(int x, int y, DataFrame data,int *h, DataFrame circles, unsigned int *counter)
__device__ void HstFill(int x, int y, DataFrame data,DataFrame circles, unsigned int *counter)
{
  const size_t HST_SIZE = GRID_SIZE*GRID_SIZE/BIN_SIZE;
  int 	       hst[HST_SIZE] = {0}; // va inizializzato
  int 	       i, idx;

  // log_id(); printf("HstFill\n");

  // atomicAdd(counter,1);

  for ( i=0; i<data.h; i++)
  {
    // float xd, yd, d;
    float xd, yd;
    int d;
    
    xd = GetElement(data, i, 0);
    yd = GetElement(data, i, 1);
    d  = __float2int_rn(  Distance2( __int2float_rn(x), __int2float_rn(y),xd,yd) ) / BIN_SIZE ;

    if (d < HST_SIZE) hst[d] +=1; // questo if serve per evitare errori di accesso alla memoria nel caso di valori "strani"

    
    // potrebbero lavorare piu' thread sullo stesso elemento 
    // va implementato un meccanismo di locking per evitarlo
    // in piu' questo blocco va eseguito solo al termine del ciclo for, quando hai ormai analizzato tutti i punti
    // altrimenti crei (n - TH)  volte lo stesso cerchio

    /*
    if(hst[bin]>TH)
    {
      idx = atomicAdd(counter,1); // garantisce che l'incremento avvenga un thread alla volta, quindi idx puo' essere usato solo dal thread in esecuzione

      SetElement(circles, idx,0,x);
      SetElement(circles, idx,1,y);
      // float r2=d;
      // SetElement(circles, idx,2,r2);
      SetElement(circles, idx,2,d);
    }
    */
  }


  // dopo aver riempito l'array hst, scandisce tutti gli elementi e aggiunge alla lista dei cerchi il cerchio trovato
  for ( i=0; i < HST_SIZE; i++)
  {
    if(hst[i]>TH)
    {
      idx = atomicAdd(counter,1); // garantisce che l'incremento avvenga un thread alla volta, quindi idx puo' essere usato solo dal thread in esecuzione

      //log_msg(""); printf("counter: %d, x %f, y %f, radius: %f\n", idx, __int2float_rn(x), __int2float_rn(y),  sqrt( __int2float_rn(i*BIN_SIZE) ) );

      SetElement(circles, idx,0, __int2float_rn(x));
      SetElement(circles, idx,1, __int2float_rn(y));
      // float r2=d;
      // SetElement(circles, idx,2,r2);
      SetElement(circles, idx,2, sqrt( __int2float_rn(i*BIN_SIZE) ) );
    }

  }
}




//---------------------------------------------------------
//Histogram algorithm kernel
__global__ void GridKernel(DataFrame data, DataFrame circles,unsigned int *counter)
{
  //x and y indexes
  int x = blockIdx.x * blockDim.x+ threadIdx.x - (GRID_SIZE / 2);
  int y = blockIdx.y * blockDim.y +threadIdx.y - (GRID_SIZE / 2);

//  const size_t histo_size = GRID_SIZE*GRID_SIZE/BIN_SIZE;
//  int histo[histo_size];
//  se con histo non ci fai niente, e' inutile definirla qui e passarla alla funzione
//  in piu' il contenuto non e' inizializzato

//  HistoFill(x,y, data, histo, circles, counter);
  HstFill(x,y, data, circles, counter);


}


//------------------------------------------------------------
//dump dataframe function
void dump(DataFrame m)
{
  for (int i = 0; i< m.h; i++)     // Loop sulle righe
  {
    for (int j = 0; j< m.w; j++)    // Loop sulle colonne
      printf("%3.1f\t", m.e[i*m.w + j]);
    printf("\n");  // A capo di fine riga
  }
  printf("\n");
}



//------------------------------------------------------------
//read floats from file.dat
void readBin(std::vector<float> buf)
{
}



//-------------------------------------------------------------
int main(int argc, char** argv)
{
  std::vector<float> buf;
  std::ifstream in("file.dat",std::ios::binary); //open the input file
  while(!in.eof())
  {
    float w;
    in.read( (char*) &w, sizeof(w));
    buf.push_back(w);
  }

  in.close(); //close the input file .... ormai i dati sono letti, puoi chiudere il file

  DataFrame data, circles;

  data.h = buf.size()>>1;
  data.w = 2;
  data.e = (float*) malloc(data.w * data.h * sizeof(float));

  circles.h = 15;
  circles.w = 3;
  circles.e = (float*) malloc(circles.w * circles.h * sizeof(float));

  data.e = &buf[0]; //copy imported floats from buf to data .... non stai copiando i dati, se fai cosi' non ti serve la memoria che hai allocato prima

  float a = CircleFit(data, circles);

//  dump(data);
  dump(circles);

  // in.close(); //close the input file
  return 0;
}

	.text
	.file	"reticolo.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z9CircleFit9DataFrameS_        # -- Begin function _Z9CircleFit9DataFrameS_
	.type	_Z9CircleFit9DataFrameS_,@function
_Z9CircleFit9DataFrameS_:               # @_Z9CircleFit9DataFrameS_
	.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	$72, %rsp
	.cfi_def_cfa_offset 128
	.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	%rcx, %rbx
	movq	%rdx, %r14
	movq	%rsi, %r15
	movq	%rdx, %r13
	shrq	$32, %r13
	leaq	56(%rsp), %rax
	movq	%rdi, -8(%rax)
	movq	%rdi, %rcx
	shrq	$32, %rcx
	imull	%edi, %ecx
	movslq	%ecx, %r12
	shlq	$2, %r12
	movq	%rax, %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	je	.LBB0_2
# %bb.1:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB0_2:
	movq	56(%rsp), %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	40(%rsp), %rdi
	movl	%r14d, -8(%rdi)
	movl	%r13d, -4(%rdi)
	imull	%r13d, %r14d
	movslq	%r14d, %r14
	shlq	$2, %r14
	movq	%r14, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	je	.LBB0_4
# %bb.3:
	movl	%eax, %ebp
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
	movq	%rsp, %rdi
	movl	$4, %esi
	movl	$1, %edx
	callq	hipMallocManaged
	movl	%ebp, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB0_5
.LBB0_4:                                # %.critedge
	movq	%rsp, %rdi
	movl	$4, %esi
	movl	$1, %edx
	callq	hipMallocManaged
.LBB0_5:
	movq	(%rsp), %rdi
	movl	$4, %edx
	xorl	%esi, %esi
	callq	hipMemset
	movq	(%rsp), %rsi
	leaq	28(%rsp), %r15
	movl	$4, %edx
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	(%r15), %esi
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	64(%rsp), %r15
	movq	%r15, %rdi
	callq	hipEventCreate
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	movq	(%r15), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movabsq	$34359738376, %rdi              # imm = 0x800000008
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_7
# %bb.6:
	movq	48(%rsp), %rdi
	movq	56(%rsp), %rsi
	movq	32(%rsp), %rdx
	movq	40(%rsp), %rcx
	movq	(%rsp), %r8
	callq	_Z25__device_stub__GridKernel9DataFrameS_Pj
.LBB0_7:
	callq	hipDeviceSynchronize
	movl	%eax, %ebp
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	movq	64(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	12(%rsp), %rdi
	callq	hipEventElapsedTime
	testl	%ebp, %ebp
	je	.LBB0_9
# %bb.8:
	movl	%ebp, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB0_9:
	cvtss2sd	12(%rsp), %xmm0
	movl	$.L.str.5, %edi
	movb	$1, %al
	callq	printf
	movq	40(%rsp), %rsi
	movq	%rbx, %rdi
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	je	.LBB0_11
# %bb.10:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.6, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB0_11:
	movq	(%rsp), %rsi
	leaq	28(%rsp), %rbx
	movl	$4, %edx
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	(%rbx), %esi
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	movq	56(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipFree
	movss	12(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	addq	$72, %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_end0:
	.size	_Z9CircleFit9DataFrameS_, .Lfunc_end0-_Z9CircleFit9DataFrameS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z25__device_stub__GridKernel9DataFrameS_Pj # -- Begin function _Z25__device_stub__GridKernel9DataFrameS_Pj
	.type	_Z25__device_stub__GridKernel9DataFrameS_Pj,@function
_Z25__device_stub__GridKernel9DataFrameS_Pj: # @_Z25__device_stub__GridKernel9DataFrameS_Pj
	.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
	leaq	80(%rsp), %rax
	movq	%rdi, (%rax)
	movq	%rsi, 8(%rax)
	leaq	64(%rsp), %rsi
	movq	%rdx, (%rsi)
	movq	%rcx, 8(%rsi)
	leaq	24(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rsi, 8(%rbx)
	movq	%rcx, 16(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%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	$_Z10GridKernel9DataFrameS_Pj, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z25__device_stub__GridKernel9DataFrameS_Pj, .Lfunc_end1-_Z25__device_stub__GridKernel9DataFrameS_Pj
	.cfi_endproc
                                        # -- End function
	.globl	_Z4dump9DataFrame               # -- Begin function _Z4dump9DataFrame
	.type	_Z4dump9DataFrame,@function
_Z4dump9DataFrame:                      # @_Z4dump9DataFrame
	.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
	movq	%rsi, 8(%rsp)                   # 8-byte Spill
	movq	%rdi, %rax
	shrq	$32, %rax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	testl	%eax, %eax
	jle	.LBB2_6
# %bb.1:                                # %.preheader.lr.ph
	movq	%rdi, %r14
	movl	%r14d, %r12d
	xorl	%r13d, %r13d
	xorl	%ebp, %ebp
.LBB2_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_4 Depth 2
	testl	%r14d, %r14d
	jle	.LBB2_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB2_2 Depth=1
	movl	%r13d, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,4), %rbx
	xorl	%r15d, %r15d
.LBB2_4:                                #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%r15,4), %xmm0
	movl	$.L.str.8, %edi
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB2_4
.LBB2_5:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%rbp
	addl	%r14d, %r13d
	cmpq	16(%rsp), %rbp                  # 8-byte Folded Reload
	jne	.LBB2_2
.LBB2_6:                                # %._crit_edge11
	movl	$10, %edi
	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
	jmp	putchar@PLT                     # TAILCALL
.Lfunc_end2:
	.size	_Z4dump9DataFrame, .Lfunc_end2-_Z4dump9DataFrame
	.cfi_endproc
                                        # -- End function
	.globl	_Z7readBinSt6vectorIfSaIfEE     # -- Begin function _Z7readBinSt6vectorIfSaIfEE
	.type	_Z7readBinSt6vectorIfSaIfEE,@function
_Z7readBinSt6vectorIfSaIfEE:            # @_Z7readBinSt6vectorIfSaIfEE
	.cfi_startproc
# %bb.0:
	retq
.Lfunc_end3:
	.size	_Z7readBinSt6vectorIfSaIfEE, .Lfunc_end3-_Z7readBinSt6vectorIfSaIfEE
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %bb.0:                                # %.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$560, %rsp                      # imm = 0x230
	.cfi_def_cfa_offset 592
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	xorps	%xmm0, %xmm0
	movaps	%xmm0, 16(%rsp)
	movq	$0, 32(%rsp)
	leaq	40(%rsp), %rbx
	movl	$.L.str.10, %esi
	movq	%rbx, %rdi
	movl	$4, %edx
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode
	movq	(%rbx), %rax
	movq	-24(%rax), %rax
	testb	$2, 72(%rsp,%rax)
	jne	.LBB4_7
# %bb.1:                                # %.lr.ph
	leaq	40(%rsp), %rbx
	leaq	12(%rsp), %r14
	leaq	16(%rsp), %r15
.LBB4_2:                                # =>This Inner Loop Header: Depth=1
.Ltmp0:
	movl	$4, %edx
	movq	%rbx, %rdi
	movq	%r14, %rsi
	callq	_ZNSi4readEPcl
.Ltmp1:
# %bb.3:                                #   in Loop: Header=BB4_2 Depth=1
	movq	24(%rsp), %rsi
	cmpq	32(%rsp), %rsi
	je	.LBB4_5
# %bb.4:                                #   in Loop: Header=BB4_2 Depth=1
	movss	12(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%rsi)
	addq	$4, %rsi
	movq	%rsi, 24(%rsp)
	jmp	.LBB4_6
.LBB4_5:                                #   in Loop: Header=BB4_2 Depth=1
.Ltmp2:
	movq	%r15, %rdi
	movq	%r14, %rdx
	callq	_ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_
.Ltmp3:
.LBB4_6:                                # %_ZNSt6vectorIfSaIfEE9push_backERKf.exit
                                        #   in Loop: Header=BB4_2 Depth=1
	movq	40(%rsp), %rax
	movq	-24(%rax), %rax
	testb	$2, 72(%rsp,%rax)
	je	.LBB4_2
.LBB4_7:                                # %._crit_edge
.Ltmp5:
	leaq	40(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEE5closeEv
.Ltmp6:
# %bb.8:
	movq	16(%rsp), %r14
	movq	24(%rsp), %r15
	subq	%r14, %r15
	andq	$-8, %r15
	shlq	$29, %r15
	orq	$2, %r15
	movl	$180, %edi
	callq	malloc
	movq	%rax, %rbx
.Ltmp8:
	movabsq	$64424509443, %rdx              # imm = 0xF00000003
	movq	%r15, %rdi
	movq	%r14, %rsi
	movq	%rax, %rcx
	callq	_Z9CircleFit9DataFrameS_
.Ltmp9:
# %bb.9:
	movabsq	$64424509443, %rdi              # imm = 0xF00000003
	movq	%rbx, %rsi
	callq	_Z4dump9DataFrame
	leaq	40(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev
	movq	16(%rsp), %rdi
	testq	%rdi, %rdi
	je	.LBB4_11
# %bb.10:
	callq	_ZdlPv
.LBB4_11:                               # %_ZNSt6vectorIfSaIfEED2Ev.exit
	xorl	%eax, %eax
	addq	$560, %rsp                      # imm = 0x230
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB4_14:
	.cfi_def_cfa_offset 592
.Ltmp10:
	jmp	.LBB4_15
.LBB4_12:
.Ltmp7:
	jmp	.LBB4_15
.LBB4_13:
.Ltmp4:
.LBB4_15:
	movq	%rax, %rbx
	leaq	40(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev
	movq	16(%rsp), %rdi
	testq	%rdi, %rdi
	je	.LBB4_17
# %bb.16:
	callq	_ZdlPv
.LBB4_17:                               # %_ZNSt6vectorIfSaIfEED2Ev.exit16
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end4:
	.size	main, .Lfunc_end4-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table4:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Lfunc_begin0-.Lfunc_begin0    # >> Call Site 1 <<
	.uleb128 .Ltmp0-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp3-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp3
	.uleb128 .Ltmp4-.Lfunc_begin0           #     jumps to .Ltmp4
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp5-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Ltmp6-.Ltmp5                  #   Call between .Ltmp5 and .Ltmp6
	.uleb128 .Ltmp7-.Lfunc_begin0           #     jumps to .Ltmp7
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp8-.Lfunc_begin0           # >> Call Site 4 <<
	.uleb128 .Ltmp9-.Ltmp8                  #   Call between .Ltmp8 and .Ltmp9
	.uleb128 .Ltmp10-.Lfunc_begin0          #     jumps to .Ltmp10
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp9-.Lfunc_begin0           # >> Call Site 5 <<
	.uleb128 .Lfunc_end4-.Ltmp9             #   Call between .Ltmp9 and .Lfunc_end4
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.section	.text._ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_,"axG",@progbits,_ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_,comdat
	.weak	_ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_ # -- Begin function _ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_
	.p2align	1, 0x90
	.type	_ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_,@function
_ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_: # @_ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_
	.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
	movq	%rdx, (%rsp)                    # 8-byte Spill
	movq	%rsi, %r12
	movq	%rdi, %rbx
	movl	$1, %esi
	movl	$.L.str.11, %edx
	callq	_ZNKSt6vectorIfSaIfEE12_M_check_lenEmPKc
	movq	(%rbx), %r13
	movq	8(%rbx), %r15
	movq	%r12, 8(%rsp)                   # 8-byte Spill
	subq	%r13, %r12
	movq	%r12, %r14
	sarq	$2, %r14
	testq	%rax, %rax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	je	.LBB5_1
# %bb.2:
	movq	%rbx, %rdi
	movq	%rax, %rsi
	xorl	%edx, %edx
	callq	_ZNSt15__new_allocatorIfE8allocateEmPKv
	movq	%rax, %rbp
	jmp	.LBB5_3
.LBB5_1:
	xorl	%ebp, %ebp
.LBB5_3:                                # %_ZNSt12_Vector_baseIfSaIfEE11_M_allocateEm.exit
	movq	(%rsp), %rax                    # 8-byte Reload
	movss	(%rax), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%rbp,%r14,4)
	testq	%r12, %r12
	jle	.LBB5_5
# %bb.4:
	movq	%rbp, %rdi
	movq	%r13, %rsi
	movq	%r12, %rdx
	callq	memmove@PLT
.LBB5_5:                                # %_ZNSt6vectorIfSaIfEE11_S_relocateEPfS2_S2_RS0_.exit
	addq	%rbp, %r12
	addq	$4, %r12
	movq	8(%rsp), %rsi                   # 8-byte Reload
	subq	%rsi, %r15
	testq	%r15, %r15
	jle	.LBB5_7
# %bb.6:
	movq	%r12, %rdi
	movq	%r15, %rdx
	callq	memmove@PLT
.LBB5_7:                                # %_ZNSt6vectorIfSaIfEE11_S_relocateEPfS2_S2_RS0_.exit16
	testq	%r13, %r13
	je	.LBB5_9
# %bb.8:
	movq	%r13, %rdi
	callq	_ZdlPv
.LBB5_9:                                # %_ZNSt12_Vector_baseIfSaIfEE13_M_deallocateEPfm.exit
	addq	%r15, %r12
	movq	%rbp, (%rbx)
	movq	%r12, 8(%rbx)
	movq	16(%rsp), %rax                  # 8-byte Reload
	leaq	(,%rax,4), %rax
	addq	%rbp, %rax
	movq	%rax, 16(%rbx)
	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	_ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_, .Lfunc_end5-_ZNSt6vectorIfSaIfEE17_M_realloc_insertIJRKfEEEvN9__gnu_cxx17__normal_iteratorIPfS1_EEDpOT_
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNKSt6vectorIfSaIfEE12_M_check_lenEmPKc,"axG",@progbits,_ZNKSt6vectorIfSaIfEE12_M_check_lenEmPKc,comdat
	.weak	_ZNKSt6vectorIfSaIfEE12_M_check_lenEmPKc # -- Begin function _ZNKSt6vectorIfSaIfEE12_M_check_lenEmPKc
	.p2align	1, 0x90
	.type	_ZNKSt6vectorIfSaIfEE12_M_check_lenEmPKc,@function
_ZNKSt6vectorIfSaIfEE12_M_check_lenEmPKc: # @_ZNKSt6vectorIfSaIfEE12_M_check_lenEmPKc
	.cfi_startproc
# %bb.0:
	movabsq	$2305843009213693951, %rcx      # imm = 0x1FFFFFFFFFFFFFFF
	movq	8(%rdi), %r8
	subq	(%rdi), %r8
	sarq	$2, %r8
	movq	%rcx, %rax
	subq	%r8, %rax
	cmpq	%rsi, %rax
	jb	.LBB6_2
# %bb.1:
	cmpq	%rsi, %r8
	cmovaq	%r8, %rsi
	leaq	(%rsi,%r8), %rax
	cmpq	%rcx, %rax
	cmovaeq	%rcx, %rax
	addq	%r8, %rsi
	cmovbq	%rcx, %rax
	retq
.LBB6_2:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	%rdx, %rdi
	callq	_ZSt20__throw_length_errorPKc
.Lfunc_end6:
	.size	_ZNKSt6vectorIfSaIfEE12_M_check_lenEmPKc, .Lfunc_end6-_ZNKSt6vectorIfSaIfEE12_M_check_lenEmPKc
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNSt15__new_allocatorIfE8allocateEmPKv,"axG",@progbits,_ZNSt15__new_allocatorIfE8allocateEmPKv,comdat
	.weak	_ZNSt15__new_allocatorIfE8allocateEmPKv # -- Begin function _ZNSt15__new_allocatorIfE8allocateEmPKv
	.p2align	1, 0x90
	.type	_ZNSt15__new_allocatorIfE8allocateEmPKv,@function
_ZNSt15__new_allocatorIfE8allocateEmPKv: # @_ZNSt15__new_allocatorIfE8allocateEmPKv
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	%rsi, %rax
	shrq	$61, %rax
	jne	.LBB7_1
# %bb.3:
	shlq	$2, %rsi
	movq	%rsi, %rdi
	popq	%rax
	.cfi_def_cfa_offset 8
	jmp	_Znwm                           # TAILCALL
.LBB7_1:
	.cfi_def_cfa_offset 16
	shrq	$62, %rsi
	je	.LBB7_2
# %bb.4:
	callq	_ZSt28__throw_bad_array_new_lengthv
.LBB7_2:
	callq	_ZSt17__throw_bad_allocv
.Lfunc_end7:
	.size	_ZNSt15__new_allocatorIfE8allocateEmPKv, .Lfunc_end7-_ZNSt15__new_allocatorIfE8allocateEmPKv
	.cfi_endproc
                                        # -- End function
	.text
	.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	.LBB8_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB8_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z10GridKernel9DataFrameS_Pj, %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_end8:
	.size	__hip_module_ctor, .Lfunc_end8-__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	.LBB9_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
.LBB9_2:
	retq
.Lfunc_end9:
	.size	__hip_module_dtor, .Lfunc_end9-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"CUDA malloc data DataFrame: %s\n"
	.size	.L.str, 32

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"CUDA malloc circles DataFrame: %s\n"
	.size	.L.str.1, 35

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"CUDA malloc counter variable: %s\n"
	.size	.L.str.2, 34

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"initialized counter : %u\n"
	.size	.L.str.3, 26

	.type	_Z10GridKernel9DataFrameS_Pj,@object # @_Z10GridKernel9DataFrameS_Pj
	.section	.rodata,"a",@progbits
	.globl	_Z10GridKernel9DataFrameS_Pj
	.p2align	3, 0x0
_Z10GridKernel9DataFrameS_Pj:
	.quad	_Z25__device_stub__GridKernel9DataFrameS_Pj
	.size	_Z10GridKernel9DataFrameS_Pj, 8

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Time: %3.5f ms\n"
	.size	.L.str.5, 16

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Copy circles off of device: %s\n"
	.size	.L.str.6, 32

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"counter : %u\n"
	.size	.L.str.7, 14

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"%3.1f\t"
	.size	.L.str.8, 7

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"file.dat"
	.size	.L.str.10, 9

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"vector::_M_realloc_insert"
	.size	.L.str.11, 26

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z10GridKernel9DataFrameS_Pj"
	.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

	.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 _Z25__device_stub__GridKernel9DataFrameS_Pj
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z10GridKernel9DataFrameS_Pj
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z10GridKernel9DataFrameS_Pj ; -- Begin function _Z10GridKernel9DataFrameS_Pj
	.globl	_Z10GridKernel9DataFrameS_Pj
	.p2align	8
	.type	_Z10GridKernel9DataFrameS_Pj,@function
_Z10GridKernel9DataFrameS_Pj:           ; @_Z10GridKernel9DataFrameS_Pj
; %bb.0:                                ; %loadstoreloop.preheader
	s_clause 0x3
	s_load_b128 s[8:11], s[0:1], 0x0
	s_load_b64 s[2:3], s[0:1], 0x10
	s_load_b128 s[4:7], s[0:1], 0x18
	s_load_b32 s12, s[0:1], 0x34
	v_dual_mov_b32 v1, 16 :: v_dual_mov_b32 v2, 0
	s_mov_b64 s[0:1], 0
.LBB0_1:                                ; %loadstoreloop
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_4) | instid1(VALU_DEP_2)
	s_add_u32 s0, s0, 1
	s_addc_u32 s1, s1, 0
	scratch_store_b8 v1, v2, off
	v_cmp_gt_u64_e64 s13, 0x4000, s[0:1]
	v_add_nc_u32_e32 v1, 1, v1
	s_and_b32 vcc_lo, exec_lo, s13
	s_cbranch_vccnz .LBB0_1
; %bb.2:                                ; %split
	v_and_b32_e32 v1, 0x3ff, v0
	v_bfe_u32 v0, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s0, s12, 0xffff
	s_lshr_b32 s1, s12, 16
	s_mul_i32 s14, s14, s0
	s_mul_i32 s15, s15, s1
	v_add3_u32 v2, v1, s14, 0xffffffc0
	v_add3_u32 v3, v0, s15, 0xffffffc0
	s_cmp_gt_i32 s9, 0
	s_mov_b32 s0, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cvt_f32_i32_e32 v0, v2
	v_cvt_f32_i32_e32 v1, v3
	s_cbranch_scc1 .LBB0_4
; %bb.3:                                ; %..preheader_crit_edge.i
	v_cvt_f32_i32_e32 v2, v2
	v_cvt_f32_i32_e32 v3, v3
	s_branch .LBB0_5
.LBB0_4:
	s_mov_b32 s0, -1
                                        ; implicit-def: $vgpr2
                                        ; implicit-def: $vgpr3
.LBB0_5:                                ; %Flow35
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 vcc_lo, exec_lo, s0
	s_cbranch_vccnz .LBB0_15
; %bb.6:                                ; %.lr.ph.i
	s_cmp_gt_i32 s8, 0
	s_mov_b32 s1, 0
	s_cselect_b32 s12, -1, 0
	s_cmp_gt_i32 s8, 1
	s_mov_b32 s0, s1
	s_cselect_b32 s13, -1, 0
	s_add_u32 s14, s10, 4
	s_addc_u32 s15, s11, 0
.LBB0_7:                                ; =>This Inner Loop Header: Depth=1
	s_and_not1_b32 vcc_lo, exec_lo, s12
	s_mov_b32 s16, 0
	s_cbranch_vccnz .LBB0_9
; %bb.8:                                ;   in Loop: Header=BB0_7 Depth=1
	s_lshl_b64 s[16:17], s[0:1], 2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s16, s10, s16
	s_addc_u32 s17, s11, s17
	s_load_b32 s16, s[16:17], 0x0
.LBB0_9:                                ; %_Z10GetElement9DataFrameii.exit.i
                                        ;   in Loop: Header=BB0_7 Depth=1
	s_and_not1_b32 vcc_lo, exec_lo, s13
	s_mov_b32 s17, 0
	s_cbranch_vccnz .LBB0_11
; %bb.10:                               ;   in Loop: Header=BB0_7 Depth=1
	s_lshl_b64 s[18:19], s[0:1], 2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s18, s14, s18
	s_addc_u32 s19, s15, s19
	s_load_b32 s17, s[18:19], 0x0
.LBB0_11:                               ; %_Z10GetElement9DataFrameii.exit46.i
                                        ;   in Loop: Header=BB0_7 Depth=1
	s_waitcnt lgkmcnt(0)
	v_dual_subrev_f32 v2, s17, v1 :: v_dual_subrev_f32 v3, s16, v0
	s_mov_b32 s16, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v2, v2, v2
	v_fmac_f32_e32 v2, v3, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_rndne_f32_e32 v2, v2
	v_cvt_i32_f32_e32 v2, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v3, 31, v2
	v_lshrrev_b32_e32 v3, 30, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v2, v2, v3
	v_ashrrev_i32_e32 v2, 2, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_u32_e32 0x1000, v2
	s_cbranch_execz .LBB0_13
; %bb.12:                               ;   in Loop: Header=BB0_7 Depth=1
	v_lshl_add_u32 v2, v2, 2, 16
	scratch_load_b32 v3, v2, off
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v3, 1, v3
	scratch_store_b32 v2, v3, off
.LBB0_13:                               ;   in Loop: Header=BB0_7 Depth=1
	s_or_b32 exec_lo, exec_lo, s16
	s_add_i32 s9, s9, -1
	s_add_i32 s0, s0, s8
	s_cmp_eq_u32 s9, 0
	s_cbranch_scc0 .LBB0_7
; %bb.14:
	v_dual_mov_b32 v2, v0 :: v_dual_mov_b32 v3, v1
.LBB0_15:                               ; %Flow36
	s_cmp_gt_i32 s2, 0
	v_mov_b32_e32 v4, 0
	s_cselect_b32 s1, -1, 0
	s_cmp_gt_i32 s2, 1
	s_mov_b32 s9, 0
	s_cselect_b32 s8, -1, 0
	s_cmp_gt_i32 s2, 2
	s_cselect_b32 s10, -1, 0
	s_add_u32 s11, s4, 4
	s_addc_u32 s12, s5, 0
	s_add_u32 s13, s4, 8
	s_addc_u32 s14, s5, 0
.LBB0_16:                               ; =>This Inner Loop Header: Depth=1
	s_add_i32 s0, s9, 16
	s_mov_b32 s15, exec_lo
	scratch_load_b32 v0, off, s0
	s_waitcnt vmcnt(0)
	v_cmpx_lt_i32_e32 30, v0
	s_cbranch_execz .LBB0_25
; %bb.17:                               ;   in Loop: Header=BB0_16 Depth=1
	s_mov_b32 s16, exec_lo
	s_mov_b32 s0, exec_lo
	v_mbcnt_lo_u32_b32 v0, s16, 0
                                        ; implicit-def: $vgpr1
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_19
; %bb.18:                               ;   in Loop: Header=BB0_16 Depth=1
	s_bcnt1_i32_b32 s16, s16
	s_delay_alu instid0(SALU_CYCLE_1)
	v_mov_b32_e32 v1, s16
	global_atomic_add_u32 v1, v4, v1, s[6:7] glc
.LBB0_19:                               ;   in Loop: Header=BB0_16 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	s_waitcnt vmcnt(0)
	v_readfirstlane_b32 s0, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v1, s0, v0
	v_mul_lo_u32 v0, v1, s2
	v_cmp_gt_i32_e32 vcc_lo, s3, v1
	s_and_b32 s0, vcc_lo, s1
	s_delay_alu instid0(VALU_DEP_2)
	v_ashrrev_i32_e32 v1, 31, v0
	s_and_saveexec_b32 s16, s0
	s_cbranch_execz .LBB0_21
; %bb.20:                               ;   in Loop: Header=BB0_16 Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[5:6], 2, v[0:1]
	v_add_co_u32 v5, s0, s4, v5
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v6, s0, s5, v6, s0
	global_store_b32 v[5:6], v2, off
.LBB0_21:                               ; %_Z10SetElement9DataFrameiif.exit.i
                                        ;   in Loop: Header=BB0_16 Depth=1
	s_or_b32 exec_lo, exec_lo, s16
	s_and_b32 s0, vcc_lo, s8
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s16, s0
	s_cbranch_execz .LBB0_23
; %bb.22:                               ;   in Loop: Header=BB0_16 Depth=1
	v_lshlrev_b64 v[5:6], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v5, s0, s11, v5
	v_add_co_ci_u32_e64 v6, s0, s12, v6, s0
	global_store_b32 v[5:6], v3, off
.LBB0_23:                               ; %_Z10SetElement9DataFrameiif.exit49.i
                                        ;   in Loop: Header=BB0_16 Depth=1
	s_or_b32 exec_lo, exec_lo, s16
	s_and_b32 s0, vcc_lo, s10
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 exec_lo, exec_lo, s0
	s_cbranch_execz .LBB0_25
; %bb.24:                               ;   in Loop: Header=BB0_16 Depth=1
	v_cvt_f32_i32_e32 v5, s9
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v6, 0x4f800000, v5
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v5
	v_cndmask_b32_e32 v5, v5, v6, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_2)
	v_sqrt_f32_e32 v6, v5
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v7, -1, v6
	v_add_nc_u32_e32 v8, 1, v6
	v_fma_f32 v9, -v7, v6, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v10, -v8, v6, v5
	v_cmp_ge_f32_e64 s0, 0, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v6, v6, v7, s0
	v_cmp_lt_f32_e64 s0, 0, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v6, v6, v8, s0
	v_mul_f32_e32 v7, 0x37800000, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_4)
	v_cndmask_b32_e32 v6, v6, v7, vcc_lo
	v_add_co_u32 v0, vcc_lo, s13, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s14, v1, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v5, 0x260
	v_cndmask_b32_e32 v5, v6, v5, vcc_lo
	global_store_b32 v[0:1], v5, off
.LBB0_25:                               ; %Flow33
                                        ;   in Loop: Header=BB0_16 Depth=1
	s_or_b32 exec_lo, exec_lo, s15
	s_add_i32 s9, s9, 4
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmpk_lg_i32 s9, 0x4000
	s_cbranch_scc1 .LBB0_16
; %bb.26:                               ; %_Z7HstFillii9DataFrameS_Pj.exit
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10GridKernel9DataFrameS_Pj
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 16400
		.amdhsa_kernarg_size 296
		.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 1
		.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 11
		.amdhsa_next_free_sgpr 20
		.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	_Z10GridKernel9DataFrameS_Pj, .Lfunc_end0-_Z10GridKernel9DataFrameS_Pj
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 936
; NumSgprs: 22
; NumVgprs: 11
; ScratchSize: 16400
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 22
; NumVGPRsForWavesPerEU: 11
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 1
; 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:
      - .offset:         0
        .size:           16
        .value_kind:     by_value
      - .offset:         16
        .size:           16
        .value_kind:     by_value
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z10GridKernel9DataFrameS_Pj
    .private_segment_fixed_size: 16400
    .sgpr_count:     22
    .sgpr_spill_count: 0
    .symbol:         _Z10GridKernel9DataFrameS_Pj.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     11
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
