#include <math.h>
#include <stdio.h>
#include <getopt.h>

#define FILE_SIZE 666
#define BLOCKSIZE 256
#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }

inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true)
{
  if (code != cudaSuccess){
    fprintf(stderr, "GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
    if (abort) exit(code);
  }
}


__device__ int d_m;
__device__ float d_r;

// Kernel functions
__global__ 
void reduce(int *g_idata, unsigned int *g_out) {
  __shared__ int sdata[BLOCKSIZE];
  // each thread loads one element from global to shared mem
  int i = blockIdx.x*blockDim.x + threadIdx.x;

  sdata[threadIdx.x] = g_idata[i];

  __syncthreads();
  // do reduction in shared mem
  for (int s=1; s < blockDim.x; s *=2)
  {
    int index = 2 * s * threadIdx.x;
    if (index < blockDim.x)
    {
      sdata[index] += sdata[index + s];
    }
    __syncthreads();
  }

  // write result for this block to global mem
  if (threadIdx.x == 0){
      atomicAdd(g_out, sdata[0]);
  }
}

__device__
bool is_equal(float a, float b, float eps)
{
  return fabs(a - b) <= eps ? true : false;
}

__global__
void findvec(float *base_vec, int m, float *in, int *mvec)
{
  int index = blockIdx.x * blockDim.x + threadIdx.x;
  int i;
  
  // check if vec of size m is similar
  int found = true;
  for (i = 0; i < m; i++){
    if (!is_equal(in[index + i], base_vec[i], d_r)){
      found = false;
      break;
    }
  }
  if (found) {
      mvec[index] = 1;
  }
}

int load_data(char *fname, float *x)
{
  FILE *f = fopen(fname, "r");
  float buf;
  int i = 0;
  while(fscanf(f, "%f", &buf) > 0)
    x[i++] = buf;
  fclose(f);
  return i - 1;
}

int countlines(char *fname)
{
    FILE *f = fopen(fname, "r");
    if (f == NULL)
        return -1;

    char z, buf;
    int linenumbers = 0;
    while((z = fgetc(f)) != EOF)
        if (z == '\n')
            linenumbers++;
        buf = z;
    
    printf("last: %i\n", buf);
    fclose(f);
    return linenumbers;
}

// parameters
typedef struct {
  float r;                  // max distance
  int m;                    // embed dim
  char infile[FILE_SIZE];   //
  char outfile[FILE_SIZE];  //
  bool apen;                 // 1: approximate not sample entropy
} params;

static struct option options[] = {
    {"in", required_argument, NULL, 'i'},
    {"out", required_argument, NULL, 'o'},
    {"embed", required_argument, NULL, 'm'},
    {"radius", required_argument, NULL, 'r'},
    {"apen", required_argument, NULL, 'a'},
};

void dump_params(params * p)
{
  fprintf(stdout,"#\n");
  fprintf(stdout,"#m:%d\n",p->m);
  fprintf(stdout,"#r:%f\n",p->r);
  fprintf(stdout,"#infile:%s\n",p->infile);
  fprintf(stdout,"#outfile:%s\n",p->outfile);
  fprintf(stdout,"#approx:%d\n",p->apen);
  fflush(stdout);
}

void usage(char **argv)
{
    printf("Usage: %s <params> \n\n", argv[0]);
    printf("Model params:\n");
    printf("   -m, --embed=INT        set the embedding dimension 'dim' to INT\n");
    printf("   -r, --radius=FLOAT     set the maximal distance between vectors\n");
    printf("                          to 'radius' to FLOAT\n");
    printf("   -i, --in=FILE_NAME     set the input data to FILE_NAME\n");
    printf("   -o, --out=FILE_NAME    set the output data to FILE_NAME\n");
    printf("   -a, --apen=INT         calculates Approximate Entropy (1) instead of SampEn (def, 0)\n");
    printf("\n");
}

void parse_arguments(int argc, char **argv, params *p)
{
  int c;

  while( (c = getopt_long(argc, argv, "mrioa:", options, NULL)) != EOF) {
    switch (c) {
      case 'm':
        sscanf(optarg, "%d", &(p->m));
        break;
      case 'r':
        sscanf(optarg, "%f", &(p->r));
        break;
      case 'i':
        strcpy(p->infile, optarg);
        break;
      case 'o':
        strcpy(p->outfile, optarg);
        break;
      case 'a':
        int buf;
        sscanf(optarg, "%i", &buf);
        p->apen = buf;
        break;
    }
  }
}

float sandard_deviation(float *x, int N)
{
  int i;
  float sd = 0, mean = 0;
  
  for (i = 0; i < N; ++i){
    mean += x[i];
    sd += x[i] * x[i];
  }
  
  mean /= N;
  sd = sd / N - mean * mean;
  
  return sqrt(sd);
}

int
find_similar_vectors(float *x, int N, int m, int numBlocks, int blockSize, bool apen=false)
{
    int i; //dummy idx
    
    // space in shared mem for base vec m
    float *base_vec;
    gpuErrchk(cudaMallocManaged(&base_vec, m * sizeof(float)));
    
    // space in shared mem for reduction
    unsigned int *matches;
    gpuErrchk(cudaMallocManaged(&matches, sizeof(unsigned int)));
    
    // space in shared mem for identical vectors
    int *mvec;
    gpuErrchk(cudaMallocManaged(&mvec, N * sizeof(int)));

    // search for EACH possible base vec of length m + 1
    unsigned long n = 0;
    for (int ibv = 0; ibv <= N - m; ibv++){
      // build temporary base vec of length m
      for (i = ibv; i < ibv + m; ++i) base_vec[i - ibv] = x[i];

      // matches per node
      for (i = 0; i < N; ++i) mvec[i] = 0;  

      // Run kernel on the GPU
      // find matches for temporary vec
      findvec<<<numBlocks, blockSize>>>(base_vec, m, x, mvec);
      gpuErrchk(cudaDeviceSynchronize());

      //reduce
      matches[0] = 0;
      reduce<<<numBlocks, blockSize>>>(mvec, matches);
      gpuErrchk(cudaDeviceSynchronize());
      n += matches[0] - (apen ? 0 : 1);
    }
    
    gpuErrchk(cudaFree(matches));
    gpuErrchk(cudaFree(mvec));
    
    return n;
}

int main(int argc, char **argv)
{
  params p = {
    0.2f,
    2,
    "data.dat",
    "out.dat",
    false
  };
  
  parse_arguments(argc, argv, &p);
  dump_params(&p);
  
  // data
  int N = countlines(p.infile);
  if (N <= p.m + 1){
      printf("m (%d) > length of data (%d)\nExiting...", p.m, N);
      return N;
  }

  // parrallelism
  int blockSize = BLOCKSIZE; //4 ;//256;
  int numBlocks = (N + blockSize - 1) / blockSize;

  // Allocate Unified Memory – accessible from CPU or GPU
  float *x;
  gpuErrchk(cudaMallocManaged(&x, N * sizeof(float)));

  // initialize data
  load_data(p.infile, x);
  float sd = sandard_deviation(x, N);

  // Sampen algorithm initialisation
  int m = p.m;
  gpuErrchk(cudaMemcpyToSymbol(d_m, &m, sizeof(int), 0, cudaMemcpyHostToDevice));
  float r = p.r * sd;
  gpuErrchk(cudaMemcpyToSymbol(d_r, &r, sizeof(float), 0, cudaMemcpyHostToDevice));

  bool apen = p.apen;
  unsigned long n_m = find_similar_vectors(x, N, m, numBlocks, blockSize, apen);
  unsigned long n_m_plus_1 = find_similar_vectors(x, N, m + 1, numBlocks, blockSize, apen);
       
  FILE * outFile;
  outFile = fopen(p.outfile, "w");
    fprintf(outFile, "m vector matches: %lu\n", n_m);
    fprintf(outFile, "(m+1) vector matches: %lu\n", n_m_plus_1);
    fprintf(outFile, "ratio = n_{m+1}/n_m: %f\n", (float)n_m_plus_1/n_m);
    fprintf(outFile, "SampEn = -ln(ratio): %f\n", -log((float)n_m_plus_1/n_m));
  fclose(outFile);

  // Free memory
  gpuErrchk(cudaFree(x));
  
  return 0;
}

	.file	"tmpxft_0035d563_00000000-6_cs.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2039:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2039:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata._Z9gpuAssert9cudaErrorPKcib.str1.1,"aMS",@progbits,1
.LC1:
	.string	"GPUassert: %s %s %d\n"
	.section	.text._Z9gpuAssert9cudaErrorPKcib,"axG",@progbits,_Z9gpuAssert9cudaErrorPKcib,comdat
	.weak	_Z9gpuAssert9cudaErrorPKcib
	.type	_Z9gpuAssert9cudaErrorPKcib, @function
_Z9gpuAssert9cudaErrorPKcib:
.LFB2027:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L8
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movl	%edx, 12(%rsp)
	movq	%rsi, (%rsp)
	call	cudaGetErrorString@PLT
	movl	12(%rsp), %r9d
	movq	(%rsp), %r8
	leaq	.LC1(%rip), %rdx
	movq	stderr(%rip), %rdi
	movq	%rax, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	testb	%bpl, %bpl
	je	.L2
	movl	%ebx, %edi
	call	exit@PLT
.L2:
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L8:
	.cfi_restore 3
	.cfi_restore 6
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z9gpuAssert9cudaErrorPKcib, .-_Z9gpuAssert9cudaErrorPKcib
	.text
	.globl	_Z8is_equalfff
	.type	_Z8is_equalfff, @function
_Z8is_equalfff:
.LFB2028:
	.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
.LFE2028:
	.size	_Z8is_equalfff, .-_Z8is_equalfff
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"r"
.LC3:
	.string	"%f"
	.text
	.globl	_Z9load_dataPcPf
	.type	_Z9load_dataPcPf, @function
_Z9load_dataPcPf:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC3(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rsi, %r12
	leaq	.LC2(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	movq	%rax, %rbp
.L15:
	xorl	%eax, %eax
	leaq	4(%rsp), %rdx
	movq	%r13, %rsi
	movq	%rbp, %rdi
	call	__isoc23_fscanf@PLT
	testl	%eax, %eax
	jle	.L19
	movss	4(%rsp), %xmm0
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	jmp	.L15
.L19:
	movq	%rbp, %rdi
	call	fclose@PLT
	leal	-1(%rbx), %eax
	movq	8(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	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
.LFE2029:
	.size	_Z9load_dataPcPf, .-_Z9load_dataPcPf
	.section	.rodata.str1.1
.LC4:
	.string	"last: %i\n"
	.text
	.globl	_Z10countlinesPc
	.type	_Z10countlinesPc, @function
_Z10countlinesPc:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC2(%rip), %rsi
	orl	$-1, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	pushq	%rcx
	.cfi_def_cfa_offset 32
	call	fopen@PLT
	testq	%rax, %rax
	je	.L20
	movq	%rax, %rbx
	xorl	%ebp, %ebp
.L22:
	movq	%rbx, %rdi
	call	fgetc@PLT
	cmpb	$-1, %al
	je	.L28
	cmpb	$10, %al
	jne	.L22
	incl	%ebp
	jmp	.L22
.L28:
	movl	$2, %edi
	orl	$-1, %edx
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
.L20:
	movl	%ebp, %eax
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z10countlinesPc, .-_Z10countlinesPc
	.section	.rodata.str1.1
.LC5:
	.string	"#\n"
.LC6:
	.string	"#m:%d\n"
.LC7:
	.string	"#r:%f\n"
.LC8:
	.string	"#infile:%s\n"
.LC9:
	.string	"#outfile:%s\n"
.LC10:
	.string	"#approx:%d\n"
	.text
	.globl	_Z11dump_paramsP6params
	.type	_Z11dump_paramsP6params, @function
_Z11dump_paramsP6params:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	movq	stdout(%rip), %rdi
	movl	$2, %esi
	leaq	.LC5(%rip), %rdx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	4(%rbx), %ecx
	movl	$2, %esi
	xorl	%eax, %eax
	movq	stdout(%rip), %rdi
	leaq	.LC6(%rip), %rdx
	call	__fprintf_chk@PLT
	movl	$2, %esi
	movq	stdout(%rip), %rdi
	movb	$1, %al
	leaq	.LC7(%rip), %rdx
	cvtss2sd	(%rbx), %xmm0
	call	__fprintf_chk@PLT
	leaq	8(%rbx), %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	movq	stdout(%rip), %rdi
	leaq	.LC8(%rip), %rdx
	call	__fprintf_chk@PLT
	movq	stdout(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	674(%rbx), %rcx
	leaq	.LC9(%rip), %rdx
	call	__fprintf_chk@PLT
	movzbl	1340(%rbx), %ecx
	movl	$2, %esi
	xorl	%eax, %eax
	movq	stdout(%rip), %rdi
	leaq	.LC10(%rip), %rdx
	call	__fprintf_chk@PLT
	movq	stdout(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	fflush@PLT
	.cfi_endproc
.LFE2031:
	.size	_Z11dump_paramsP6params, .-_Z11dump_paramsP6params
	.section	.rodata.str1.1
.LC11:
	.string	"Usage: %s <params> \n\n"
.LC12:
	.string	"Model params:\n"
.LC13:
	.string	"   -m, --embed=INT        set the embedding dimension 'dim' to INT\n"
.LC14:
	.string	"   -r, --radius=FLOAT     set the maximal distance between vectors\n"
.LC15:
	.string	"                          to 'radius' to FLOAT\n"
.LC16:
	.string	"   -i, --in=FILE_NAME     set the input data to FILE_NAME\n"
.LC17:
	.string	"   -o, --out=FILE_NAME    set the output data to FILE_NAME\n"
.LC18:
	.string	"   -a, --apen=INT         calculates Approximate Entropy (1) instead of SampEn (def, 0)\n"
.LC19:
	.string	"\n"
	.text
	.globl	_Z5usagePPc
	.type	_Z5usagePPc, @function
_Z5usagePPc:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	(%rdi), %rdx
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC17(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC18(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC19(%rip), %rsi
	xorl	%eax, %eax
	popq	%rdx
	.cfi_def_cfa_offset 8
	movl	$2, %edi
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2032:
	.size	_Z5usagePPc, .-_Z5usagePPc
	.section	.rodata.str1.1
.LC20:
	.string	"%d"
.LC21:
	.string	"%i"
.LC22:
	.string	"mrioa:"
	.text
	.globl	_Z15parse_argumentsiPPcP6params
	.type	_Z15parse_argumentsiPPcP6params, @function
_Z15parse_argumentsiPPcP6params:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	_ZL7options(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%edi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdx, %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
.L45:
	xorl	%r8d, %r8d
	movq	%r13, %rcx
	leaq	.LC22(%rip), %rdx
	movq	%r12, %rsi
	movl	%ebp, %edi
	call	getopt_long@PLT
	cmpl	$-1, %eax
	je	.L49
	cmpl	$109, %eax
	je	.L35
	jg	.L36
	cmpl	$97, %eax
	je	.L37
	leaq	8(%rbx), %rdi
	cmpl	$105, %eax
	je	.L47
	jmp	.L45
.L36:
	cmpl	$111, %eax
	je	.L40
	movq	%rbx, %rdx
	leaq	.LC3(%rip), %rsi
	cmpl	$114, %eax
	je	.L48
	jmp	.L45
.L35:
	leaq	4(%rbx), %rdx
	leaq	.LC20(%rip), %rsi
.L48:
	movq	optarg(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc23_sscanf@PLT
	jmp	.L45
.L40:
	leaq	674(%rbx), %rdi
.L47:
	movq	optarg(%rip), %rsi
	movl	$666, %edx
	call	__strcpy_chk@PLT
	jmp	.L45
.L37:
	movq	optarg(%rip), %rdi
	xorl	%eax, %eax
	leaq	4(%rsp), %rdx
	leaq	.LC21(%rip), %rsi
	call	__isoc23_sscanf@PLT
	cmpl	$0, 4(%rsp)
	setne	1340(%rbx)
	jmp	.L45
.L49:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L44
	call	__stack_chk_fail@PLT
.L44:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	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
.LFE2033:
	.size	_Z15parse_argumentsiPPcP6params, .-_Z15parse_argumentsiPPcP6params
	.globl	_Z17sandard_deviationPfi
	.type	_Z17sandard_deviationPfi, @function
_Z17sandard_deviationPfi:
.LFB2034:
	.cfi_startproc
	endbr64
	xorps	%xmm1, %xmm1
	xorl	%eax, %eax
	movaps	%xmm1, %xmm0
.L51:
	cmpl	%eax, %esi
	jle	.L53
	movss	(%rdi,%rax,4), %xmm2
	incq	%rax
	addss	%xmm2, %xmm1
	mulss	%xmm2, %xmm2
	addss	%xmm2, %xmm0
	jmp	.L51
.L53:
	cvtsi2ssl	%esi, %xmm2
	divss	%xmm2, %xmm1
	divss	%xmm2, %xmm0
	mulss	%xmm1, %xmm1
	subss	%xmm1, %xmm0
	jmp	sqrtf@PLT
	.cfi_endproc
.LFE2034:
	.size	_Z17sandard_deviationPfi, .-_Z17sandard_deviationPfi
	.globl	_Z27__device_stub__Z6reducePiPjPiPj
	.type	_Z27__device_stub__Z6reducePiPjPiPj, @function
_Z27__device_stub__Z6reducePiPjPiPj:
.LFB2061:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L54
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z6reducePiPj(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L54:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L56
	call	__stack_chk_fail@PLT
.L56:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2061:
	.size	_Z27__device_stub__Z6reducePiPjPiPj, .-_Z27__device_stub__Z6reducePiPjPiPj
	.globl	_Z6reducePiPj
	.type	_Z6reducePiPj, @function
_Z6reducePiPj:
.LFB2062:
	.cfi_startproc
	endbr64
	jmp	_Z27__device_stub__Z6reducePiPjPiPj
	.cfi_endproc
.LFE2062:
	.size	_Z6reducePiPj, .-_Z6reducePiPj
	.globl	_Z31__device_stub__Z7findvecPfiS_PiPfiS_Pi
	.type	_Z31__device_stub__Z7findvecPfiS_PiPfiS_Pi, @function
_Z31__device_stub__Z7findvecPfiS_PiPfiS_Pi:
.LFB2063:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movl	%esi, 20(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movq	%rcx, (%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L59
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z7findvecPfiS_Pi(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L59:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L61
	call	__stack_chk_fail@PLT
.L61:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2063:
	.size	_Z31__device_stub__Z7findvecPfiS_PiPfiS_Pi, .-_Z31__device_stub__Z7findvecPfiS_PiPfiS_Pi
	.globl	_Z7findvecPfiS_Pi
	.type	_Z7findvecPfiS_Pi, @function
_Z7findvecPfiS_Pi:
.LFB2064:
	.cfi_startproc
	endbr64
	jmp	_Z31__device_stub__Z7findvecPfiS_PiPfiS_Pi
	.cfi_endproc
.LFE2064:
	.size	_Z7findvecPfiS_Pi, .-_Z7findvecPfiS_Pi
	.section	.rodata.str1.1
.LC24:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/lukaszmachura/cusampen/master/cs.cu"
	.text
	.globl	_Z20find_similar_vectorsPfiiiib
	.type	_Z20find_similar_vectorsPfiiiib, @function
_Z20find_similar_vectorsPfiiiib:
.LFB2035:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movabsq	$4294967297, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%r8d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%ecx, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdi, %r12
	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
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movb	%r9b, 15(%rsp)
	leaq	24(%rsp), %rdi
	movl	%esi, 8(%rsp)
	movslq	%edx, %rsi
	movl	$1, %edx
	movq	%rsi, %rbx
	salq	$2, %rsi
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	call	cudaMallocManaged@PLT
	movl	$1, %ecx
	movl	$193, %edx
	leaq	.LC24(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	leaq	32(%rsp), %rdi
	movl	$1, %edx
	movl	$4, %esi
	call	cudaMallocManaged@PLT
	movl	$1, %ecx
	movl	$197, %edx
	leaq	.LC24(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movslq	8(%rsp), %rsi
	leaq	40(%rsp), %rdi
	movl	$1, %edx
	salq	$2, %rsi
	call	cudaMallocManaged@PLT
	movl	$1, %ecx
	movl	$201, %edx
	leaq	.LC24(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	xorl	%esi, %esi
	movq	%rsi, (%rsp)
.L65:
	movl	8(%rsp), %eax
	movl	%ebp, %edx
	subl	%ebx, %eax
	cmpl	%ebp, %eax
	jl	.L71
	movq	24(%rsp), %rcx
	movq	%rbp, %rax
	addl	%ebx, %edx
.L72:
	cmpl	%eax, %edx
	jle	.L75
	movss	(%r12,%rax,4), %xmm0
	addq	$4, %rcx
	incq	%rax
	movss	%xmm0, -4(%rcx)
	jmp	.L72
.L75:
	movq	40(%rsp), %rdx
	xorl	%eax, %eax
.L67:
	cmpl	%eax, 8(%rsp)
	jle	.L76
	xorl	%ecx, %ecx
	movl	%ecx, (%rdx,%rax,4)
	incq	%rax
	jmp	.L67
.L76:
	movq	%r15, 64(%rsp)
	movl	68(%rsp), %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r15, 52(%rsp)
	movl	56(%rsp), %esi
	movl	%r14d, 60(%rsp)
	movq	60(%rsp), %rdx
	movl	%r13d, 48(%rsp)
	movq	48(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L69
	movq	40(%rsp), %rcx
	movq	24(%rsp), %rdi
	movq	%r12, %rdx
	movl	%ebx, %esi
	call	_Z31__device_stub__Z7findvecPfiS_PiPfiS_Pi
.L69:
	call	cudaDeviceSynchronize@PLT
	movl	$1, %ecx
	movl	$215, %edx
	leaq	.LC24(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	32(%rsp), %rax
	xorl	%edx, %edx
	xorl	%r9d, %r9d
	movq	%r15, 64(%rsp)
	movl	68(%rsp), %ecx
	xorl	%r8d, %r8d
	movl	%edx, (%rax)
	movq	%r15, 52(%rsp)
	movl	56(%rsp), %esi
	movl	%r14d, 60(%rsp)
	movq	60(%rsp), %rdx
	movl	%r13d, 48(%rsp)
	movq	48(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L70
	movq	32(%rsp), %rsi
	movq	40(%rsp), %rdi
	call	_Z27__device_stub__Z6reducePiPjPiPj
.L70:
	call	cudaDeviceSynchronize@PLT
	movl	$220, %edx
	movl	$1, %ecx
	incq	%rbp
	movl	%eax, %edi
	leaq	.LC24(%rip), %rsi
	call	_Z9gpuAssert9cudaErrorPKcib
	movb	15(%rsp), %dl
	movq	32(%rsp), %rax
	xorl	$1, %edx
	movl	(%rax), %eax
	movzbl	%dl, %edx
	subl	%edx, %eax
	addq	%rax, (%rsp)
	jmp	.L65
.L71:
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movl	$1, %ecx
	movl	$224, %edx
	leaq	.LC24(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movl	$1, %ecx
	movl	$225, %edx
	leaq	.LC24(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movl	(%rsp), %eax
	movq	72(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L73
	call	__stack_chk_fail@PLT
.L73:
	addq	$88, %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
.LFE2035:
	.size	_Z20find_similar_vectorsPfiiiib, .-_Z20find_similar_vectorsPfiiiib
	.section	.rodata.str1.1
.LC25:
	.string	"m (%d) > length of data (%d)\nExiting..."
.LC26:
	.string	"w"
.LC27:
	.string	"m vector matches: %lu\n"
.LC28:
	.string	"(m+1) vector matches: %lu\n"
.LC29:
	.string	"ratio = n_{m+1}/n_m: %f\n"
.LC31:
	.string	"SampEn = -ln(ratio): %f\n"
	.section	.rodata
	.align 32
.LC0:
	.long	1045220557
	.long	2
	.string	"data.dat"
	.zero	657
	.string	"out.dat"
	.zero	658
	.byte	0
	.zero	3
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2036:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	%edi, %eax
	movq	%rsi, %r8
	movl	$336, %ecx
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	leaq	.LC0(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$1400, %rsp
	.cfi_def_cfa_offset 1440
	movq	%fs:40, %rdx
	movq	%rdx, 1384(%rsp)
	xorl	%edx, %edx
	leaq	40(%rsp), %rbx
	leaq	40(%rsp), %rdi
	rep movsl
	movq	%rbx, %rdx
	movl	%eax, %edi
	movq	%r8, %rsi
	call	_Z15parse_argumentsiPPcP6params
	leaq	48(%rsp), %rbp
	movq	%rbx, %rdi
	call	_Z11dump_paramsP6params
	movq	%rbp, %rdi
	call	_Z10countlinesPc
	movl	44(%rsp), %edx
	movl	%eax, %ebx
	leal	1(%rdx), %eax
	cmpl	%ebx, %eax
	jl	.L78
	movl	%ebx, %ecx
	leaq	.LC25(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L77
.L78:
	leal	255(%rbx), %eax
	movl	$256, %ecx
	movslq	%ebx, %rsi
	cltd
	salq	$2, %rsi
	leaq	32(%rsp), %rdi
	leaq	.LC24(%rip), %r12
	idivl	%ecx
	movl	$1, %edx
	movl	%eax, %r13d
	call	cudaMallocManaged@PLT
	movl	$1, %ecx
	movl	$256, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	32(%rsp), %rsi
	movq	%rbp, %rdi
	call	_Z9load_dataPcPf
	movq	32(%rsp), %rdi
	movl	%ebx, %esi
	call	_Z17sandard_deviationPfi
	movl	44(%rsp), %eax
	xorl	%ecx, %ecx
	leaq	24(%rsp), %rsi
	movl	$1, %r8d
	movl	$4, %edx
	leaq	_ZL3d_m(%rip), %rdi
	movss	%xmm0, 12(%rsp)
	movl	%eax, 24(%rsp)
	call	cudaMemcpyToSymbol@PLT
	movl	$1, %ecx
	movl	$264, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movss	12(%rsp), %xmm0
	mulss	40(%rsp), %xmm0
	movl	$1, %r8d
	xorl	%ecx, %ecx
	leaq	28(%rsp), %rsi
	movl	$4, %edx
	leaq	_ZL3d_r(%rip), %rdi
	movss	%xmm0, 28(%rsp)
	call	cudaMemcpyToSymbol@PLT
	movl	$1, %ecx
	movl	$266, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movl	24(%rsp), %edx
	movq	32(%rsp), %rdi
	movl	%ebx, %esi
	movzbl	1380(%rsp), %r9d
	movl	%r13d, %ecx
	movl	$256, %r8d
	movl	%r9d, 12(%rsp)
	call	_Z20find_similar_vectorsPfiiiib
	movl	12(%rsp), %r9d
	movl	%r13d, %ecx
	movl	%ebx, %esi
	movslq	%eax, %rbp
	movl	24(%rsp), %eax
	movq	32(%rsp), %rdi
	movl	$256, %r8d
	leal	1(%rax), %edx
	call	_Z20find_similar_vectorsPfiiiib
	leaq	714(%rsp), %rdi
	leaq	.LC26(%rip), %rsi
	movslq	%eax, %rbx
	call	fopen@PLT
	movq	%rbp, %rcx
	movl	$2, %esi
	leaq	.LC27(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %r13
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	xorl	%eax, %eax
	movq	%rbx, %rcx
	movl	$2, %esi
	leaq	.LC28(%rip), %rdx
	movq	%r13, %rdi
	call	__fprintf_chk@PLT
	testq	%rbx, %rbx
	js	.L80
	cvtsi2ssq	%rbx, %xmm0
	jmp	.L81
.L80:
	movq	%rbx, %rax
	andl	$1, %ebx
	shrq	%rax
	orq	%rbx, %rax
	cvtsi2ssq	%rax, %xmm0
	addss	%xmm0, %xmm0
.L81:
	testq	%rbp, %rbp
	js	.L82
	cvtsi2ssq	%rbp, %xmm1
	jmp	.L83
.L82:
	movq	%rbp, %rax
	andl	$1, %ebp
	shrq	%rax
	orq	%rbp, %rax
	cvtsi2ssq	%rax, %xmm1
	addss	%xmm1, %xmm1
.L83:
	divss	%xmm1, %xmm0
	leaq	.LC29(%rip), %rdx
	movq	%r13, %rdi
	movb	$1, %al
	movl	$2, %esi
	movd	%xmm0, %ebx
	cvtss2sd	%xmm0, %xmm0
	call	__fprintf_chk@PLT
	movd	%ebx, %xmm0
	xorl	%ebx, %ebx
	call	logf@PLT
	movl	$2, %esi
	movq	%r13, %rdi
	movb	$1, %al
	xorps	.LC30(%rip), %xmm0
	leaq	.LC31(%rip), %rdx
	cvtss2sd	%xmm0, %xmm0
	call	__fprintf_chk@PLT
	movq	%r13, %rdi
	call	fclose@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movl	$1, %ecx
	movl	$281, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
.L77:
	movq	1384(%rsp), %rax
	subq	%fs:40, %rax
	je	.L84
	call	__stack_chk_fail@PLT
.L84:
	addq	$1400, %rsp
	.cfi_def_cfa_offset 40
	movl	%ebx, %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
.LFE2036:
	.size	main, .-main
	.section	.rodata.str1.1
.LC33:
	.string	"_Z7findvecPfiS_Pi"
.LC34:
	.string	"_Z6reducePiPj"
.LC35:
	.string	"d_m"
.LC36:
	.string	"d_r"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2066:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -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	.LC33(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z7findvecPfiS_Pi(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC34(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z6reducePiPj(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC35(%rip), %rdx
	movl	$4, %r9d
	leaq	_ZL3d_m(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC36(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$4, %r9d
	leaq	_ZL3d_r(%rip), %rsi
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2066:
	.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.str1.1
.LC37:
	.string	"in"
.LC38:
	.string	"out"
.LC39:
	.string	"embed"
.LC40:
	.string	"radius"
.LC41:
	.string	"apen"
	.section	.data.rel.local,"aw"
	.align 32
	.type	_ZL7options, @object
	.size	_ZL7options, 160
_ZL7options:
	.quad	.LC37
	.long	1
	.zero	4
	.quad	0
	.long	105
	.zero	4
	.quad	.LC38
	.long	1
	.zero	4
	.quad	0
	.long	111
	.zero	4
	.quad	.LC39
	.long	1
	.zero	4
	.quad	0
	.long	109
	.zero	4
	.quad	.LC40
	.long	1
	.zero	4
	.quad	0
	.long	114
	.zero	4
	.quad	.LC41
	.long	1
	.zero	4
	.quad	0
	.long	97
	.zero	4
	.local	_ZL3d_r
	.comm	_ZL3d_r,4,4
	.local	_ZL3d_m
	.comm	_ZL3d_m,4,4
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC30:
	.long	-2147483648
	.long	0
	.long	0
	.long	0
	.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 <math.h>
#include <stdio.h>
#include <getopt.h>

#define FILE_SIZE 666
#define BLOCKSIZE 256
#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }

inline void gpuAssert(hipError_t code, const char *file, int line, bool abort=true)
{
  if (code != hipSuccess){
    fprintf(stderr, "GPUassert: %s %s %d\n", hipGetErrorString(code), file, line);
    if (abort) exit(code);
  }
}


__device__ int d_m;
__device__ float d_r;

// Kernel functions
__global__ 
void reduce(int *g_idata, unsigned int *g_out) {
  __shared__ int sdata[BLOCKSIZE];
  // each thread loads one element from global to shared mem
  int i = blockIdx.x*blockDim.x + threadIdx.x;

  sdata[threadIdx.x] = g_idata[i];

  __syncthreads();
  // do reduction in shared mem
  for (int s=1; s < blockDim.x; s *=2)
  {
    int index = 2 * s * threadIdx.x;
    if (index < blockDim.x)
    {
      sdata[index] += sdata[index + s];
    }
    __syncthreads();
  }

  // write result for this block to global mem
  if (threadIdx.x == 0){
      atomicAdd(g_out, sdata[0]);
  }
}

__device__
bool is_equal(float a, float b, float eps)
{
  return fabs(a - b) <= eps ? true : false;
}

__global__
void findvec(float *base_vec, int m, float *in, int *mvec)
{
  int index = blockIdx.x * blockDim.x + threadIdx.x;
  int i;
  
  // check if vec of size m is similar
  int found = true;
  for (i = 0; i < m; i++){
    if (!is_equal(in[index + i], base_vec[i], d_r)){
      found = false;
      break;
    }
  }
  if (found) {
      mvec[index] = 1;
  }
}

int load_data(char *fname, float *x)
{
  FILE *f = fopen(fname, "r");
  float buf;
  int i = 0;
  while(fscanf(f, "%f", &buf) > 0)
    x[i++] = buf;
  fclose(f);
  return i - 1;
}

int countlines(char *fname)
{
    FILE *f = fopen(fname, "r");
    if (f == NULL)
        return -1;

    char z, buf;
    int linenumbers = 0;
    while((z = fgetc(f)) != EOF)
        if (z == '\n')
            linenumbers++;
        buf = z;
    
    printf("last: %i\n", buf);
    fclose(f);
    return linenumbers;
}

// parameters
typedef struct {
  float r;                  // max distance
  int m;                    // embed dim
  char infile[FILE_SIZE];   //
  char outfile[FILE_SIZE];  //
  bool apen;                 // 1: approximate not sample entropy
} params;

static struct option options[] = {
    {"in", required_argument, NULL, 'i'},
    {"out", required_argument, NULL, 'o'},
    {"embed", required_argument, NULL, 'm'},
    {"radius", required_argument, NULL, 'r'},
    {"apen", required_argument, NULL, 'a'},
};

void dump_params(params * p)
{
  fprintf(stdout,"#\n");
  fprintf(stdout,"#m:%d\n",p->m);
  fprintf(stdout,"#r:%f\n",p->r);
  fprintf(stdout,"#infile:%s\n",p->infile);
  fprintf(stdout,"#outfile:%s\n",p->outfile);
  fprintf(stdout,"#approx:%d\n",p->apen);
  fflush(stdout);
}

void usage(char **argv)
{
    printf("Usage: %s <params> \n\n", argv[0]);
    printf("Model params:\n");
    printf("   -m, --embed=INT        set the embedding dimension 'dim' to INT\n");
    printf("   -r, --radius=FLOAT     set the maximal distance between vectors\n");
    printf("                          to 'radius' to FLOAT\n");
    printf("   -i, --in=FILE_NAME     set the input data to FILE_NAME\n");
    printf("   -o, --out=FILE_NAME    set the output data to FILE_NAME\n");
    printf("   -a, --apen=INT         calculates Approximate Entropy (1) instead of SampEn (def, 0)\n");
    printf("\n");
}

void parse_arguments(int argc, char **argv, params *p)
{
  int c;

  while( (c = getopt_long(argc, argv, "mrioa:", options, NULL)) != EOF) {
    switch (c) {
      case 'm':
        sscanf(optarg, "%d", &(p->m));
        break;
      case 'r':
        sscanf(optarg, "%f", &(p->r));
        break;
      case 'i':
        strcpy(p->infile, optarg);
        break;
      case 'o':
        strcpy(p->outfile, optarg);
        break;
      case 'a':
        int buf;
        sscanf(optarg, "%i", &buf);
        p->apen = buf;
        break;
    }
  }
}

float sandard_deviation(float *x, int N)
{
  int i;
  float sd = 0, mean = 0;
  
  for (i = 0; i < N; ++i){
    mean += x[i];
    sd += x[i] * x[i];
  }
  
  mean /= N;
  sd = sd / N - mean * mean;
  
  return sqrt(sd);
}

int
find_similar_vectors(float *x, int N, int m, int numBlocks, int blockSize, bool apen=false)
{
    int i; //dummy idx
    
    // space in shared mem for base vec m
    float *base_vec;
    gpuErrchk(hipMallocManaged(&base_vec, m * sizeof(float)));
    
    // space in shared mem for reduction
    unsigned int *matches;
    gpuErrchk(hipMallocManaged(&matches, sizeof(unsigned int)));
    
    // space in shared mem for identical vectors
    int *mvec;
    gpuErrchk(hipMallocManaged(&mvec, N * sizeof(int)));

    // search for EACH possible base vec of length m + 1
    unsigned long n = 0;
    for (int ibv = 0; ibv <= N - m; ibv++){
      // build temporary base vec of length m
      for (i = ibv; i < ibv + m; ++i) base_vec[i - ibv] = x[i];

      // matches per node
      for (i = 0; i < N; ++i) mvec[i] = 0;  

      // Run kernel on the GPU
      // find matches for temporary vec
      findvec<<<numBlocks, blockSize>>>(base_vec, m, x, mvec);
      gpuErrchk(hipDeviceSynchronize());

      //reduce
      matches[0] = 0;
      reduce<<<numBlocks, blockSize>>>(mvec, matches);
      gpuErrchk(hipDeviceSynchronize());
      n += matches[0] - (apen ? 0 : 1);
    }
    
    gpuErrchk(hipFree(matches));
    gpuErrchk(hipFree(mvec));
    
    return n;
}

int main(int argc, char **argv)
{
  params p = {
    0.2f,
    2,
    "data.dat",
    "out.dat",
    false
  };
  
  parse_arguments(argc, argv, &p);
  dump_params(&p);
  
  // data
  int N = countlines(p.infile);
  if (N <= p.m + 1){
      printf("m (%d) > length of data (%d)\nExiting...", p.m, N);
      return N;
  }

  // parrallelism
  int blockSize = BLOCKSIZE; //4 ;//256;
  int numBlocks = (N + blockSize - 1) / blockSize;

  // Allocate Unified Memory – accessible from CPU or GPU
  float *x;
  gpuErrchk(hipMallocManaged(&x, N * sizeof(float)));

  // initialize data
  load_data(p.infile, x);
  float sd = sandard_deviation(x, N);

  // Sampen algorithm initialisation
  int m = p.m;
  gpuErrchk(hipMemcpyToSymbol(HIP_SYMBOL(d_m), &m, sizeof(int), 0, hipMemcpyHostToDevice));
  float r = p.r * sd;
  gpuErrchk(hipMemcpyToSymbol(HIP_SYMBOL(d_r), &r, sizeof(float), 0, hipMemcpyHostToDevice));

  bool apen = p.apen;
  unsigned long n_m = find_similar_vectors(x, N, m, numBlocks, blockSize, apen);
  unsigned long n_m_plus_1 = find_similar_vectors(x, N, m + 1, numBlocks, blockSize, apen);
       
  FILE * outFile;
  outFile = fopen(p.outfile, "w");
    fprintf(outFile, "m vector matches: %lu\n", n_m);
    fprintf(outFile, "(m+1) vector matches: %lu\n", n_m_plus_1);
    fprintf(outFile, "ratio = n_{m+1}/n_m: %f\n", (float)n_m_plus_1/n_m);
    fprintf(outFile, "SampEn = -ln(ratio): %f\n", -log((float)n_m_plus_1/n_m));
  fclose(outFile);

  // Free memory
  gpuErrchk(hipFree(x));
  
  return 0;
}

	.text
	.file	"cs.hip"
	.globl	_Z21__device_stub__reducePiPj   # -- Begin function _Z21__device_stub__reducePiPj
	.type	_Z21__device_stub__reducePiPj,@function
_Z21__device_stub__reducePiPj:          # @_Z21__device_stub__reducePiPj
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z6reducePiPj, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z21__device_stub__reducePiPj, .Lfunc_end0-_Z21__device_stub__reducePiPj
	.cfi_endproc
                                        # -- End function
	.globl	_Z22__device_stub__findvecPfiS_Pi # -- Begin function _Z22__device_stub__findvecPfiS_Pi
	.type	_Z22__device_stub__findvecPfiS_Pi,@function
_Z22__device_stub__findvecPfiS_Pi:      # @_Z22__device_stub__findvecPfiS_Pi
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	4(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	32(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	24(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z7findvecPfiS_Pi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z22__device_stub__findvecPfiS_Pi, .Lfunc_end1-_Z22__device_stub__findvecPfiS_Pi
	.cfi_endproc
                                        # -- End function
	.globl	_Z9load_dataPcPf                # -- Begin function _Z9load_dataPcPf
	.type	_Z9load_dataPcPf,@function
_Z9load_dataPcPf:                       # @_Z9load_dataPcPf
	.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	$.L.str, %esi
	callq	fopen
	movq	%rax, %r14
	leaq	4(%rsp), %rdx
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	$-1, %ebp
	testl	%eax, %eax
	jle	.LBB2_3
# %bb.1:                                # %.lr.ph.preheader
	leaq	4(%rsp), %r15
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movss	4(%rsp), %xmm0                  # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%rbx)
	movl	$.L.str.1, %esi
	movq	%r14, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	incl	%ebp
	addq	$4, %rbx
	testl	%eax, %eax
	jg	.LBB2_2
.LBB2_3:                                # %._crit_edge
	movq	%r14, %rdi
	callq	fclose
	movl	%ebp, %eax
	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	_Z9load_dataPcPf, .Lfunc_end2-_Z9load_dataPcPf
	.cfi_endproc
                                        # -- End function
	.globl	_Z10countlinesPc                # -- Begin function _Z10countlinesPc
	.type	_Z10countlinesPc,@function
_Z10countlinesPc:                       # @_Z10countlinesPc
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	$.L.str, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB3_1
# %bb.2:                                # %.preheader.outer.preheader
	movq	%rax, %r14
	xorl	%ebx, %ebx
.LBB3_3:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	callq	fgetc
	cmpb	$-1, %al
	je	.LBB3_6
# %bb.4:                                # %.preheader
                                        #   in Loop: Header=BB3_3 Depth=1
	movzbl	%al, %eax
	cmpl	$10, %eax
	jne	.LBB3_3
# %bb.5:                                #   in Loop: Header=BB3_3 Depth=1
	incl	%ebx
	jmp	.LBB3_3
.LBB3_6:
	movl	$.L.str.2, %edi
	movl	$-1, %esi
	xorl	%eax, %eax
	callq	printf
	movq	%r14, %rdi
	callq	fclose
	jmp	.LBB3_7
.LBB3_1:
	movl	$-1, %ebx
.LBB3_7:
	movl	%ebx, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z10countlinesPc, .Lfunc_end3-_Z10countlinesPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z11dump_paramsP6params         # -- Begin function _Z11dump_paramsP6params
	.type	_Z11dump_paramsP6params,@function
_Z11dump_paramsP6params:                # @_Z11dump_paramsP6params
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	movq	stdout(%rip), %rcx
	movl	$.L.str.3, %edi
	movl	$2, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movq	stdout(%rip), %rdi
	movl	4(%rbx), %edx
	movl	$.L.str.4, %esi
	xorl	%eax, %eax
	callq	fprintf
	movq	stdout(%rip), %rdi
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.5, %esi
	movb	$1, %al
	callq	fprintf
	movq	stdout(%rip), %rdi
	leaq	8(%rbx), %rdx
	movl	$.L.str.6, %esi
	xorl	%eax, %eax
	callq	fprintf
	movq	stdout(%rip), %rdi
	leaq	674(%rbx), %rdx
	movl	$.L.str.7, %esi
	xorl	%eax, %eax
	callq	fprintf
	movq	stdout(%rip), %rdi
	movzbl	1340(%rbx), %edx
	movl	$.L.str.8, %esi
	xorl	%eax, %eax
	callq	fprintf
	movq	stdout(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	fflush                          # TAILCALL
.Lfunc_end4:
	.size	_Z11dump_paramsP6params, .Lfunc_end4-_Z11dump_paramsP6params
	.cfi_endproc
                                        # -- End function
	.globl	_Z5usagePPc                     # -- Begin function _Z5usagePPc
	.type	_Z5usagePPc,@function
_Z5usagePPc:                            # @_Z5usagePPc
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	(%rdi), %rsi
	movl	$.L.str.9, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	movl	$.Lstr.4, %edi
	callq	puts@PLT
	movl	$.Lstr.5, %edi
	callq	puts@PLT
	movl	$.Lstr.6, %edi
	callq	puts@PLT
	movl	$10, %edi
	popq	%rax
	.cfi_def_cfa_offset 8
	jmp	putchar@PLT                     # TAILCALL
.Lfunc_end5:
	.size	_Z5usagePPc, .Lfunc_end5-_Z5usagePPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z15parse_argumentsiPPcP6params # -- Begin function _Z15parse_argumentsiPPcP6params
	.type	_Z15parse_argumentsiPPcP6params,@function
_Z15parse_argumentsiPPcP6params:        # @_Z15parse_argumentsiPPcP6params
	.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
	movq	%rdx, %rbx
	movq	%rsi, %r14
	movl	%edi, %ebp
	leaq	674(%rdx), %r15
	leaq	8(%rdx), %r12
	leaq	4(%rdx), %r13
.LBB6_1:                                # =>This Inner Loop Header: Depth=1
	movl	$.L.str.18, %edx
	movl	$_ZL7options, %ecx
	movl	%ebp, %edi
	movq	%r14, %rsi
	xorl	%r8d, %r8d
	callq	getopt_long
                                        # kill: def $eax killed $eax def $rax
	leal	-105(%rax), %ecx
	cmpl	$9, %ecx
	ja	.LBB6_2
# %bb.11:                               #   in Loop: Header=BB6_1 Depth=1
	jmpq	*.LJTI6_0(,%rcx,8)
.LBB6_8:                                #   in Loop: Header=BB6_1 Depth=1
	movq	optarg(%rip), %rsi
	movq	%r12, %rdi
	callq	strcpy
	jmp	.LBB6_1
.LBB6_2:                                #   in Loop: Header=BB6_1 Depth=1
	cmpl	$97, %eax
	je	.LBB6_10
# %bb.3:                                #   in Loop: Header=BB6_1 Depth=1
	cmpl	$-1, %eax
	jne	.LBB6_1
	jmp	.LBB6_4
.LBB6_9:                                #   in Loop: Header=BB6_1 Depth=1
	movq	optarg(%rip), %rsi
	movq	%r15, %rdi
	callq	strcpy
	jmp	.LBB6_1
.LBB6_7:                                #   in Loop: Header=BB6_1 Depth=1
	movq	optarg(%rip), %rdi
	movl	$.L.str.1, %esi
	movq	%rbx, %rdx
	jmp	.LBB6_6
.LBB6_5:                                #   in Loop: Header=BB6_1 Depth=1
	movq	optarg(%rip), %rdi
	movl	$.L.str.19, %esi
	movq	%r13, %rdx
.LBB6_6:                                #   in Loop: Header=BB6_1 Depth=1
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	jmp	.LBB6_1
.LBB6_10:                               #   in Loop: Header=BB6_1 Depth=1
	movq	optarg(%rip), %rdi
	movl	$.L.str.20, %esi
	leaq	4(%rsp), %rdx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	cmpl	$0, 4(%rsp)
	setne	1340(%rbx)
	jmp	.LBB6_1
.LBB6_4:
	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
	retq
.Lfunc_end6:
	.size	_Z15parse_argumentsiPPcP6params, .Lfunc_end6-_Z15parse_argumentsiPPcP6params
	.cfi_endproc
	.section	.rodata,"a",@progbits
	.p2align	3, 0x0
.LJTI6_0:
	.quad	.LBB6_8
	.quad	.LBB6_1
	.quad	.LBB6_1
	.quad	.LBB6_1
	.quad	.LBB6_5
	.quad	.LBB6_1
	.quad	.LBB6_9
	.quad	.LBB6_1
	.quad	.LBB6_1
	.quad	.LBB6_7
                                        # -- End function
	.text
	.globl	_Z17sandard_deviationPfi        # -- Begin function _Z17sandard_deviationPfi
	.type	_Z17sandard_deviationPfi,@function
_Z17sandard_deviationPfi:               # @_Z17sandard_deviationPfi
	.cfi_startproc
# %bb.0:
	xorps	%xmm1, %xmm1
	xorps	%xmm0, %xmm0
	xorps	%xmm2, %xmm2
	testl	%esi, %esi
	jle	.LBB7_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%esi, %eax
	xorl	%ecx, %ecx
.LBB7_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movss	(%rdi,%rcx,4), %xmm3            # xmm3 = mem[0],zero,zero,zero
	addss	%xmm3, %xmm2
	mulss	%xmm3, %xmm3
	addss	%xmm3, %xmm0
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB7_2
.LBB7_3:                                # %._crit_edge
	xorps	%xmm3, %xmm3
	cvtsi2ss	%esi, %xmm3
	divss	%xmm3, %xmm2
	divss	%xmm3, %xmm0
	mulss	%xmm2, %xmm2
	subss	%xmm2, %xmm0
	ucomiss	%xmm1, %xmm0
	jb	sqrtf                           # TAILCALL
# %bb.4:                                # %._crit_edge.split
	sqrtss	%xmm0, %xmm0
	retq
.Lfunc_end7:
	.size	_Z17sandard_deviationPfi, .Lfunc_end7-_Z17sandard_deviationPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z20find_similar_vectorsPfiiiib # -- Begin function _Z20find_similar_vectorsPfiiiib
	.type	_Z20find_similar_vectorsPfiiiib,@function
_Z20find_similar_vectorsPfiiiib:        # @_Z20find_similar_vectorsPfiiiib
	.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
	movl	%r9d, %r14d
	movl	%r8d, %r15d
	movl	%ecx, %r12d
	movl	%esi, %ebx
	movq	%rdi, 32(%rsp)                  # 8-byte Spill
	movl	%edx, 4(%rsp)                   # 4-byte Spill
	movslq	%edx, %rax
	movq	%rax, 64(%rsp)                  # 8-byte Spill
	leaq	(,%rax,4), %rsi
	leaq	48(%rsp), %rdi
	movl	$1, %edx
	callq	hipMallocManaged
	testl	%eax, %eax
	jne	.LBB8_1
# %bb.3:                                # %_Z9gpuAssert10hipError_tPKcib.exit
	leaq	16(%rsp), %rdi
	movl	$4, %esi
	movl	$1, %edx
	callq	hipMallocManaged
	testl	%eax, %eax
	jne	.LBB8_4
# %bb.5:                                # %_Z9gpuAssert10hipError_tPKcib.exit38
	movslq	%ebx, %rsi
	shlq	$2, %rsi
	leaq	8(%rsp), %rdi
	movl	$1, %edx
	callq	hipMallocManaged
	testl	%eax, %eax
	jne	.LBB8_11
# %bb.6:                                # %_Z9gpuAssert10hipError_tPKcib.exit40.preheader
	movl	%ebx, %eax
	subl	4(%rsp), %eax                   # 4-byte Folded Reload
	jge	.LBB8_12
# %bb.7:                                # %_Z9gpuAssert10hipError_tPKcib.exit40.preheader._Z9gpuAssert10hipError_tPKcib.exit40._crit_edge_crit_edge
	xorl	%r15d, %r15d
	movq	16(%rsp), %rdi
	jmp	.LBB8_8
.LBB8_12:                               # %.preheader58.lr.ph
	movl	%r12d, %ecx
	btsq	$32, %rcx
	movq	%rcx, 40(%rsp)                  # 8-byte Spill
	movl	%r15d, %r13d
	btsq	$32, %r13
	movzbl	%r14b, %ecx
	decl	%ecx
	movl	%ecx, 24(%rsp)                  # 4-byte Spill
	movl	%ebx, 28(%rsp)                  # 4-byte Spill
	movl	%ebx, %ecx
	shlq	$2, %rcx
	movq	%rcx, 56(%rsp)                  # 8-byte Spill
	incl	%eax
	xorl	%ebp, %ebp
	movq	32(%rsp), %rbx                  # 8-byte Reload
	xorl	%r15d, %r15d
.LBB8_13:                               # %.preheader58
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB8_15 Depth 2
	movq	%rax, %r12
	cmpl	$0, 4(%rsp)                     # 4-byte Folded Reload
	jle	.LBB8_16
# %bb.14:                               # %.lr.ph
                                        #   in Loop: Header=BB8_13 Depth=1
	movq	64(%rsp), %rax                  # 8-byte Reload
	addq	%rbp, %rax
	movq	48(%rsp), %rcx
	xorl	%edx, %edx
.LBB8_15:                               #   Parent Loop BB8_13 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%rbx,%rdx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%rcx,%rdx,4)
	leaq	(%rdx,%rbp), %rsi
	incq	%rsi
	incq	%rdx
	cmpq	%rax, %rsi
	jl	.LBB8_15
.LBB8_16:                               # %.preheader
                                        #   in Loop: Header=BB8_13 Depth=1
	cmpl	$0, 28(%rsp)                    # 4-byte Folded Reload
	jle	.LBB8_18
# %bb.17:                               # %.lr.ph65
                                        #   in Loop: Header=BB8_13 Depth=1
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	movq	56(%rsp), %rdx                  # 8-byte Reload
	callq	memset@PLT
.LBB8_18:                               # %._crit_edge
                                        #   in Loop: Header=BB8_13 Depth=1
	movq	40(%rsp), %rdi                  # 8-byte Reload
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB8_20
# %bb.19:                               #   in Loop: Header=BB8_13 Depth=1
	movq	48(%rsp), %rdi
	movq	8(%rsp), %rcx
	movl	4(%rsp), %esi                   # 4-byte Reload
	movq	32(%rsp), %rdx                  # 8-byte Reload
	callq	_Z22__device_stub__findvecPfiS_Pi
.LBB8_20:                               #   in Loop: Header=BB8_13 Depth=1
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB8_21
# %bb.26:                               # %_Z9gpuAssert10hipError_tPKcib.exit46
                                        #   in Loop: Header=BB8_13 Depth=1
	movq	16(%rsp), %rax
	movl	$0, (%rax)
	movq	40(%rsp), %rdi                  # 8-byte Reload
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB8_28
# %bb.27:                               #   in Loop: Header=BB8_13 Depth=1
	movq	8(%rsp), %rdi
	movq	16(%rsp), %rsi
	callq	_Z21__device_stub__reducePiPj
.LBB8_28:                               #   in Loop: Header=BB8_13 Depth=1
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB8_29
# %bb.30:                               # %_Z9gpuAssert10hipError_tPKcib.exit48
                                        #   in Loop: Header=BB8_13 Depth=1
	movq	16(%rsp), %rdi
	addl	24(%rsp), %r15d                 # 4-byte Folded Reload
	addl	(%rdi), %r15d
	incq	%rbp
	addq	$4, %rbx
	movq	%r12, %rax
	cmpq	%r12, %rbp
	jne	.LBB8_13
.LBB8_8:                                # %_Z9gpuAssert10hipError_tPKcib.exit40._crit_edge
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB8_9
# %bb.23:                               # %_Z9gpuAssert10hipError_tPKcib.exit42
	movq	8(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB8_24
# %bb.25:                               # %_Z9gpuAssert10hipError_tPKcib.exit44
	movl	%r15d, %eax
	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
.LBB8_29:
	.cfi_def_cfa_offset 128
	movl	%eax, %r14d
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.33, %esi
	movl	$.L.str.21, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$222, %r8d
	jmp	.LBB8_22
.LBB8_21:
	movl	%eax, %r14d
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.33, %esi
	movl	$.L.str.21, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$217, %r8d
.LBB8_22:
	xorl	%eax, %eax
	callq	fprintf
	movl	%r14d, %edi
	callq	exit
.LBB8_1:
	movl	%eax, %r13d
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.33, %esi
	movl	$.L.str.21, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$195, %r8d
	jmp	.LBB8_2
.LBB8_4:
	movl	%eax, %r13d
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.33, %esi
	movl	$.L.str.21, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$199, %r8d
	jmp	.LBB8_2
.LBB8_11:
	movl	%eax, %r13d
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.33, %esi
	movl	$.L.str.21, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$203, %r8d
.LBB8_2:
	xorl	%eax, %eax
	callq	fprintf
	movl	%r13d, %edi
	callq	exit
.LBB8_9:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.33, %esi
	movl	$.L.str.21, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$226, %r8d
	jmp	.LBB8_10
.LBB8_24:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.33, %esi
	movl	$.L.str.21, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$227, %r8d
.LBB8_10:
	xorl	%eax, %eax
	callq	fprintf
	movl	%ebx, %edi
	callq	exit
.Lfunc_end8:
	.size	_Z20find_similar_vectorsPfiiiib, .Lfunc_end8-_Z20find_similar_vectorsPfiiiib
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI9_0:
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.text
	.globl	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	$1368, %rsp                     # imm = 0x558
	.cfi_def_cfa_offset 1424
	.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, %rbx
	movl	%edi, %ebp
	leaq	24(%rsp), %r14
	movl	$.L__const.main.p, %esi
	movl	$1344, %edx                     # imm = 0x540
	movq	%r14, %rdi
	callq	memcpy@PLT
	movl	%ebp, %edi
	movq	%rbx, %rsi
	movq	%r14, %rdx
	callq	_Z15parse_argumentsiPPcP6params
	movq	%r14, %rdi
	callq	_Z11dump_paramsP6params
	leaq	32(%rsp), %r14
	movq	%r14, %rdi
	callq	_Z10countlinesPc
	movl	%eax, %ebx
	movl	-4(%r14), %esi
	leal	1(%rsi), %eax
	cmpl	%eax, %ebx
	jle	.LBB9_1
# %bb.2:
	leal	255(%rbx), %eax
	leal	510(%rbx), %ebp
	testl	%eax, %eax
	cmovnsl	%eax, %ebp
	movslq	%ebx, %rsi
	shlq	$2, %rsi
	leaq	8(%rsp), %rdi
	movl	$1, %edx
	callq	hipMallocManaged
	testl	%eax, %eax
	jne	.LBB9_23
# %bb.3:                                # %_Z9gpuAssert10hipError_tPKcib.exit
	movq	8(%rsp), %rsi
	movq	%r14, %rdi
	callq	_Z9load_dataPcPf
	xorps	%xmm1, %xmm1
	xorps	%xmm0, %xmm0
	xorps	%xmm2, %xmm2
	testl	%ebx, %ebx
	jle	.LBB9_6
# %bb.4:                                # %.lr.ph.preheader.i
	movq	8(%rsp), %rax
	movl	%ebx, %ecx
	xorl	%edx, %edx
.LBB9_5:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	movss	(%rax,%rdx,4), %xmm3            # xmm3 = mem[0],zero,zero,zero
	addss	%xmm3, %xmm2
	mulss	%xmm3, %xmm3
	addss	%xmm3, %xmm0
	incq	%rdx
	cmpq	%rdx, %rcx
	jne	.LBB9_5
.LBB9_6:                                # %_Z17sandard_deviationPfi.exit
	xorps	%xmm3, %xmm3
	cvtsi2ss	%ebx, %xmm3
	divss	%xmm3, %xmm2
	divss	%xmm3, %xmm0
	mulss	%xmm2, %xmm2
	subss	%xmm2, %xmm0
	ucomiss	%xmm1, %xmm0
	jb	.LBB9_8
# %bb.7:
	sqrtss	%xmm0, %xmm0
	jmp	.LBB9_9
.LBB9_1:
	movl	$.L.str.22, %edi
                                        # kill: def $esi killed $esi killed $rsi
	movl	%ebx, %edx
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB9_22
.LBB9_8:                                # %call.sqrt
	callq	sqrtf
.LBB9_9:                                # %_Z17sandard_deviationPfi.exit.split
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	movl	28(%rsp), %eax
	leaq	16(%rsp), %rsi
	movl	%eax, (%rsi)
	movl	$d_m, %edi
	movl	$4, %edx
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	testl	%eax, %eax
	jne	.LBB9_10
# %bb.12:                               # %_Z9gpuAssert10hipError_tPKcib.exit32
	movss	4(%rsp), %xmm0                  # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	mulss	24(%rsp), %xmm0
	leaq	20(%rsp), %rsi
	movss	%xmm0, (%rsi)
	movl	$d_r, %edi
	movl	$4, %edx
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	testl	%eax, %eax
	jne	.LBB9_13
# %bb.14:                               # %_Z9gpuAssert10hipError_tPKcib.exit34
	sarl	$8, %ebp
	leaq	698(%rsp), %rax
	movzbl	666(%rax), %r12d
	movq	8(%rsp), %rdi
	movl	16(%rsp), %edx
	movl	%ebx, %esi
	movl	%ebp, %ecx
	movl	$256, %r8d                      # imm = 0x100
	movl	%r12d, %r9d
	callq	_Z20find_similar_vectorsPfiiiib
	movl	%eax, %r14d
	movslq	%eax, %r15
	movq	8(%rsp), %rdi
	movl	16(%rsp), %edx
	incl	%edx
	movl	%ebx, %esi
	movl	%ebp, %ecx
	movl	$256, %r8d                      # imm = 0x100
	movl	%r12d, %r9d
	callq	_Z20find_similar_vectorsPfiiiib
	movl	%eax, %r12d
	movslq	%eax, %r13
	movl	$.L.str.23, %esi
	leaq	698(%rsp), %rdi
	callq	fopen
	movq	%rax, %rbx
	movl	$.L.str.24, %esi
	movq	%rax, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movl	$.L.str.25, %esi
	movq	%rbx, %rdi
	movq	%r13, %rdx
	xorl	%eax, %eax
	callq	fprintf
	testq	%r13, %r13
	js	.LBB9_15
# %bb.16:                               # %_Z9gpuAssert10hipError_tPKcib.exit34
	cvtsi2ss	%r12d, %xmm1
	jmp	.LBB9_17
.LBB9_15:
	shrq	%r13
	andl	$1, %r12d
	orq	%r13, %r12
	cvtsi2ss	%r12, %xmm1
	addss	%xmm1, %xmm1
.LBB9_17:                               # %_Z9gpuAssert10hipError_tPKcib.exit34
	testq	%r15, %r15
	js	.LBB9_18
# %bb.19:                               # %_Z9gpuAssert10hipError_tPKcib.exit34
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r14d, %xmm0
	jmp	.LBB9_20
.LBB9_18:
	shrq	%r15
	andl	$1, %r14d
	orq	%r15, %r14
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r14, %xmm0
	addss	%xmm0, %xmm0
.LBB9_20:                               # %_Z9gpuAssert10hipError_tPKcib.exit34
	divss	%xmm0, %xmm1
	movss	%xmm1, 4(%rsp)                  # 4-byte Spill
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	movl	$.L.str.26, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	movss	4(%rsp), %xmm0                  # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	callq	logf
	xorps	.LCPI9_0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.27, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	movq	%rbx, %rdi
	callq	fclose
	movq	8(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB9_24
# %bb.21:                               # %_Z9gpuAssert10hipError_tPKcib.exit36
	xorl	%ebx, %ebx
.LBB9_22:
	movl	%ebx, %eax
	addq	$1368, %rsp                     # imm = 0x558
	.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
.LBB9_23:
	.cfi_def_cfa_offset 1424
	movl	%eax, %r15d
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.33, %esi
	movl	$.L.str.21, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$258, %r8d                      # imm = 0x102
	xorl	%eax, %eax
	callq	fprintf
	movl	%r15d, %edi
	callq	exit
.LBB9_10:
	movl	%eax, %r14d
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.33, %esi
	movl	$.L.str.21, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$266, %r8d                      # imm = 0x10A
	jmp	.LBB9_11
.LBB9_13:
	movl	%eax, %r14d
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.33, %esi
	movl	$.L.str.21, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$268, %r8d                      # imm = 0x10C
.LBB9_11:
	xorl	%eax, %eax
	callq	fprintf
	movl	%r14d, %edi
	callq	exit
.LBB9_24:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.33, %esi
	movl	$.L.str.21, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$283, %r8d                      # imm = 0x11B
	xorl	%eax, %eax
	callq	fprintf
	movl	%ebx, %edi
	callq	exit
.Lfunc_end9:
	.size	main, .Lfunc_end9-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB10_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB10_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z6reducePiPj, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z7findvecPfiS_Pi, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$0, 8(%rsp)
	movl	$0, (%rsp)
	movl	$d_m, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movl	$4, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	callq	__hipRegisterVar
	movl	$0, 8(%rsp)
	movl	$0, (%rsp)
	movl	$d_r, %esi
	movl	$.L__unnamed_4, %edx
	movl	$.L__unnamed_4, %ecx
	movl	$4, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	callq	__hipRegisterVar
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end10:
	.size	__hip_module_ctor, .Lfunc_end10-__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	.LBB11_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
.LBB11_2:
	retq
.Lfunc_end11:
	.size	__hip_module_dtor, .Lfunc_end11-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	d_m,@object                     # @d_m
	.local	d_m
	.comm	d_m,4,4
	.type	d_r,@object                     # @d_r
	.local	d_r
	.comm	d_r,4,4
	.type	_Z6reducePiPj,@object           # @_Z6reducePiPj
	.section	.rodata,"a",@progbits
	.globl	_Z6reducePiPj
	.p2align	3, 0x0
_Z6reducePiPj:
	.quad	_Z21__device_stub__reducePiPj
	.size	_Z6reducePiPj, 8

	.type	_Z7findvecPfiS_Pi,@object       # @_Z7findvecPfiS_Pi
	.globl	_Z7findvecPfiS_Pi
	.p2align	3, 0x0
_Z7findvecPfiS_Pi:
	.quad	_Z22__device_stub__findvecPfiS_Pi
	.size	_Z7findvecPfiS_Pi, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"r"
	.size	.L.str, 2

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"%f"
	.size	.L.str.1, 3

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"last: %i\n"
	.size	.L.str.2, 10

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"#\n"
	.size	.L.str.3, 3

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"#m:%d\n"
	.size	.L.str.4, 7

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"#r:%f\n"
	.size	.L.str.5, 7

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"#infile:%s\n"
	.size	.L.str.6, 12

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"#outfile:%s\n"
	.size	.L.str.7, 13

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"#approx:%d\n"
	.size	.L.str.8, 12

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Usage: %s <params> \n\n"
	.size	.L.str.9, 22

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"mrioa:"
	.size	.L.str.18, 7

	.type	_ZL7options,@object             # @_ZL7options
	.data
	.p2align	4, 0x0
_ZL7options:
	.quad	.L.str.28
	.long	1                               # 0x1
	.zero	4
	.quad	0
	.long	105                             # 0x69
	.zero	4
	.quad	.L.str.29
	.long	1                               # 0x1
	.zero	4
	.quad	0
	.long	111                             # 0x6f
	.zero	4
	.quad	.L.str.30
	.long	1                               # 0x1
	.zero	4
	.quad	0
	.long	109                             # 0x6d
	.zero	4
	.quad	.L.str.31
	.long	1                               # 0x1
	.zero	4
	.quad	0
	.long	114                             # 0x72
	.zero	4
	.quad	.L.str.32
	.long	1                               # 0x1
	.zero	4
	.quad	0
	.long	97                              # 0x61
	.zero	4
	.size	_ZL7options, 160

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

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	"%i"
	.size	.L.str.20, 3

	.type	.L.str.21,@object               # @.str.21
.L.str.21:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/lukaszmachura/cusampen/master/cs.hip"
	.size	.L.str.21, 99

	.type	.L__const.main.p,@object        # @__const.main.p
	.section	.rodata,"a",@progbits
	.p2align	2, 0x0
.L__const.main.p:
	.long	0x3e4ccccd                      # float 0.200000003
	.long	2                               # 0x2
	.asciz	"data.dat\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
	.asciz	"out.dat\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
	.byte	0                               # 0x0
	.zero	3
	.size	.L__const.main.p, 1344

	.type	.L.str.22,@object               # @.str.22
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.22:
	.asciz	"m (%d) > length of data (%d)\nExiting..."
	.size	.L.str.22, 40

	.type	.L.str.23,@object               # @.str.23
.L.str.23:
	.asciz	"w"
	.size	.L.str.23, 2

	.type	.L.str.24,@object               # @.str.24
.L.str.24:
	.asciz	"m vector matches: %lu\n"
	.size	.L.str.24, 23

	.type	.L.str.25,@object               # @.str.25
.L.str.25:
	.asciz	"(m+1) vector matches: %lu\n"
	.size	.L.str.25, 27

	.type	.L.str.26,@object               # @.str.26
.L.str.26:
	.asciz	"ratio = n_{m+1}/n_m: %f\n"
	.size	.L.str.26, 25

	.type	.L.str.27,@object               # @.str.27
.L.str.27:
	.asciz	"SampEn = -ln(ratio): %f\n"
	.size	.L.str.27, 25

	.type	.L.str.28,@object               # @.str.28
.L.str.28:
	.asciz	"in"
	.size	.L.str.28, 3

	.type	.L.str.29,@object               # @.str.29
.L.str.29:
	.asciz	"out"
	.size	.L.str.29, 4

	.type	.L.str.30,@object               # @.str.30
.L.str.30:
	.asciz	"embed"
	.size	.L.str.30, 6

	.type	.L.str.31,@object               # @.str.31
.L.str.31:
	.asciz	"radius"
	.size	.L.str.31, 7

	.type	.L.str.32,@object               # @.str.32
.L.str.32:
	.asciz	"apen"
	.size	.L.str.32, 5

	.type	.L.str.33,@object               # @.str.33
.L.str.33:
	.asciz	"GPUassert: %s %s %d\n"
	.size	.L.str.33, 21

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z6reducePiPj"
	.size	.L__unnamed_1, 14

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z7findvecPfiS_Pi"
	.size	.L__unnamed_2, 18

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"d_m"
	.size	.L__unnamed_3, 4

	.type	.L__unnamed_4,@object           # @3
.L__unnamed_4:
	.asciz	"d_r"
	.size	.L__unnamed_4, 4

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Model params:"
	.size	.Lstr, 14

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"   -m, --embed=INT        set the embedding dimension 'dim' to INT"
	.size	.Lstr.1, 67

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"   -r, --radius=FLOAT     set the maximal distance between vectors"
	.size	.Lstr.2, 67

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"                          to 'radius' to FLOAT"
	.size	.Lstr.3, 47

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"   -i, --in=FILE_NAME     set the input data to FILE_NAME"
	.size	.Lstr.4, 58

	.type	.Lstr.5,@object                 # @str.5
.Lstr.5:
	.asciz	"   -o, --out=FILE_NAME    set the output data to FILE_NAME"
	.size	.Lstr.5, 59

	.type	.Lstr.6,@object                 # @str.6
.Lstr.6:
	.asciz	"   -a, --apen=INT         calculates Approximate Entropy (1) instead of SampEn (def, 0)"
	.size	.Lstr.6, 88

	.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 _Z21__device_stub__reducePiPj
	.addrsig_sym _Z22__device_stub__findvecPfiS_Pi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym d_m
	.addrsig_sym d_r
	.addrsig_sym _Z6reducePiPj
	.addrsig_sym _Z7findvecPfiS_Pi
	.addrsig_sym _ZL7options
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z6reducePiPj           ; -- Begin function _Z6reducePiPj
	.globl	_Z6reducePiPj
	.p2align	8
	.type	_Z6reducePiPj,@function
_Z6reducePiPj:                          ; @_Z6reducePiPj
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x1c
	s_load_b128 s[0:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	s_cmp_lt_u32 s4, 2
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	v_add_co_u32 v1, vcc_lo, s0, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	global_load_b32 v1, v[1:2], off
	v_lshlrev_b32_e32 v2, 2, v0
	s_waitcnt vmcnt(0)
	ds_store_b32 v2, v1
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB0_5
; %bb.1:                                ; %.lr.ph.preheader
	s_mov_b32 s1, 1
.LBB0_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	s_lshl_b32 s0, s1, 1
	s_mov_b32 s5, exec_lo
	v_mul_lo_u32 v1, s0, v0
	v_cmpx_gt_u32_e64 s4, v1
	s_cbranch_execz .LBB0_4
; %bb.3:                                ;   in Loop: Header=BB0_2 Depth=1
	v_lshlrev_b32_e32 v1, 2, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_lshl_add_u32 v2, s1, 2, v1
	ds_load_b32 v2, v2
	ds_load_b32 v3, v1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u32_e32 v2, v3, v2
	ds_store_b32 v1, v2
.LBB0_4:                                ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s5
	s_cmp_ge_u32 s0, s4
	s_mov_b32 s1, s0
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_2
.LBB0_5:                                ; %._crit_edge
	s_mov_b32 s0, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_8
; %bb.6:
	s_mov_b32 s0, exec_lo
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mbcnt_lo_u32_b32 v0, s0, 0
	v_cmp_eq_u32_e32 vcc_lo, 0, v0
	s_and_b32 s1, exec_lo, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_mov_b32 exec_lo, s1
	s_cbranch_execz .LBB0_8
; %bb.7:
	v_mov_b32_e32 v0, 0
	s_bcnt1_i32_b32 s0, s0
	ds_load_b32 v1, v0
	s_waitcnt lgkmcnt(0)
	v_mul_lo_u32 v1, v1, s0
	global_atomic_add_u32 v0, v1, s[2:3]
.LBB0_8:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6reducePiPj
		.amdhsa_group_segment_fixed_size 1024
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 4
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z6reducePiPj, .Lfunc_end0-_Z6reducePiPj
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 336
; NumSgprs: 18
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 1024 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 4
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z7findvecPfiS_Pi       ; -- Begin function _Z7findvecPfiS_Pi
	.globl	_Z7findvecPfiS_Pi
	.p2align	8
	.type	_Z7findvecPfiS_Pi,@function
_Z7findvecPfiS_Pi:                      ; @_Z7findvecPfiS_Pi
; %bb.0:
	s_clause 0x2
	s_load_b32 s3, s[0:1], 0x2c
	s_load_b32 s2, s[0:1], 0x8
	s_load_b128 s[4:7], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s3, s3, 0xffff
	s_cmp_lt_i32 s2, 1
	v_mad_u64_u32 v[1:2], null, s15, s3, v[0:1]
	s_cbranch_scc1 .LBB1_6
; %bb.1:                                ; %.lr.ph
	s_getpc_b64 s[8:9]
	s_add_u32 s8, s8, d_r@rel32@lo+4
	s_addc_u32 s9, s9, d_r@rel32@hi+12
	s_delay_alu instid0(VALU_DEP_1)
	v_mov_b32_e32 v2, v1
	s_load_b64 s[0:1], s[0:1], 0x0
	s_load_b32 s3, s[8:9], 0x0
	s_mov_b32 s9, 0
                                        ; implicit-def: $sgpr8
                                        ; implicit-def: $sgpr11
                                        ; implicit-def: $sgpr10
.LBB1_2:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1)
	v_ashrrev_i32_e32 v3, 31, v2
	s_waitcnt lgkmcnt(0)
	s_load_b32 s12, s[0:1], 0x0
	s_or_b32 s10, s10, exec_lo
	s_or_b32 s11, s11, exec_lo
	v_lshlrev_b64 v[3:4], 2, v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v3, vcc_lo, s4, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v4, vcc_lo
	global_load_b32 v0, v[3:4], off
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_subrev_f32_e32 v0, s12, v0
	s_mov_b32 s12, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_le_f32_e64 |v0|, s3
; %bb.3:                                ;   in Loop: Header=BB1_2 Depth=1
	s_add_i32 s2, s2, -1
	s_add_u32 s0, s0, 4
	s_addc_u32 s1, s1, 0
	s_cmp_eq_u32 s2, 0
	v_add_nc_u32_e32 v2, 1, v2
	s_cselect_b32 s13, -1, 0
	s_and_not1_b32 s11, s11, exec_lo
	s_and_b32 s13, s13, exec_lo
	s_and_not1_b32 s10, s10, exec_lo
	s_or_b32 s11, s11, s13
; %bb.4:                                ; %Flow
                                        ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s12
	s_xor_b32 s12, s10, -1
	s_and_b32 s13, exec_lo, s11
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	s_or_b32 s9, s13, s9
	s_and_not1_b32 s8, s8, exec_lo
	s_and_b32 s12, s12, exec_lo
	s_or_b32 s8, s8, s12
	s_and_not1_b32 exec_lo, exec_lo, s9
	s_cbranch_execnz .LBB1_2
; %bb.5:                                ; %loop.exit.guard
	s_or_b32 exec_lo, exec_lo, s9
	s_branch .LBB1_7
.LBB1_6:
	s_mov_b32 s8, -1
.LBB1_7:                                ; %Flow27
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s0, s8
	s_cbranch_execz .LBB1_9
; %bb.8:                                ; %.critedge
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v2, 31, v1
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	v_mov_b32_e32 v2, 1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v0, vcc_lo, s6, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v1, vcc_lo
	global_store_b32 v[0:1], v2, off
.LBB1_9:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7findvecPfiS_Pi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 5
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z7findvecPfiS_Pi, .Lfunc_end1-_Z7findvecPfiS_Pi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 348
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.protected	d_m                     ; @d_m
	.type	d_m,@object
	.section	.bss,"aw",@nobits
	.globl	d_m
	.p2align	2, 0x0
d_m:
	.long	0                               ; 0x0
	.size	d_m, 4

	.protected	d_r                     ; @d_r
	.type	d_r,@object
	.globl	d_r
	.p2align	2, 0x0
d_r:
	.long	0x00000000                      ; float 0
	.size	d_r, 4

	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.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 d_m
	.addrsig_sym d_r
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 1024
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z6reducePiPj
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z6reducePiPj.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     4
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7findvecPfiS_Pi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z7findvecPfiS_Pi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
