#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "unistd.h"
#include "time.h"
#include "string.h"

// Stores temporary shift values
__constant__ float dm_shifts[4096];

// ---------------------- Optimised Dedispersion Loop  ------------------------------
__global__ void dedisperse_loop(float *outbuff, float *buff, int nsamp, int nchans, float tsamp,
                                float startdm, float dmstep, int maxshift)
{
    extern __shared__ float shared[];

    int c, s = threadIdx.x + blockIdx.x * blockDim.x;
    float shift_temp = (startdm + blockIdx.y * dmstep) / tsamp;
    
    for (s = threadIdx.x + blockIdx.x * blockDim.x; 
         s < nsamp; 
         s += blockDim.x * gridDim.x) {

        shared[threadIdx.x] = 0;
     
        for(c = 0; c < nchans; c++) {
            int shift = c * (nsamp + maxshift) + floor(dm_shifts[c] * shift_temp);
            shared[threadIdx.x] += buff[s + shift];
        }

        outbuff[blockIdx.y * nsamp + s] = shared[threadIdx.x];
    }
}

// -------------------------- Main Program -----------------------------------

float fch1 = 156, foff = -0.005859375, tsamp = 0.000165, dmstep = 0.02, startdm = 0;
int nchans = 1024, nsamp = 1024, tdms = 1024;
int gridsize = 128, blocksize = 128;

// Process command-line parameters
void process_arguments(int argc, char *argv[])
{
    int i = 1;
    
    while((fopen(argv[i], "r")) != NULL)
        i++;

    while(i < argc) {
       if (!strcmp(argv[i], "-nchans"))
           nchans = atoi(argv[++i]);
       else if (!strcmp(argv[i], "-nsamp"))
           nsamp = atoi(argv[++i]);
       else if (!strcmp(argv[i], "-dmstep"))
           dmstep = atof(argv[++i]);
       else if (!strcmp(argv[i], "-startdm"))
           startdm = atof(argv[++i]);
       else if (!strcmp(argv[i], "-tdms"))
           tdms = atoi(argv[++i]);
       else if (!strcmp(argv[i], "-gridsize"))
           gridsize = atoi(argv[++i]);
       else if (!strcmp(argv[i], "-blocksize"))
           blocksize = atoi(argv[++i]);
       else if (!strcmp(argv[i], "-tsamp"))
           tsamp = atof(argv[++i]);
       else if (!strcmp(argv[i], "-foff"))
           foff = -atof(argv[++i]);
       i++;
    }
}

// Fill buffer with data (blocking call)
void generate_data(float* buffer, int nsamp, int nchans)
{
    for(int i = 0; i < nsamp * nchans; i++)
        buffer[i] = 0.1;
}

// DM delay calculation
float dmdelay(float f1, float f2)
{
  return(4148.741601 * ((1.0 / f1 / f1) - (1.0 / f2 / f2)));
}

int main(int argc, char *argv[])
{
   float *input, *output, *d_input, *d_output;
   int maxshift, i, j;

   process_arguments(argc, argv);

    // Calculate temporary DM-shifts
    float *dmshifts = (float *) malloc(nchans * sizeof(float));
    for (unsigned i = 0; i < nchans; i++)
          dmshifts[i] = dmdelay(fch1 + (foff * i), fch1);

    // Calculate maxshift
    maxshift = ceil(dmshifts[nchans - 1] * (startdm + dmstep * tdms) / tsamp);

    // Allocate and initialise arrays
    input = (float *) malloc( (nsamp + maxshift) * nchans * sizeof(float));
    output = (float *) malloc( nsamp * tdms * sizeof(float));
    for(i = 0; i < nchans; i++)
        for(j = 0; j < nsamp + maxshift; j++) {
            input[i * (nsamp + maxshift) + j] = i;
         }

    // Initialise CUDA stuff
    ( cudaSetDevice(1));
    cudaEvent_t event_start, event_stop;
    float timestamp, kernelTime;

    cudaEventCreate(&event_start); 
    cudaEventCreate(&event_stop);

    printf("nsamp: %d, nchans: %d, tsamp: %f, startdm: %f, dmstep: %f, tdms: %d, fch1: %f, foff: %f, maxshift: %d\n",
           nsamp, nchans, tsamp, startdm, dmstep, tdms, fch1, foff, maxshift);

    // Allocate CUDA memory and copy dmshifts
    ( cudaMalloc((void **) &d_input, (nsamp + maxshift) * nchans * sizeof(float)));
    ( cudaMalloc((void **) &d_output, nsamp * tdms * sizeof(float)));
    ( cudaMemset(d_output, 0, nsamp * tdms * sizeof(float)));
    ( cudaMemcpyToSymbol(dm_shifts, dmshifts, nchans * sizeof(int)) );

    time_t start = time(NULL);

    // Copy input to GPU
    cudaEventRecord(event_start, 0);
    ( cudaMemcpy(d_input, input, (nsamp + maxshift) * nchans * sizeof(float), cudaMemcpyHostToDevice) );    
    cudaEventRecord(event_stop, 0);
    cudaEventSynchronize(event_stop);
    cudaEventElapsedTime(&timestamp, event_start, event_stop);
    printf("Copied to GPU in: %lf\n", timestamp);

    dim3 gridDim(nsamp / blocksize, tdms);  
    cudaEventRecord(event_start, 0);
    dedisperse_loop<<<gridDim, blocksize, 512>>>(d_output, d_input, nsamp, nchans, tsamp, startdm, dmstep, maxshift);
    cudaEventRecord(event_stop, 0);
    cudaEventSynchronize(event_stop);
    cudaEventElapsedTime(&timestamp, event_start, event_stop);
    printf("Processed in: %lf\n", timestamp);
    kernelTime = timestamp;

    // Copy output from GPU
    cudaEventRecord(event_start, 0);
    ( cudaMemcpy(output, d_output, nsamp * tdms * sizeof(float), cudaMemcpyDeviceToHost) );    
    cudaEventRecord(event_stop, 0);
    cudaEventSynchronize(event_stop);
    cudaEventElapsedTime(&timestamp, event_start, event_stop);
    printf("Copied from GPU in: %lf\n", timestamp);

    // Check values
    int val = 0;
    for(i = 0; i < nchans; i++) val += i;

 /*   for(i = 0; i < tdms; i++)
        for(j = 0; j < nsamp; j++)
            if (output[i * nsamp + j] != val)
                printf("Error: dm: %d nsamp: %d value:%f \n", i, j, output[i*nsamp+j]);

*/
    printf("Total time: %d\n", (int) (time(NULL) - start));
    printf("Performance: %lf Gflops\n", (nchans * tdms) * (nsamp * 1.0 / kernelTime / 1.0e6));
}


	.file	"tmpxft_002d3aff_00000000-6_brute_dedisp_imp.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2046:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2046:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"r"
.LC1:
	.string	"-nchans"
.LC2:
	.string	"-nsamp"
.LC3:
	.string	"-dmstep"
.LC4:
	.string	"-startdm"
.LC5:
	.string	"-tdms"
.LC6:
	.string	"-gridsize"
.LC7:
	.string	"-blocksize"
.LC8:
	.string	"-tsamp"
.LC9:
	.string	"-foff"
	.text
	.globl	_Z17process_argumentsiPPc
	.type	_Z17process_argumentsiPPc, @function
_Z17process_argumentsiPPc:
.LFB2040:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%edi, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	.LC0(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	$1, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	pushq	%rdx
	.cfi_def_cfa_offset 64
.L3:
	movq	(%rbx,%rbp,8), %rdi
	movq	%r12, %rsi
	movq	%rbp, %r13
	incq	%rbp
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L3
	leaq	.LC4(%rip), %r15
.L4:
	cmpl	%r14d, %r13d
	jge	.L19
	movslq	%r13d, %rax
	leaq	.LC1(%rip), %rsi
	movq	(%rbx,%rax,8), %r12
	leaq	0(,%rax,8), %rbp
	movq	%r12, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L5
	movq	8(%rbx,%rbp), %rdi
	call	atoi@PLT
	movl	%eax, nchans(%rip)
.L8:
	incl	%r13d
	jmp	.L6
.L5:
	leaq	.LC2(%rip), %rsi
	movq	%r12, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L7
	movq	8(%rbx,%rbp), %rdi
	call	atoi@PLT
	movl	%eax, nsamp(%rip)
	jmp	.L8
.L7:
	leaq	.LC3(%rip), %rsi
	movq	%r12, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L9
	movq	8(%rbx,%rbp), %rdi
	call	atof@PLT
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, dmstep(%rip)
	jmp	.L8
.L9:
	movq	%r15, %rsi
	movq	%r12, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L10
	movq	8(%rbx,%rbp), %rdi
	call	atof@PLT
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, startdm(%rip)
	jmp	.L8
.L10:
	leaq	.LC5(%rip), %rsi
	movq	%r12, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L11
	movq	8(%rbx,%rbp), %rdi
	call	atoi@PLT
	movl	%eax, tdms(%rip)
	jmp	.L8
.L11:
	leaq	.LC6(%rip), %rsi
	movq	%r12, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L12
	movq	8(%rbx,%rbp), %rdi
	call	atoi@PLT
	movl	%eax, gridsize(%rip)
	jmp	.L8
.L12:
	leaq	.LC7(%rip), %rsi
	movq	%r12, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L13
	movq	8(%rbx,%rbp), %rdi
	call	atoi@PLT
	movl	%eax, blocksize(%rip)
	jmp	.L8
.L13:
	leaq	.LC8(%rip), %rsi
	movq	%r12, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L14
	movq	8(%rbx,%rbp), %rdi
	call	atof@PLT
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, tsamp(%rip)
	jmp	.L8
.L14:
	leaq	.LC9(%rip), %rsi
	movq	%r12, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L6
	movq	8(%rbx,%rbp), %rdi
	call	atof@PLT
	cvtsd2ss	%xmm0, %xmm0
	xorps	.LC10(%rip), %xmm0
	movss	%xmm0, foff(%rip)
	jmp	.L8
.L6:
	incl	%r13d
	jmp	.L4
.L19:
	popq	%rax
	.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
.LFE2040:
	.size	_Z17process_argumentsiPPc, .-_Z17process_argumentsiPPc
	.globl	_Z13generate_dataPfii
	.type	_Z13generate_dataPfii, @function
_Z13generate_dataPfii:
.LFB2041:
	.cfi_startproc
	endbr64
	imull	%edx, %esi
	movss	.LC11(%rip), %xmm0
	xorl	%eax, %eax
.L21:
	cmpl	%eax, %esi
	jle	.L23
	movss	%xmm0, (%rdi,%rax,4)
	incq	%rax
	jmp	.L21
.L23:
	ret
	.cfi_endproc
.LFE2041:
	.size	_Z13generate_dataPfii, .-_Z13generate_dataPfii
	.globl	_Z7dmdelayff
	.type	_Z7dmdelayff, @function
_Z7dmdelayff:
.LFB2042:
	.cfi_startproc
	endbr64
	movsd	.LC12(%rip), %xmm2
	cvtss2sd	%xmm0, %xmm3
	cvtss2sd	%xmm1, %xmm1
	movaps	%xmm2, %xmm0
	divsd	%xmm3, %xmm0
	divsd	%xmm1, %xmm2
	divsd	%xmm3, %xmm0
	divsd	%xmm1, %xmm2
	subsd	%xmm2, %xmm0
	mulsd	.LC13(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	ret
	.cfi_endproc
.LFE2042:
	.size	_Z7dmdelayff, .-_Z7dmdelayff
	.globl	_Z43__device_stub__Z15dedisperse_loopPfS_iifffiPfS_iifffi
	.type	_Z43__device_stub__Z15dedisperse_loopPfS_iifffiPfS_iifffi, @function
_Z43__device_stub__Z15dedisperse_loopPfS_iifffiPfS_iifffi:
.LFB2068:
	.cfi_startproc
	endbr64
	subq	$200, %rsp
	.cfi_def_cfa_offset 208
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movl	%edx, 28(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 24(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 8(%rsp)
	movss	%xmm0, 20(%rsp)
	movss	%xmm1, 16(%rsp)
	movss	%xmm2, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 184(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	28(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 176(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	pushq	64(%rsp)
	.cfi_def_cfa_offset 216
	leaq	_Z15dedisperse_loopPfS_iifffi(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 224
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 216
	popq	%rdx
	.cfi_def_cfa_offset 208
.L25:
	movq	184(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$200, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2068:
	.size	_Z43__device_stub__Z15dedisperse_loopPfS_iifffiPfS_iifffi, .-_Z43__device_stub__Z15dedisperse_loopPfS_iifffiPfS_iifffi
	.globl	_Z15dedisperse_loopPfS_iifffi
	.type	_Z15dedisperse_loopPfS_iifffi, @function
_Z15dedisperse_loopPfS_iifffi:
.LFB2069:
	.cfi_startproc
	endbr64
	jmp	_Z43__device_stub__Z15dedisperse_loopPfS_iifffiPfS_iifffi
	.cfi_endproc
.LFE2069:
	.size	_Z15dedisperse_loopPfS_iifffi, .-_Z15dedisperse_loopPfS_iifffi
	.section	.rodata.str1.1
.LC14:
	.string	"nsamp: %d, nchans: %d, tsamp: %f, startdm: %f, dmstep: %f, tdms: %d, fch1: %f, foff: %f, maxshift: %d\n"
.LC15:
	.string	"Copied to GPU in: %lf\n"
.LC16:
	.string	"Processed in: %lf\n"
.LC17:
	.string	"Copied from GPU in: %lf\n"
.LC18:
	.string	"Total time: %d\n"
.LC20:
	.string	"Performance: %lf Gflops\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2043:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	call	_Z17process_argumentsiPPc
	movslq	nchans(%rip), %r12
	movq	%r12, %rbp
	salq	$2, %r12
	movq	%r12, %rdi
	call	malloc@PLT
	movss	fch1(%rip), %xmm4
	movss	foff(%rip), %xmm5
	movq	%rax, %rbx
	xorl	%eax, %eax
.L31:
	cmpl	%ebp, %eax
	jnb	.L42
	movl	%eax, %edx
	movaps	%xmm4, %xmm1
	cvtsi2ssq	%rdx, %xmm0
	mulss	%xmm5, %xmm0
	addss	%xmm4, %xmm0
	call	_Z7dmdelayff
	movss	%xmm0, (%rbx,%rax,4)
	incq	%rax
	jmp	.L31
.L42:
	movl	tdms(%rip), %r13d
	cvtsi2ssl	%r13d, %xmm0
	mulss	dmstep(%rip), %xmm0
	addss	startdm(%rip), %xmm0
	mulss	-4(%rbx,%r12), %xmm0
	divss	tsamp(%rip), %xmm0
	call	ceilf@PLT
	movl	%ebp, %edi
	movl	nsamp(%rip), %edx
	cvttss2sil	%xmm0, %r12d
	movl	%edx, 12(%rsp)
	leal	(%rdx,%r12), %r15d
	imull	%r15d, %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	movl	12(%rsp), %edx
	movq	%rax, %r14
	imull	%edx, %r13d
	movslq	%r13d, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	xorl	%ecx, %ecx
	xorl	%edx, %edx
	movq	%rax, %r13
.L35:
	cmpl	%edx, %ebp
	jle	.L37
	movslq	%ecx, %rax
	leaq	(%r14,%rax,4), %rsi
	xorl	%eax, %eax
.L38:
	cmpl	%eax, %r15d
	jle	.L43
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, (%rsi,%rax,4)
	incq	%rax
	jmp	.L38
.L43:
	incl	%edx
	addl	%r15d, %ecx
	jmp	.L35
.L37:
	movl	$1, %edi
	leaq	28(%rsp), %rbp
	call	cudaSetDevice@PLT
	leaq	48(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	56(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	nchans(%rip), %ecx
	movl	%r12d, %r9d
	movb	$5, %al
	movl	tdms(%rip), %r8d
	movl	nsamp(%rip), %edx
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	cvtss2sd	foff(%rip), %xmm4
	cvtss2sd	fch1(%rip), %xmm3
	cvtss2sd	dmstep(%rip), %xmm2
	cvtss2sd	startdm(%rip), %xmm1
	cvtss2sd	tsamp(%rip), %xmm0
	call	__printf_chk@PLT
	movl	nsamp(%rip), %esi
	leaq	32(%rsp), %rdi
	addl	%r12d, %esi
	imull	nchans(%rip), %esi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	nsamp(%rip), %esi
	leaq	40(%rsp), %rdi
	imull	tdms(%rip), %esi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	nsamp(%rip), %edx
	imull	tdms(%rip), %edx
	xorl	%esi, %esi
	movq	40(%rsp), %rdi
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemset@PLT
	movl	$1, %r8d
	xorl	%ecx, %ecx
	movq	%rbx, %rsi
	movslq	nchans(%rip), %rdx
	leaq	_ZL9dm_shifts(%rip), %rdi
	salq	$2, %rdx
	call	cudaMemcpyToSymbol@PLT
	xorl	%edi, %edi
	call	time@PLT
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	movq	%rax, %rbx
	call	cudaEventRecord@PLT
	movl	nsamp(%rip), %edx
	movq	32(%rsp), %rdi
	movq	%r14, %rsi
	movl	$1, %ecx
	addl	%r12d, %edx
	imull	nchans(%rip), %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	movq	%rbp, %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	28(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	48(%rsp), %rdi
	movl	nsamp(%rip), %eax
	movl	$1, 72(%rsp)
	cltd
	idivl	blocksize(%rip)
	xorl	%esi, %esi
	movl	%eax, 64(%rsp)
	movl	tdms(%rip), %eax
	movl	%eax, 68(%rsp)
	call	cudaEventRecord@PLT
	movl	blocksize(%rip), %eax
	movq	64(%rsp), %rdi
	xorl	%r9d, %r9d
	movl	72(%rsp), %esi
	movl	$512, %r8d
	movl	%eax, 76(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 80(%rsp)
	movl	84(%rsp), %ecx
	movq	76(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L39
	movl	nchans(%rip), %ecx
	movl	nsamp(%rip), %edx
	movl	%r12d, %r8d
	movss	dmstep(%rip), %xmm2
	movss	startdm(%rip), %xmm1
	movss	tsamp(%rip), %xmm0
	movq	32(%rsp), %rsi
	movq	40(%rsp), %rdi
	call	_Z43__device_stub__Z15dedisperse_loopPfS_iifffiPfS_iifffi
.L39:
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	movq	%rbp, %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	28(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	movss	28(%rsp), %xmm2
	movss	%xmm2, 12(%rsp)
	call	cudaEventRecord@PLT
	movl	nsamp(%rip), %edx
	movq	40(%rsp), %rsi
	movq	%r13, %rdi
	imull	tdms(%rip), %edx
	movl	$2, %ecx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	movq	%rbp, %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC17(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	28(%rsp), %xmm0
	call	__printf_chk@PLT
	xorl	%edi, %edi
	call	time@PLT
	leaq	.LC18(%rip), %rsi
	movl	$2, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	subl	%ebx, %edx
	call	__printf_chk@PLT
	movss	12(%rsp), %xmm2
	cvtsi2sdl	nsamp(%rip), %xmm1
	leaq	.LC20(%rip), %rsi
	movl	nchans(%rip), %eax
	imull	tdms(%rip), %eax
	movl	$2, %edi
	cvtss2sd	%xmm2, %xmm2
	divsd	%xmm2, %xmm1
	cvtsi2sdl	%eax, %xmm0
	movb	$1, %al
	divsd	.LC19(%rip), %xmm1
	mulsd	%xmm1, %xmm0
	call	__printf_chk@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L40
	call	__stack_chk_fail@PLT
.L40:
	addq	$104, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2043:
	.size	main, .-main
	.section	.rodata.str1.1
.LC21:
	.string	"_Z15dedisperse_loopPfS_iifffi"
.LC22:
	.string	"dm_shifts"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2071:
	.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	.LC21(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z15dedisperse_loopPfS_iifffi(%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	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC22(%rip), %rdx
	movl	$16384, %r9d
	leaq	_ZL9dm_shifts(%rip), %rsi
	pushq	$1
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.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
.LFE2071:
	.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
	.globl	blocksize
	.data
	.align 4
	.type	blocksize, @object
	.size	blocksize, 4
blocksize:
	.long	128
	.globl	gridsize
	.align 4
	.type	gridsize, @object
	.size	gridsize, 4
gridsize:
	.long	128
	.globl	tdms
	.align 4
	.type	tdms, @object
	.size	tdms, 4
tdms:
	.long	1024
	.globl	nsamp
	.align 4
	.type	nsamp, @object
	.size	nsamp, 4
nsamp:
	.long	1024
	.globl	nchans
	.align 4
	.type	nchans, @object
	.size	nchans, 4
nchans:
	.long	1024
	.globl	startdm
	.bss
	.align 4
	.type	startdm, @object
	.size	startdm, 4
startdm:
	.zero	4
	.globl	dmstep
	.data
	.align 4
	.type	dmstep, @object
	.size	dmstep, 4
dmstep:
	.long	1017370378
	.globl	tsamp
	.align 4
	.type	tsamp, @object
	.size	tsamp, 4
tsamp:
	.long	959251418
	.globl	foff
	.align 4
	.type	foff, @object
	.size	foff, 4
foff:
	.long	-1145044992
	.globl	fch1
	.align 4
	.type	fch1, @object
	.size	fch1, 4
fch1:
	.long	1125908480
	.local	_ZL9dm_shifts
	.comm	_ZL9dm_shifts,16384,32
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC10:
	.long	-2147483648
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC11:
	.long	1036831949
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC12:
	.long	0
	.long	1072693248
	.align 8
.LC13:
	.long	-644863570
	.long	1085289661
	.align 8
.LC19:
	.long	0
	.long	1093567616
	.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 <stdlib.h>
#include <stdio.h>
#include "unistd.h"
#include "time.h"
#include "string.h"

// Stores temporary shift values
__constant__ float dm_shifts[4096];

// ---------------------- Optimised Dedispersion Loop  ------------------------------
__global__ void dedisperse_loop(float *outbuff, float *buff, int nsamp, int nchans, float tsamp,
                                float startdm, float dmstep, int maxshift)
{
    extern __shared__ float shared[];

    int c, s = threadIdx.x + blockIdx.x * blockDim.x;
    float shift_temp = (startdm + blockIdx.y * dmstep) / tsamp;
    
    for (s = threadIdx.x + blockIdx.x * blockDim.x; 
         s < nsamp; 
         s += blockDim.x * gridDim.x) {

        shared[threadIdx.x] = 0;
     
        for(c = 0; c < nchans; c++) {
            int shift = c * (nsamp + maxshift) + floor(dm_shifts[c] * shift_temp);
            shared[threadIdx.x] += buff[s + shift];
        }

        outbuff[blockIdx.y * nsamp + s] = shared[threadIdx.x];
    }
}

// -------------------------- Main Program -----------------------------------

float fch1 = 156, foff = -0.005859375, tsamp = 0.000165, dmstep = 0.02, startdm = 0;
int nchans = 1024, nsamp = 1024, tdms = 1024;
int gridsize = 128, blocksize = 128;

// Process command-line parameters
void process_arguments(int argc, char *argv[])
{
    int i = 1;
    
    while((fopen(argv[i], "r")) != NULL)
        i++;

    while(i < argc) {
       if (!strcmp(argv[i], "-nchans"))
           nchans = atoi(argv[++i]);
       else if (!strcmp(argv[i], "-nsamp"))
           nsamp = atoi(argv[++i]);
       else if (!strcmp(argv[i], "-dmstep"))
           dmstep = atof(argv[++i]);
       else if (!strcmp(argv[i], "-startdm"))
           startdm = atof(argv[++i]);
       else if (!strcmp(argv[i], "-tdms"))
           tdms = atoi(argv[++i]);
       else if (!strcmp(argv[i], "-gridsize"))
           gridsize = atoi(argv[++i]);
       else if (!strcmp(argv[i], "-blocksize"))
           blocksize = atoi(argv[++i]);
       else if (!strcmp(argv[i], "-tsamp"))
           tsamp = atof(argv[++i]);
       else if (!strcmp(argv[i], "-foff"))
           foff = -atof(argv[++i]);
       i++;
    }
}

// Fill buffer with data (blocking call)
void generate_data(float* buffer, int nsamp, int nchans)
{
    for(int i = 0; i < nsamp * nchans; i++)
        buffer[i] = 0.1;
}

// DM delay calculation
float dmdelay(float f1, float f2)
{
  return(4148.741601 * ((1.0 / f1 / f1) - (1.0 / f2 / f2)));
}

int main(int argc, char *argv[])
{
   float *input, *output, *d_input, *d_output;
   int maxshift, i, j;

   process_arguments(argc, argv);

    // Calculate temporary DM-shifts
    float *dmshifts = (float *) malloc(nchans * sizeof(float));
    for (unsigned i = 0; i < nchans; i++)
          dmshifts[i] = dmdelay(fch1 + (foff * i), fch1);

    // Calculate maxshift
    maxshift = ceil(dmshifts[nchans - 1] * (startdm + dmstep * tdms) / tsamp);

    // Allocate and initialise arrays
    input = (float *) malloc( (nsamp + maxshift) * nchans * sizeof(float));
    output = (float *) malloc( nsamp * tdms * sizeof(float));
    for(i = 0; i < nchans; i++)
        for(j = 0; j < nsamp + maxshift; j++) {
            input[i * (nsamp + maxshift) + j] = i;
         }

    // Initialise CUDA stuff
    ( hipSetDevice(1));
    hipEvent_t event_start, event_stop;
    float timestamp, kernelTime;

    hipEventCreate(&event_start); 
    hipEventCreate(&event_stop);

    printf("nsamp: %d, nchans: %d, tsamp: %f, startdm: %f, dmstep: %f, tdms: %d, fch1: %f, foff: %f, maxshift: %d\n",
           nsamp, nchans, tsamp, startdm, dmstep, tdms, fch1, foff, maxshift);

    // Allocate CUDA memory and copy dmshifts
    ( hipMalloc((void **) &d_input, (nsamp + maxshift) * nchans * sizeof(float)));
    ( hipMalloc((void **) &d_output, nsamp * tdms * sizeof(float)));
    ( hipMemset(d_output, 0, nsamp * tdms * sizeof(float)));
    ( hipMemcpyToSymbol(HIP_SYMBOL(dm_shifts), dmshifts, nchans * sizeof(int)) );

    time_t start = time(NULL);

    // Copy input to GPU
    hipEventRecord(event_start, 0);
    ( hipMemcpy(d_input, input, (nsamp + maxshift) * nchans * sizeof(float), hipMemcpyHostToDevice) );    
    hipEventRecord(event_stop, 0);
    hipEventSynchronize(event_stop);
    hipEventElapsedTime(&timestamp, event_start, event_stop);
    printf("Copied to GPU in: %lf\n", timestamp);

    dim3 gridDim(nsamp / blocksize, tdms);  
    hipEventRecord(event_start, 0);
    dedisperse_loop<<<gridDim, blocksize, 512>>>(d_output, d_input, nsamp, nchans, tsamp, startdm, dmstep, maxshift);
    hipEventRecord(event_stop, 0);
    hipEventSynchronize(event_stop);
    hipEventElapsedTime(&timestamp, event_start, event_stop);
    printf("Processed in: %lf\n", timestamp);
    kernelTime = timestamp;

    // Copy output from GPU
    hipEventRecord(event_start, 0);
    ( hipMemcpy(output, d_output, nsamp * tdms * sizeof(float), hipMemcpyDeviceToHost) );    
    hipEventRecord(event_stop, 0);
    hipEventSynchronize(event_stop);
    hipEventElapsedTime(&timestamp, event_start, event_stop);
    printf("Copied from GPU in: %lf\n", timestamp);

    // Check values
    int val = 0;
    for(i = 0; i < nchans; i++) val += i;

 /*   for(i = 0; i < tdms; i++)
        for(j = 0; j < nsamp; j++)
            if (output[i * nsamp + j] != val)
                printf("Error: dm: %d nsamp: %d value:%f \n", i, j, output[i*nsamp+j]);

*/
    printf("Total time: %d\n", (int) (time(NULL) - start));
    printf("Performance: %lf Gflops\n", (nchans * tdms) * (nsamp * 1.0 / kernelTime / 1.0e6));
}


	.text
	.file	"brute_dedisp_imp.hip"
	.globl	_Z30__device_stub__dedisperse_loopPfS_iifffi # -- Begin function _Z30__device_stub__dedisperse_loopPfS_iifffi
	.type	_Z30__device_stub__dedisperse_loopPfS_iifffi,@function
_Z30__device_stub__dedisperse_loopPfS_iifffi: # @_Z30__device_stub__dedisperse_loopPfS_iifffi
	.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	$160, %rsp
	.cfi_def_cfa_offset 208
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	28(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	24(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	20(%rsp), %rcx
	movss	%xmm0, (%rcx)
	leaq	16(%rsp), %r9
	movss	%xmm1, (%r9)
	leaq	12(%rsp), %r10
	movss	%xmm2, (%r10)
	leaq	8(%rsp), %r11
	movl	%r8d, (%r11)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r9, 40(%rbx)
	movq	%r10, 48(%rbx)
	movq	%r11, 56(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	40(%rsp), %r12
	leaq	32(%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	$_Z15dedisperse_loopPfS_iifffi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$176, %rsp
	.cfi_adjust_cfa_offset -176
	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	_Z30__device_stub__dedisperse_loopPfS_iifffi, .Lfunc_end0-_Z30__device_stub__dedisperse_loopPfS_iifffi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z17process_argumentsiPPc
.LCPI1_0:
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.text
	.globl	_Z17process_argumentsiPPc
	.type	_Z17process_argumentsiPPc,@function
_Z17process_argumentsiPPc:              # @_Z17process_argumentsiPPc
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movl	%edi, %ebp
	xorl	%r15d, %r15d
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	movq	8(%rbx,%r15,8), %rdi
	movl	$.L.str, %esi
	callq	fopen
	incq	%r15
	testq	%rax, %rax
	jne	.LBB1_1
	jmp	.LBB1_2
.LBB1_3:                                # %.lr.ph
                                        #   in Loop: Header=BB1_2 Depth=1
	movslq	%r15d, %r12
	movq	(%rbx,%r12,8), %r14
	movl	$.L.str.1, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	je	.LBB1_4
# %bb.5:                                #   in Loop: Header=BB1_2 Depth=1
	movl	$.L.str.2, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	je	.LBB1_6
# %bb.7:                                #   in Loop: Header=BB1_2 Depth=1
	movl	$.L.str.3, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	je	.LBB1_8
# %bb.9:                                #   in Loop: Header=BB1_2 Depth=1
	movl	$.L.str.4, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	je	.LBB1_10
# %bb.11:                               #   in Loop: Header=BB1_2 Depth=1
	movl	$.L.str.5, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	je	.LBB1_12
# %bb.13:                               #   in Loop: Header=BB1_2 Depth=1
	movl	$.L.str.6, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	je	.LBB1_14
# %bb.15:                               #   in Loop: Header=BB1_2 Depth=1
	movl	$.L.str.7, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	je	.LBB1_16
# %bb.17:                               #   in Loop: Header=BB1_2 Depth=1
	movl	$.L.str.8, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	je	.LBB1_18
# %bb.19:                               #   in Loop: Header=BB1_2 Depth=1
	movl	$.L.str.9, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	jne	.LBB1_21
# %bb.20:                               #   in Loop: Header=BB1_2 Depth=1
	leal	1(%r12), %r15d
	movq	8(%rbx,%r12,8), %rdi
	callq	atof
	cvtsd2ss	%xmm0, %xmm0
	xorps	.LCPI1_0(%rip), %xmm0
	movss	%xmm0, foff(%rip)
	jmp	.LBB1_21
.LBB1_4:                                #   in Loop: Header=BB1_2 Depth=1
	leal	1(%r12), %r15d
	movq	8(%rbx,%r12,8), %rdi
	callq	atoi
	movl	%eax, nchans(%rip)
	jmp	.LBB1_21
.LBB1_6:                                #   in Loop: Header=BB1_2 Depth=1
	leal	1(%r12), %r15d
	movq	8(%rbx,%r12,8), %rdi
	callq	atoi
	movl	%eax, nsamp(%rip)
	jmp	.LBB1_21
.LBB1_8:                                #   in Loop: Header=BB1_2 Depth=1
	leal	1(%r12), %r15d
	movq	8(%rbx,%r12,8), %rdi
	callq	atof
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, dmstep(%rip)
	jmp	.LBB1_21
.LBB1_10:                               #   in Loop: Header=BB1_2 Depth=1
	leal	1(%r12), %r15d
	movq	8(%rbx,%r12,8), %rdi
	callq	atof
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, startdm(%rip)
	jmp	.LBB1_21
.LBB1_12:                               #   in Loop: Header=BB1_2 Depth=1
	leal	1(%r12), %r15d
	movq	8(%rbx,%r12,8), %rdi
	callq	atoi
	movl	%eax, tdms(%rip)
	jmp	.LBB1_21
.LBB1_14:                               #   in Loop: Header=BB1_2 Depth=1
	leal	1(%r12), %r15d
	movq	8(%rbx,%r12,8), %rdi
	callq	atoi
	movl	%eax, gridsize(%rip)
	jmp	.LBB1_21
.LBB1_16:                               #   in Loop: Header=BB1_2 Depth=1
	leal	1(%r12), %r15d
	movq	8(%rbx,%r12,8), %rdi
	callq	atoi
	movl	%eax, blocksize(%rip)
	jmp	.LBB1_21
.LBB1_18:                               #   in Loop: Header=BB1_2 Depth=1
	leal	1(%r12), %r15d
	movq	8(%rbx,%r12,8), %rdi
	callq	atof
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, tsamp(%rip)
.LBB1_21:                               #   in Loop: Header=BB1_2 Depth=1
	incl	%r15d
.LBB1_2:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	cmpl	%ebp, %r15d
	jl	.LBB1_3
# %bb.22:                               # %._crit_edge
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z17process_argumentsiPPc, .Lfunc_end1-_Z17process_argumentsiPPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z13generate_dataPfii           # -- Begin function _Z13generate_dataPfii
	.type	_Z13generate_dataPfii,@function
_Z13generate_dataPfii:                  # @_Z13generate_dataPfii
	.cfi_startproc
# %bb.0:
	imull	%edx, %esi
	testl	%esi, %esi
	jle	.LBB2_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%esi, %eax
	xorl	%ecx, %ecx
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$1036831949, (%rdi,%rcx,4)      # imm = 0x3DCCCCCD
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB2_2
.LBB2_3:                                # %._crit_edge
	retq
.Lfunc_end2:
	.size	_Z13generate_dataPfii, .Lfunc_end2-_Z13generate_dataPfii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z7dmdelayff
.LCPI3_0:
	.quad	0x3ff0000000000000              # double 1
.LCPI3_1:
	.quad	0x40b034bdd99029ae              # double 4148.7416009999997
	.text
	.globl	_Z7dmdelayff
	.type	_Z7dmdelayff,@function
_Z7dmdelayff:                           # @_Z7dmdelayff
	.cfi_startproc
# %bb.0:
	cvtss2sd	%xmm0, %xmm0
	movsd	.LCPI3_0(%rip), %xmm2           # xmm2 = mem[0],zero
	movapd	%xmm2, %xmm3
	divsd	%xmm0, %xmm3
	divsd	%xmm0, %xmm3
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	divsd	%xmm0, %xmm2
	divsd	%xmm0, %xmm2
	subsd	%xmm2, %xmm3
	mulsd	.LCPI3_1(%rip), %xmm3
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm3, %xmm0
	retq
.Lfunc_end3:
	.size	_Z7dmdelayff, .Lfunc_end3-_Z7dmdelayff
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI4_0:
	.quad	0x3ff0000000000000              # double 1
.LCPI4_1:
	.quad	0x40b034bdd99029ae              # double 4148.7416009999997
.LCPI4_2:
	.quad	0x412e848000000000              # double 1.0E+6
	.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	$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
	callq	_Z17process_argumentsiPPc
	movslq	nchans(%rip), %rbx
	leaq	(,%rbx,4), %rdi
	callq	malloc
	movq	%rax, %r15
	movl	%ebx, %r13d
	testq	%rbx, %rbx
	movq	%rbx, 48(%rsp)                  # 8-byte Spill
	je	.LBB4_1
# %bb.12:                               # %.lr.ph
	movss	fch1(%rip), %xmm0               # xmm0 = mem[0],zero,zero,zero
	movss	foff(%rip), %xmm1               # xmm1 = mem[0],zero,zero,zero
	cvtss2sd	%xmm0, %xmm4
	movsd	.LCPI4_0(%rip), %xmm2           # xmm2 = mem[0],zero
	movapd	%xmm2, %xmm3
	divsd	%xmm4, %xmm3
	divsd	%xmm4, %xmm3
	xorl	%eax, %eax
	movsd	.LCPI4_1(%rip), %xmm4           # xmm4 = mem[0],zero
.LBB4_13:                               # =>This Inner Loop Header: Depth=1
	movl	%eax, %ecx
	xorps	%xmm5, %xmm5
	cvtsi2ss	%rcx, %xmm5
	mulss	%xmm1, %xmm5
	addss	%xmm0, %xmm5
	cvtss2sd	%xmm5, %xmm5
	movapd	%xmm2, %xmm6
	divsd	%xmm5, %xmm6
	divsd	%xmm5, %xmm6
	subsd	%xmm3, %xmm6
	mulsd	%xmm4, %xmm6
	xorps	%xmm5, %xmm5
	cvtsd2ss	%xmm6, %xmm5
	movss	%xmm5, (%r15,%rax,4)
	incq	%rax
	cmpq	%rax, %r13
	jne	.LBB4_13
# %bb.2:                                # %._crit_edge.loopexit
	movss	-4(%r15,%rbx,4), %xmm1          # xmm1 = mem[0],zero,zero,zero
	jmp	.LBB4_3
.LBB4_1:
                                        # implicit-def: $xmm1
.LBB4_3:                                # %._crit_edge
	movl	tdms(%rip), %r14d
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r14d, %xmm0
	mulss	dmstep(%rip), %xmm0
	addss	startdm(%rip), %xmm0
	mulss	%xmm1, %xmm0
	divss	tsamp(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %eax
	movl	nsamp(%rip), %ebx
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	leal	(%rbx,%rax), %ebp
	movl	%ebp, %eax
	imull	%r13d, %eax
	movslq	%eax, %rdi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, %r12
	imull	%r14d, %ebx
	movslq	%ebx, %rdi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	testl	%r13d, %r13d
	jle	.LBB4_9
# %bb.4:                                # %.preheader.lr.ph
	movl	48(%rsp), %eax                  # 4-byte Reload
	movl	%ebp, %ecx
	xorl	%edx, %edx
	xorl	%esi, %esi
.LBB4_5:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_7 Depth 2
	testl	%ebp, %ebp
	jle	.LBB4_8
# %bb.6:                                # %.lr.ph44
                                        #   in Loop: Header=BB4_5 Depth=1
	movl	%edx, %edi
	leaq	(%r12,%rdi,4), %rdi
	xorps	%xmm0, %xmm0
	cvtsi2ss	%esi, %xmm0
	xorl	%r8d, %r8d
.LBB4_7:                                #   Parent Loop BB4_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	%xmm0, (%rdi,%r8,4)
	incq	%r8
	cmpq	%r8, %rcx
	jne	.LBB4_7
.LBB4_8:                                # %._crit_edge45
                                        #   in Loop: Header=BB4_5 Depth=1
	incq	%rsi
	addl	%ebp, %edx
	cmpq	%rax, %rsi
	jne	.LBB4_5
.LBB4_9:                                # %._crit_edge47
	movl	$1, %edi
	callq	hipSetDevice
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	movl	nsamp(%rip), %esi
	xorps	%xmm0, %xmm0
	cvtss2sd	tsamp(%rip), %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	startdm(%rip), %xmm1
	movl	nchans(%rip), %edx
	xorps	%xmm2, %xmm2
	cvtss2sd	dmstep(%rip), %xmm2
	movl	tdms(%rip), %ecx
	xorps	%xmm3, %xmm3
	cvtss2sd	fch1(%rip), %xmm3
	xorps	%xmm4, %xmm4
	cvtss2sd	foff(%rip), %xmm4
	movl	$.L.str.10, %edi
	movq	24(%rsp), %rbp                  # 8-byte Reload
	movl	%ebp, %r8d
	movb	$5, %al
	callq	printf
	movslq	nsamp(%rip), %rax
	movslq	%ebp, %r14
	addq	%r14, %rax
	movslq	nchans(%rip), %rsi
	imulq	%rax, %rsi
	shlq	$2, %rsi
	leaq	64(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipMalloc
	movslq	nsamp(%rip), %rax
	movslq	tdms(%rip), %rsi
	imulq	%rax, %rsi
	shlq	$2, %rsi
	leaq	40(%rsp), %r13
	movq	%r13, %rdi
	callq	hipMalloc
	movq	(%r13), %rdi
	movslq	nsamp(%rip), %rax
	movslq	tdms(%rip), %rdx
	imulq	%rax, %rdx
	shlq	$2, %rdx
	xorl	%esi, %esi
	callq	hipMemset
	movslq	nchans(%rip), %rdx
	shlq	$2, %rdx
	movl	$dm_shifts, %edi
	movq	%r15, %rsi
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	xorl	%edi, %edi
	callq	time
	movq	%rax, %r15
	leaq	16(%rsp), %r13
	movq	(%r13), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rbx), %rdi
	movslq	nsamp(%rip), %rax
	addq	%r14, %rax
	movslq	nchans(%rip), %rdx
	imulq	%rax, %rdx
	shlq	$2, %rdx
	movq	%r12, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	8(%rsp), %rbx
	movq	(%rbx), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rbx), %rdi
	callq	hipEventSynchronize
	movq	(%r13), %rsi
	movq	(%rbx), %rdx
	leaq	36(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.11, %edi
	movb	$1, %al
	callq	printf
	movl	nsamp(%rip), %eax
	cltd
	idivl	blocksize(%rip)
                                        # kill: def $eax killed $eax def $rax
	movl	tdms(%rip), %ebx
	shlq	$32, %rbx
	orq	%rax, %rbx
	movq	(%r13), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	blocksize(%rip), %edx
	btsq	$32, %rdx
	movl	$512, %r8d                      # imm = 0x200
	movq	%rbx, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_11
# %bb.10:
	movq	40(%rsp), %rdi
	movq	64(%rsp), %rsi
	movl	nsamp(%rip), %edx
	movl	nchans(%rip), %ecx
	movss	tsamp(%rip), %xmm0              # xmm0 = mem[0],zero,zero,zero
	movss	startdm(%rip), %xmm1            # xmm1 = mem[0],zero,zero,zero
	movss	dmstep(%rip), %xmm2             # xmm2 = mem[0],zero,zero,zero
	movl	%ebp, %r8d
	callq	_Z30__device_stub__dedisperse_loopPfS_iifffi
.LBB4_11:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	leaq	36(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.12, %edi
	movb	$1, %al
	callq	printf
	movq	16(%rsp), %rdi
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx), %xmm0
	movsd	%xmm0, 24(%rsp)                 # 8-byte Spill
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	40(%rsp), %rsi
	movslq	nsamp(%rip), %rax
	movslq	tdms(%rip), %rdx
	imulq	%rax, %rdx
	shlq	$2, %rdx
	movq	56(%rsp), %rdi                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.13, %edi
	movb	$1, %al
	callq	printf
	xorl	%edi, %edi
	callq	time
	subl	%r15d, %eax
	movl	$.L.str.14, %edi
	movl	%eax, %esi
	xorl	%eax, %eax
	callq	printf
	movl	tdms(%rip), %eax
	imull	nchans(%rip), %eax
	xorps	%xmm1, %xmm1
	cvtsi2sd	%eax, %xmm1
	xorps	%xmm0, %xmm0
	cvtsi2sdl	nsamp(%rip), %xmm0
	divsd	24(%rsp), %xmm0                 # 8-byte Folded Reload
	divsd	.LCPI4_2(%rip), %xmm0
	mulsd	%xmm1, %xmm0
	movl	$.L.str.15, %edi
	movb	$1, %al
	callq	printf
	xorl	%eax, %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
.Lfunc_end4:
	.size	main, .Lfunc_end4-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	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z15dedisperse_loopPfS_iifffi, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$0, 8(%rsp)
	movl	$1, (%rsp)
	movl	$dm_shifts, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movl	$16384, %r9d                    # imm = 0x4000
	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_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__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	.LBB6_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
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	dm_shifts,@object               # @dm_shifts
	.local	dm_shifts
	.comm	dm_shifts,16384,16
	.type	_Z15dedisperse_loopPfS_iifffi,@object # @_Z15dedisperse_loopPfS_iifffi
	.section	.rodata,"a",@progbits
	.globl	_Z15dedisperse_loopPfS_iifffi
	.p2align	3, 0x0
_Z15dedisperse_loopPfS_iifffi:
	.quad	_Z30__device_stub__dedisperse_loopPfS_iifffi
	.size	_Z15dedisperse_loopPfS_iifffi, 8

	.type	fch1,@object                    # @fch1
	.data
	.globl	fch1
	.p2align	2, 0x0
fch1:
	.long	0x431c0000                      # float 156
	.size	fch1, 4

	.type	foff,@object                    # @foff
	.globl	foff
	.p2align	2, 0x0
foff:
	.long	0xbbc00000                      # float -0.005859375
	.size	foff, 4

	.type	tsamp,@object                   # @tsamp
	.globl	tsamp
	.p2align	2, 0x0
tsamp:
	.long	0x392d03da                      # float 1.65000005E-4
	.size	tsamp, 4

	.type	dmstep,@object                  # @dmstep
	.globl	dmstep
	.p2align	2, 0x0
dmstep:
	.long	0x3ca3d70a                      # float 0.0199999996
	.size	dmstep, 4

	.type	startdm,@object                 # @startdm
	.bss
	.globl	startdm
	.p2align	2, 0x0
startdm:
	.long	0x00000000                      # float 0
	.size	startdm, 4

	.type	nchans,@object                  # @nchans
	.data
	.globl	nchans
	.p2align	2, 0x0
nchans:
	.long	1024                            # 0x400
	.size	nchans, 4

	.type	nsamp,@object                   # @nsamp
	.globl	nsamp
	.p2align	2, 0x0
nsamp:
	.long	1024                            # 0x400
	.size	nsamp, 4

	.type	tdms,@object                    # @tdms
	.globl	tdms
	.p2align	2, 0x0
tdms:
	.long	1024                            # 0x400
	.size	tdms, 4

	.type	gridsize,@object                # @gridsize
	.globl	gridsize
	.p2align	2, 0x0
gridsize:
	.long	128                             # 0x80
	.size	gridsize, 4

	.type	blocksize,@object               # @blocksize
	.globl	blocksize
	.p2align	2, 0x0
blocksize:
	.long	128                             # 0x80
	.size	blocksize, 4

	.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	"-nchans"
	.size	.L.str.1, 8

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"-nsamp"
	.size	.L.str.2, 7

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"-dmstep"
	.size	.L.str.3, 8

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"-startdm"
	.size	.L.str.4, 9

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"-tdms"
	.size	.L.str.5, 6

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"-gridsize"
	.size	.L.str.6, 10

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"-blocksize"
	.size	.L.str.7, 11

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"-tsamp"
	.size	.L.str.8, 7

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"-foff"
	.size	.L.str.9, 6

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"nsamp: %d, nchans: %d, tsamp: %f, startdm: %f, dmstep: %f, tdms: %d, fch1: %f, foff: %f, maxshift: %d\n"
	.size	.L.str.10, 103

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Copied to GPU in: %lf\n"
	.size	.L.str.11, 23

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Processed in: %lf\n"
	.size	.L.str.12, 19

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"Copied from GPU in: %lf\n"
	.size	.L.str.13, 25

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"Total time: %d\n"
	.size	.L.str.14, 16

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"Performance: %lf Gflops\n"
	.size	.L.str.15, 25

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z15dedisperse_loopPfS_iifffi"
	.size	.L__unnamed_1, 30

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"dm_shifts"
	.size	.L__unnamed_2, 10

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

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

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z30__device_stub__dedisperse_loopPfS_iifffi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym dm_shifts
	.addrsig_sym _Z15dedisperse_loopPfS_iifffi
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z15dedisperse_loopPfS_iifffi ; -- Begin function _Z15dedisperse_loopPfS_iifffi
	.globl	_Z15dedisperse_loopPfS_iifffi
	.p2align	8
	.type	_Z15dedisperse_loopPfS_iifffi,@function
_Z15dedisperse_loopPfS_iifffi:          ; @_Z15dedisperse_loopPfS_iifffi
; %bb.0:
	s_clause 0x1
	s_load_b32 s8, s[0:1], 0x34
	s_load_b128 s[4:7], s[0:1], 0x10
	s_add_u32 s2, s0, 40
	s_addc_u32 s3, s1, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s12, s8, 0xffff
	s_mov_b32 s8, exec_lo
	v_mad_u64_u32 v[1:2], null, s14, s12, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s4, v1
	s_cbranch_execz .LBB0_7
; %bb.1:                                ; %.lr.ph26
	s_clause 0x1
	s_load_b64 s[16:17], s[0:1], 0x20
	s_load_b128 s[8:11], s[0:1], 0x0
	v_cvt_f32_u32_e32 v2, s15
	s_cmp_gt_i32 s5, 0
	s_mul_i32 s15, s15, s4
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_fma_f32 v2, v2, s16, s7
	s_load_b32 s7, s[2:3], 0x0
	s_mov_b32 s2, 0
	s_cselect_b32 s3, -1, 0
	v_div_scale_f32 v3, null, s6, s6, v2
	v_div_scale_f32 v6, vcc_lo, v2, s6, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v4, v3
	s_waitcnt_depctr 0xfff
	v_fma_f32 v5, -v3, v4, 1.0
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s7, s7, s12
	v_fmac_f32_e32 v4, v5, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v5, v6, v4
	v_fma_f32 v7, -v3, v5, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v5, v7, v4
	v_fma_f32 v3, -v3, v5, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f32 v3, v3, v4, v5
	v_div_fixup_f32 v4, v3, s6, v2
	v_mov_b32_e32 v3, 0
	s_add_i32 s6, s17, s4
.LBB0_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_4 Depth 2
	v_mov_b32_e32 v5, 0
	s_and_not1_b32 vcc_lo, exec_lo, s3
	s_cbranch_vccnz .LBB0_5
; %bb.3:                                ; %.lr.ph.preheader
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_mov_b32_e32 v5, 0
	s_mov_b32 s12, 0
	s_mov_b32 s13, s5
	s_getpc_b64 s[0:1]
	s_add_u32 s0, s0, dm_shifts@rel32@lo+4
	s_addc_u32 s1, s1, dm_shifts@rel32@hi+12
.LBB0_4:                                ; %.lr.ph
                                        ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_load_b32 s14, s[0:1], 0x0
	v_cvt_f32_i32_e32 v6, s12
	s_add_i32 s13, s13, -1
	s_add_i32 s12, s12, s6
	s_add_u32 s0, s0, 4
	s_addc_u32 s1, s1, 0
	s_cmp_lg_u32 s13, 0
	s_waitcnt lgkmcnt(0)
	v_mul_f32_e32 v2, s14, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_floor_f32_e32 v2, v2
	v_add_f32_e32 v2, v2, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_i32_f32_e32 v2, v2
	v_add_nc_u32_e32 v6, v1, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v7, 31, v6
	v_lshlrev_b64 v[6:7], 2, v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v6, vcc_lo, s10, v6
	v_add_co_ci_u32_e32 v7, vcc_lo, s11, v7, vcc_lo
	global_load_b32 v2, v[6:7], off
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v5, v2, v5
	s_cbranch_scc1 .LBB0_4
.LBB0_5:                                ; %._crit_edge
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_add_nc_u32_e32 v2, s15, v1
	v_add_nc_u32_e32 v1, s7, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[6:7], 2, v[2:3]
	v_cmp_le_i32_e32 vcc_lo, s4, v1
	s_or_b32 s2, vcc_lo, s2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v6, s0, s8, v6
	v_add_co_ci_u32_e64 v7, s0, s9, v7, s0
	global_store_b32 v[6:7], v5, off
	s_and_not1_b32 exec_lo, exec_lo, s2
	s_cbranch_execnz .LBB0_2
; %bb.6:                                ; %._crit_edge27
	s_or_b32 exec_lo, exec_lo, s2
	v_lshl_add_u32 v0, v0, 2, 0
	ds_store_b32 v0, v5
.LBB0_7:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z15dedisperse_loopPfS_iifffi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 8
		.amdhsa_next_free_sgpr 18
		.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	_Z15dedisperse_loopPfS_iifffi, .Lfunc_end0-_Z15dedisperse_loopPfS_iifffi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 496
; NumSgprs: 20
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 20
; NumVGPRsForWavesPerEU: 8
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.protected	dm_shifts               ; @dm_shifts
	.type	dm_shifts,@object
	.section	.bss,"aw",@nobits
	.globl	dm_shifts
	.p2align	4, 0x0
dm_shifts:
	.zero	16384
	.size	dm_shifts, 16384

	.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 dm_shifts
	.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:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         36
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         160
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z15dedisperse_loopPfS_iifffi
    .private_segment_fixed_size: 0
    .sgpr_count:     20
    .sgpr_spill_count: 0
    .symbol:         _Z15dedisperse_loopPfS_iifffi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
