/*********************************************************
*  DESCRIPTION:                                          *
*    Serial Concurrent Wave Equation - C Version         *
*    This program implements the concurrent wave equation*
**********************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>

#define MAXPOINTS 1000000
#define MINPOINTS 20
#define MAXSTEPS 1000000
#define PI 3.14159265

void check_param(void);
void init_line(void);
void update(void);
void printfinal(void);

int nsteps, /*number of time steps*/
    tpoints, /*total points along string*/
    rcode; /*generic return code*/

float values[MAXPOINTS + 2], /*values at time t*/
      oldval[MAXPOINTS + 2], /*values at time (t-dt)*/
      newval[MAXPOINTS + 2]; /*values at time (t+dt)*/
float v[MAXPOINTS + 2], /*serial used for comparing answers with parallel*/
      o[MAXPOINTS + 2],
      n[MAXPOINTS + 2];

/*********************************************************
*  Check input values from parameters                    *
**********************************************************/
void check_param(void){
    char tchar[20];
	
    /*check number of points, number of iterations*/
    while((tpoints < MINPOINTS) || (tpoints > MAXPOINTS)){
        printf("Enter number of points along vibrating string [%d-%d]: ");
        scanf("%s", tchar);
	tpoints = atoi(tchar);
	if((tpoints < MINPOINTS) || (tpoints > MAXPOINTS)){
            printf("Invalid. Please enter value between %d and %d\n", MINPOINTS, MAXPOINTS);
	}
    }
    while((nsteps < 1) || (nsteps > MAXSTEPS)){
	printf("Enter number of time steps [1-%d]: ", MAXSTEPS);
	scanf("%s", tchar);
	nsteps = atoi(tchar);
	if((nsteps < 1) || (nsteps > MAXSTEPS)){
            printf("Invalid. Please enter value between 1 and %d\n", MAXSTEPS);
	}
    }
	
    printf("Using points = %d, steps = %d\n", tpoints, nsteps);
}

/*********************************************************
*  Initialize points on line                             *
**********************************************************/
void init_line(void){
    int i, j;
    float x, fac, k, tmp;
	
    /*Calculate initial values based on sine curve*/
    fac = 2.0 * PI;
    k = 0.0;
    tmp = tpoints - 1;
    for(j = 1; j <= tpoints; j++){
	x = k/tmp;
	values[j] = sin(fac * x);
        v[j] = values[j];
	k = k + 1.0;
    }
	
    /*Initialize old values array*/
    for(i = 1; i <= tpoints; i++){
	oldval[i] = values[i];
        o[i] = v[i];
    }
}

/*********************************************************
*  Calculate new values using wave equation              *
**********************************************************/
__global__ void do_math_kernel(float *val_d, float *old_d, float *new_d, int num_of_steps, int num_of_points){
    float dtime, c, dx, tau, sqtau;
	
    dtime = 0.3;
    c = 1.0;
    dx = 1.0;
    tau = (c * dtime / dx);
    sqtau = tau * tau;

    __shared__ float val_ds[1024];
    __shared__ float old_ds[1024];
    __shared__ float new_ds[1024];
    int tx = threadIdx.x;
    int index = blockIdx.x * blockDim.x + threadIdx.x;
    
    val_ds[tx] = val_d[index];
    old_ds[tx] = old_d[index];

    for(int i = 1; i <= num_of_steps; i++){
        /*This part needs to access elements from global memory of GPU*/
        /*if(index == 0 || index == num_of_points - 1) new_d[index] = 0.0;
        else new_d[index] = (2.0 * val_d[index]) - old_d[index] + (sqtau * (-2.0) * val_d[index]);
        old_d[index] = val_d[index];
        val_d[index] = new_d[index];*/
        /*This part accesses elements from shared memory of GPU -> faster*/
        /*if(index == 0 || index == num_of_points - 1) new_ds[tx] = 0.0;
        else new_ds[tx] = (2.0 * val_ds[tx]) - old_ds[tx] + (sqtau * (-2.0) * val_ds[tx]);
        old_ds[tx] = val_ds[tx];
        val_ds[tx] = new_ds[tx];*/
        /*This part only takes values[2~tpoints-1] total tpoins-2 points from CPU to GPU in order to reduce branch overhead*/ 
        new_ds[tx] = (2.0 * val_ds[tx]) - old_ds[tx] + (sqtau * (-2.0) * val_ds[tx]);
        old_ds[tx] = val_ds[tx];
        val_ds[tx] = new_ds[tx];
        
    }
    __syncthreads();
    val_d[index] = val_ds[tx];
    
}

void do_math(int i){
    float dtime, c, dx, tau, sqtau;
	
    dtime = 0.3;
    c = 1.0;
    dx = 1.0;
    tau = (c * dtime / dx);
    sqtau = tau * tau;
    newval[i] = (2.0 * values[i]) - oldval[i] + (sqtau * (-2.0) * values[i]);
    //n[i] = (2.0 * v[i]) - o[i] + (sqtau * (-2.0) * v[i]);
}

/***********************************************************
*  Update all values along line a specified number of times*
***********************************************************/
void updateOnDevice(){
    //int size = tpoints * sizeof(float);
    int size = (tpoints - 2) * sizeof(float);
    float *val_d, *old_d, *new_d; //memory on device

    /*1.Allocate device memory and move initiail values[] and oldval[] to GPU*/
    cudaMalloc(&val_d, size);
    //cudaMemcpy(val_d, values+1, size, cudaMemcpyHostToDevice);
    cudaMemcpy(val_d, values+2, size, cudaMemcpyHostToDevice);
    cudaMalloc(&old_d, size);
    //cudaMemcpy(old_d, oldval+1, size, cudaMemcpyHostToDevice);
    cudaMemcpy(old_d, oldval+2, size, cudaMemcpyHostToDevice);
    cudaMalloc(&new_d, size);
	
    /*2.Invoke kernel function, each thread calculates a value[] element*/
    int threads_per_block, blocks_per_grid = tpoints/1024 + 1;
    if(tpoints > 1024) threads_per_block = 1024;
    else threads_per_block = tpoints;
    dim3 dimBlock(threads_per_block); 
    dim3 dimGrid(blocks_per_grid);
    do_math_kernel<<<dimGrid,dimBlock>>>(val_d, old_d, new_d, nsteps, tpoints);

    /*3.Read final results from GPU to CPU*/
    //cudaMemcpy(values+1, val_d, size, cudaMemcpyDeviceToHost);
    cudaMemcpy(values+2, val_d, size, cudaMemcpyDeviceToHost);
    cudaFree(val_d); cudaFree(old_d); cudaFree(new_d);
}

void update(){
    int i, j;
	
    /*Update values for each time step*/
    for(i = 1; i <= nsteps; i++){
        /*Update points along line for this time step*/
        for(j = 1; j <= tpoints; j++){
	    /*global endpoints*/
            if((j == 1) || (j == tpoints)){
                newval[j] = 0.0;
                //n[j] = 0.0;
            }
	    else do_math(j);
	}
        /*Update old values with new values*/
        for(j = 1; j <= tpoints; j++){
	    oldval[j] = values[j];
	    values[j] = newval[j];
            /*o[j] = v[j];
            v[j] = n[j];*/
        }
    }
	
}

/**********************************************************
*  Print final results                                    *
**********************************************************/
void printfinal(){
    int i;

    for(i = 1; i <= tpoints; i++){
	printf("%6.4f ", values[i]);
	if(i%10 == 0) printf("\n");
    }	
}

/**********************************************************
*  Check serial and parallel answers                      *
**********************************************************/
void check_answer(){
    int wrong = 0, num = 0;
    for(int i = 1; i <= tpoints; i++){
        if(values[i]!=v[i]){
            wrong = 1;
            num++;
        }
    }
    if(wrong == 0) printf("right\n");
    else printf("%d are wrong\n", num);
    /*In command line ./ cuda_wave.out > [filename] to pipe output to the file
      then use diff file1 file2 to see if there is any difference*/
}

/*********************************************************
*  Main Program                                          *
**********************************************************/
int main(int argc, char *argv[]){
    sscanf(argv[1], "%d", &tpoints);
    sscanf(argv[2], "%d", &nsteps);
	
    check_param();
	
    printf("Initializing points on the line...\n");
    init_line();
    //printfinal();
	
    printf("Updating all points for all time steps...\n");
    //update();
    updateOnDevice();
	
    printf("Printing final results...\n");
    printfinal();
    printf("\nDone.\n\n");
	
    return 0;
}	  

	.file	"tmpxft_0035d313_00000000-6_wave.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2037:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2037:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Enter number of points along vibrating string [%d-%d]: "
.LC1:
	.string	"%s"
.LC2:
	.string	"Invalid. Please enter value between %d and %d\n"
.LC3:
	.string	"Enter number of time steps [1-%d]: "
.LC4:
	.string	"Invalid. Please enter value between 1 and %d\n"
.LC5:
	.string	"Using points = %d, steps = %d\n"
	.text
	.globl	_Z11check_paramv
	.type	_Z11check_paramv, @function
_Z11check_paramv:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC0(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	subq	$40, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
.L4:
	movl	tpoints(%rip), %eax
	subl	$20, %eax
	cmpl	$999980, %eax
	jbe	.L14
	movq	%rbp, %rsi
	movl	$2, %edi
	leaq	4(%rsp), %rbx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbx, %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	movq	%rbx, %rdi
	call	atoi@PLT
	movl	%eax, tpoints(%rip)
	subl	$20, %eax
	cmpl	$999980, %eax
	jbe	.L4
	movl	$1000000, %ecx
	movl	$20, %edx
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L4
.L14:
	leaq	.LC3(%rip), %rbp
.L7:
	movl	nsteps(%rip), %ecx
	leal	-1(%rcx), %eax
	cmpl	$999999, %eax
	jbe	.L15
	movl	$1000000, %edx
	movq	%rbp, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	4(%rsp), %rbx
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	movq	%rbx, %rsi
	call	__isoc23_scanf@PLT
	movq	%rbx, %rdi
	call	atoi@PLT
	movl	%eax, nsteps(%rip)
	decl	%eax
	cmpl	$999999, %eax
	jbe	.L7
	movl	$1000000, %edx
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L7
.L15:
	movl	tpoints(%rip), %edx
	xorl	%eax, %eax
	movl	$2, %edi
	leaq	.LC5(%rip), %rsi
	call	__printf_chk@PLT
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	addq	$40, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z11check_paramv, .-_Z11check_paramv
	.globl	_Z9init_linev
	.type	_Z9init_linev, @function
_Z9init_linev:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	xorps	%xmm1, %xmm1
	leaq	v(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	leaq	values(%rip), %r12
	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
	movl	tpoints(%rip), %ebp
	leal	-1(%rbp), %eax
	cvtsi2ssl	%eax, %xmm2
	movss	%xmm2, 8(%rsp)
.L17:
	incq	%rbx
	cmpl	%ebx, %ebp
	jl	.L22
	movaps	%xmm1, %xmm0
	divss	8(%rsp), %xmm0
	movss	%xmm1, 12(%rsp)
	mulss	.LC7(%rip), %xmm0
	call	sinf@PLT
	movss	12(%rsp), %xmm1
	addss	.LC8(%rip), %xmm1
	movss	%xmm0, (%r12,%rbx,4)
	movss	%xmm0, 0(%r13,%rbx,4)
	jmp	.L17
.L22:
	xorl	%eax, %eax
	leaq	oldval(%rip), %rdx
	leaq	values(%rip), %rcx
	leaq	o(%rip), %rsi
	leaq	v(%rip), %rdi
.L19:
	incq	%rax
	cmpl	%eax, %ebp
	jl	.L23
	movss	(%rcx,%rax,4), %xmm0
	movss	%xmm0, (%rdx,%rax,4)
	movss	(%rdi,%rax,4), %xmm0
	movss	%xmm0, (%rsi,%rax,4)
	jmp	.L19
.L23:
	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
.LFE2028:
	.size	_Z9init_linev, .-_Z9init_linev
	.globl	_Z7do_mathi
	.type	_Z7do_mathi, @function
_Z7do_mathi:
.LFB2029:
	.cfi_startproc
	endbr64
	movslq	%edi, %rdi
	leaq	values(%rip), %rax
	cvtss2sd	(%rax,%rdi,4), %xmm1
	movaps	%xmm1, %xmm0
	leaq	oldval(%rip), %rax
	addsd	%xmm1, %xmm0
	mulsd	.LC9(%rip), %xmm1
	cvtss2sd	(%rax,%rdi,4), %xmm2
	leaq	newval(%rip), %rax
	subsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%rax,%rdi,4)
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z7do_mathi, .-_Z7do_mathi
	.globl	_Z6updatev
	.type	_Z6updatev, @function
_Z6updatev:
.LFB2031:
	.cfi_startproc
	endbr64
	movl	$1, %ecx
	leaq	newval(%rip), %r8
.L26:
	cmpl	%ecx, nsteps(%rip)
	jl	.L36
	movl	$1, %edx
.L33:
	movl	tpoints(%rip), %esi
	movl	%edx, %edi
	cmpl	%edx, %esi
	jl	.L37
	cmpl	$1, %edx
	je	.L35
	cmpl	%edi, %esi
	jne	.L27
.L35:
	movl	$0x00000000, (%r8,%rdx,4)
	jmp	.L29
.L27:
	call	_Z7do_mathi
.L29:
	incq	%rdx
	jmp	.L33
.L37:
	xorl	%eax, %eax
	leaq	oldval(%rip), %rdi
	leaq	values(%rip), %rdx
.L31:
	incq	%rax
	cmpl	%eax, %esi
	jl	.L38
	movss	(%rdx,%rax,4), %xmm0
	movss	%xmm0, (%rdi,%rax,4)
	movss	(%r8,%rax,4), %xmm0
	movss	%xmm0, (%rdx,%rax,4)
	jmp	.L31
.L38:
	incl	%ecx
	jmp	.L26
.L36:
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z6updatev, .-_Z6updatev
	.section	.rodata.str1.1
.LC10:
	.string	"%6.4f "
.LC11:
	.string	"\n"
	.text
	.globl	_Z10printfinalv
	.type	_Z10printfinalv, @function
_Z10printfinalv:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	values(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	$1, %ebx
.L40:
	cmpl	%ebx, tpoints(%rip)
	movl	%ebx, %ebp
	jl	.L44
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	(%r12,%rbx,4), %xmm0
	call	__printf_chk@PLT
	movl	%ebp, %eax
	movl	$10, %ecx
	cltd
	idivl	%ecx
	testl	%edx, %edx
	jne	.L41
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L41:
	incq	%rbx
	jmp	.L40
.L44:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z10printfinalv, .-_Z10printfinalv
	.section	.rodata.str1.1
.LC12:
	.string	"right\n"
.LC13:
	.string	"%d are wrong\n"
	.text
	.globl	_Z12check_answerv
	.type	_Z12check_answerv, @function
_Z12check_answerv:
.LFB2033:
	.cfi_startproc
	endbr64
	movl	tpoints(%rip), %esi
	movl	$1, %eax
	xorl	%edx, %edx
	xorl	%ecx, %ecx
	leaq	values(%rip), %rdi
	leaq	v(%rip), %r8
.L46:
	cmpl	%eax, %esi
	jl	.L52
	movss	(%rdi,%rax,4), %xmm0
	ucomiss	(%r8,%rax,4), %xmm0
	jp	.L51
	je	.L47
.L51:
	incl	%edx
	movl	$1, %ecx
.L47:
	incq	%rax
	jmp	.L46
.L52:
	testl	%ecx, %ecx
	jne	.L50
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	jmp	__printf_chk@PLT
.L50:
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2033:
	.size	_Z12check_answerv, .-_Z12check_answerv
	.globl	_Z40__device_stub__Z14do_math_kernelPfS_S_iiPfS_S_ii
	.type	_Z40__device_stub__Z14do_math_kernelPfS_S_iiPfS_S_ii, @function
_Z40__device_stub__Z14do_math_kernelPfS_S_iiPfS_S_ii:
.LFB2059:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	40(%rsp), %rcx
	movl	%r8d, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L53
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z14do_math_kernelPfS_S_ii(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L53:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L55
	call	__stack_chk_fail@PLT
.L55:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2059:
	.size	_Z40__device_stub__Z14do_math_kernelPfS_S_iiPfS_S_ii, .-_Z40__device_stub__Z14do_math_kernelPfS_S_iiPfS_S_ii
	.globl	_Z14do_math_kernelPfS_S_ii
	.type	_Z14do_math_kernelPfS_S_ii, @function
_Z14do_math_kernelPfS_S_ii:
.LFB2060:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z14do_math_kernelPfS_S_iiPfS_S_ii
	.cfi_endproc
.LFE2060:
	.size	_Z14do_math_kernelPfS_S_ii, .-_Z14do_math_kernelPfS_S_ii
	.globl	_Z14updateOnDevicev
	.type	_Z14updateOnDevicev, @function
_Z14updateOnDevicev:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	8+values(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	subq	$72, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	movl	tpoints(%rip), %eax
	leaq	8(%rsp), %rdi
	leal	-8(,%rax,4), %ebx
	movslq	%ebx, %rbx
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%rbp, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	leaq	16(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdi
	movq	%rbx, %rdx
	movl	$1, %ecx
	leaq	8+oldval(%rip), %rsi
	call	cudaMemcpy@PLT
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movl	tpoints(%rip), %eax
	movl	$1024, %edx
	movl	$1024, %esi
	movabsq	$4294967297, %rcx
	cmpl	%edx, %eax
	movq	%rcx, 48(%rsp)
	cmovle	%eax, %edx
	movq	%rcx, 36(%rsp)
	movl	40(%rsp), %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	%edx, 32(%rsp)
	cltd
	idivl	%esi
	movq	32(%rsp), %rdx
	movl	52(%rsp), %esi
	incl	%eax
	movl	%eax, 44(%rsp)
	movq	44(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L59
	movl	tpoints(%rip), %r8d
	movl	nsteps(%rip), %ecx
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdi
	call	_Z40__device_stub__Z14do_math_kernelPfS_S_iiPfS_S_ii
.L59:
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdx
	movq	%rbp, %rdi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L60
	call	__stack_chk_fail@PLT
.L60:
	addq	$72, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z14updateOnDevicev, .-_Z14updateOnDevicev
	.section	.rodata.str1.1
.LC14:
	.string	"%d"
.LC15:
	.string	"Initializing points on the line...\n"
.LC16:
	.string	"Updating all points for all time steps...\n"
.LC17:
	.string	"Printing final results...\n"
.LC18:
	.string	"\nDone.\n\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2034:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC14(%rip), %rbp
	leaq	tpoints(%rip), %rdx
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rsi, %rbx
	pushq	%rax
	.cfi_def_cfa_offset 32
	movq	8(%rsi), %rdi
	xorl	%eax, %eax
	movq	%rbp, %rsi
	call	__isoc23_sscanf@PLT
	movq	16(%rbx), %rdi
	movq	%rbp, %rsi
	xorl	%eax, %eax
	leaq	nsteps(%rip), %rdx
	call	__isoc23_sscanf@PLT
	call	_Z11check_paramv
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	call	_Z9init_linev
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	call	_Z14updateOnDevicev
	leaq	.LC17(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	call	_Z10printfinalv
	leaq	.LC18(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	popq	%rdx
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2034:
	.size	main, .-main
	.section	.rodata.str1.1
.LC19:
	.string	"_Z14do_math_kernelPfS_S_ii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2062:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC19(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z14do_math_kernelPfS_S_ii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2062:
	.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	n
	.bss
	.align 32
	.type	n, @object
	.size	n, 4000008
n:
	.zero	4000008
	.globl	o
	.align 32
	.type	o, @object
	.size	o, 4000008
o:
	.zero	4000008
	.globl	v
	.align 32
	.type	v, @object
	.size	v, 4000008
v:
	.zero	4000008
	.globl	newval
	.align 32
	.type	newval, @object
	.size	newval, 4000008
newval:
	.zero	4000008
	.globl	oldval
	.align 32
	.type	oldval, @object
	.size	oldval, 4000008
oldval:
	.zero	4000008
	.globl	values
	.align 32
	.type	values, @object
	.size	values, 4000008
values:
	.zero	4000008
	.globl	rcode
	.align 4
	.type	rcode, @object
	.size	rcode, 4
rcode:
	.zero	4
	.globl	tpoints
	.align 4
	.type	tpoints, @object
	.size	tpoints, 4
tpoints:
	.zero	4
	.globl	nsteps
	.align 4
	.type	nsteps, @object
	.size	nsteps, 4
nsteps:
	.zero	4
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC7:
	.long	1086918619
	.align 4
.LC8:
	.long	1065353216
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC9:
	.long	-2147483648
	.long	-1077474755
	.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:

/*********************************************************
*  DESCRIPTION:                                          *
*    Serial Concurrent Wave Equation - C Version         *
*    This program implements the concurrent wave equation*
**********************************************************/

#include <hip/hip_runtime.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>

#define MAXPOINTS 1000000
#define MINPOINTS 20
#define MAXSTEPS 1000000
#define PI 3.14159265

void check_param(void);
void init_line(void);
void update(void);
void printfinal(void);

int nsteps, /*number of time steps*/
    tpoints, /*total points along string*/
    rcode; /*generic return code*/

float values[MAXPOINTS + 2], /*values at time t*/
      oldval[MAXPOINTS + 2], /*values at time (t-dt)*/
      newval[MAXPOINTS + 2]; /*values at time (t+dt)*/
float v[MAXPOINTS + 2], /*serial used for comparing answers with parallel*/
      o[MAXPOINTS + 2],
      n[MAXPOINTS + 2];

/*********************************************************
*  Check input values from parameters                    *
**********************************************************/
void check_param(void){
    char tchar[20];
	
    /*check number of points, number of iterations*/
    while((tpoints < MINPOINTS) || (tpoints > MAXPOINTS)){
        printf("Enter number of points along vibrating string [%d-%d]: ");
        scanf("%s", tchar);
	tpoints = atoi(tchar);
	if((tpoints < MINPOINTS) || (tpoints > MAXPOINTS)){
            printf("Invalid. Please enter value between %d and %d\n", MINPOINTS, MAXPOINTS);
	}
    }
    while((nsteps < 1) || (nsteps > MAXSTEPS)){
	printf("Enter number of time steps [1-%d]: ", MAXSTEPS);
	scanf("%s", tchar);
	nsteps = atoi(tchar);
	if((nsteps < 1) || (nsteps > MAXSTEPS)){
            printf("Invalid. Please enter value between 1 and %d\n", MAXSTEPS);
	}
    }
	
    printf("Using points = %d, steps = %d\n", tpoints, nsteps);
}

/*********************************************************
*  Initialize points on line                             *
**********************************************************/
void init_line(void){
    int i, j;
    float x, fac, k, tmp;
	
    /*Calculate initial values based on sine curve*/
    fac = 2.0 * PI;
    k = 0.0;
    tmp = tpoints - 1;
    for(j = 1; j <= tpoints; j++){
	x = k/tmp;
	values[j] = sin(fac * x);
        v[j] = values[j];
	k = k + 1.0;
    }
	
    /*Initialize old values array*/
    for(i = 1; i <= tpoints; i++){
	oldval[i] = values[i];
        o[i] = v[i];
    }
}

/*********************************************************
*  Calculate new values using wave equation              *
**********************************************************/
__global__ void do_math_kernel(float *val_d, float *old_d, float *new_d, int num_of_steps, int num_of_points){
    float dtime, c, dx, tau, sqtau;
	
    dtime = 0.3;
    c = 1.0;
    dx = 1.0;
    tau = (c * dtime / dx);
    sqtau = tau * tau;

    __shared__ float val_ds[1024];
    __shared__ float old_ds[1024];
    __shared__ float new_ds[1024];
    int tx = threadIdx.x;
    int index = blockIdx.x * blockDim.x + threadIdx.x;
    
    val_ds[tx] = val_d[index];
    old_ds[tx] = old_d[index];

    for(int i = 1; i <= num_of_steps; i++){
        /*This part needs to access elements from global memory of GPU*/
        /*if(index == 0 || index == num_of_points - 1) new_d[index] = 0.0;
        else new_d[index] = (2.0 * val_d[index]) - old_d[index] + (sqtau * (-2.0) * val_d[index]);
        old_d[index] = val_d[index];
        val_d[index] = new_d[index];*/
        /*This part accesses elements from shared memory of GPU -> faster*/
        /*if(index == 0 || index == num_of_points - 1) new_ds[tx] = 0.0;
        else new_ds[tx] = (2.0 * val_ds[tx]) - old_ds[tx] + (sqtau * (-2.0) * val_ds[tx]);
        old_ds[tx] = val_ds[tx];
        val_ds[tx] = new_ds[tx];*/
        /*This part only takes values[2~tpoints-1] total tpoins-2 points from CPU to GPU in order to reduce branch overhead*/ 
        new_ds[tx] = (2.0 * val_ds[tx]) - old_ds[tx] + (sqtau * (-2.0) * val_ds[tx]);
        old_ds[tx] = val_ds[tx];
        val_ds[tx] = new_ds[tx];
        
    }
    __syncthreads();
    val_d[index] = val_ds[tx];
    
}

void do_math(int i){
    float dtime, c, dx, tau, sqtau;
	
    dtime = 0.3;
    c = 1.0;
    dx = 1.0;
    tau = (c * dtime / dx);
    sqtau = tau * tau;
    newval[i] = (2.0 * values[i]) - oldval[i] + (sqtau * (-2.0) * values[i]);
    //n[i] = (2.0 * v[i]) - o[i] + (sqtau * (-2.0) * v[i]);
}

/***********************************************************
*  Update all values along line a specified number of times*
***********************************************************/
void updateOnDevice(){
    //int size = tpoints * sizeof(float);
    int size = (tpoints - 2) * sizeof(float);
    float *val_d, *old_d, *new_d; //memory on device

    /*1.Allocate device memory and move initiail values[] and oldval[] to GPU*/
    hipMalloc(&val_d, size);
    //cudaMemcpy(val_d, values+1, size, cudaMemcpyHostToDevice);
    hipMemcpy(val_d, values+2, size, hipMemcpyHostToDevice);
    hipMalloc(&old_d, size);
    //cudaMemcpy(old_d, oldval+1, size, cudaMemcpyHostToDevice);
    hipMemcpy(old_d, oldval+2, size, hipMemcpyHostToDevice);
    hipMalloc(&new_d, size);
	
    /*2.Invoke kernel function, each thread calculates a value[] element*/
    int threads_per_block, blocks_per_grid = tpoints/1024 + 1;
    if(tpoints > 1024) threads_per_block = 1024;
    else threads_per_block = tpoints;
    dim3 dimBlock(threads_per_block); 
    dim3 dimGrid(blocks_per_grid);
    do_math_kernel<<<dimGrid,dimBlock>>>(val_d, old_d, new_d, nsteps, tpoints);

    /*3.Read final results from GPU to CPU*/
    //cudaMemcpy(values+1, val_d, size, cudaMemcpyDeviceToHost);
    hipMemcpy(values+2, val_d, size, hipMemcpyDeviceToHost);
    hipFree(val_d); hipFree(old_d); hipFree(new_d);
}

void update(){
    int i, j;
	
    /*Update values for each time step*/
    for(i = 1; i <= nsteps; i++){
        /*Update points along line for this time step*/
        for(j = 1; j <= tpoints; j++){
	    /*global endpoints*/
            if((j == 1) || (j == tpoints)){
                newval[j] = 0.0;
                //n[j] = 0.0;
            }
	    else do_math(j);
	}
        /*Update old values with new values*/
        for(j = 1; j <= tpoints; j++){
	    oldval[j] = values[j];
	    values[j] = newval[j];
            /*o[j] = v[j];
            v[j] = n[j];*/
        }
    }
	
}

/**********************************************************
*  Print final results                                    *
**********************************************************/
void printfinal(){
    int i;

    for(i = 1; i <= tpoints; i++){
	printf("%6.4f ", values[i]);
	if(i%10 == 0) printf("\n");
    }	
}

/**********************************************************
*  Check serial and parallel answers                      *
**********************************************************/
void check_answer(){
    int wrong = 0, num = 0;
    for(int i = 1; i <= tpoints; i++){
        if(values[i]!=v[i]){
            wrong = 1;
            num++;
        }
    }
    if(wrong == 0) printf("right\n");
    else printf("%d are wrong\n", num);
    /*In command line ./ cuda_wave.out > [filename] to pipe output to the file
      then use diff file1 file2 to see if there is any difference*/
}

/*********************************************************
*  Main Program                                          *
**********************************************************/
int main(int argc, char *argv[]){
    sscanf(argv[1], "%d", &tpoints);
    sscanf(argv[2], "%d", &nsteps);
	
    check_param();
	
    printf("Initializing points on the line...\n");
    init_line();
    //printfinal();
	
    printf("Updating all points for all time steps...\n");
    //update();
    updateOnDevice();
	
    printf("Printing final results...\n");
    printfinal();
    printf("\nDone.\n\n");
	
    return 0;
}	  

	.text
	.file	"wave.hip"
	.globl	_Z11check_paramv                # -- Begin function _Z11check_paramv
	.type	_Z11check_paramv,@function
_Z11check_paramv:                       # @_Z11check_paramv
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	tpoints(%rip), %eax
	leal	-1000001(%rax), %ecx
	cmpl	$-999982, %ecx                  # imm = 0xFFF0BDD2
	ja	.LBB0_3
# %bb.1:
	movq	%rsp, %rbx
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.1, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movq	%rbx, %rdi
	callq	atoi
                                        # kill: def $eax killed $eax def $rax
	movl	%eax, tpoints(%rip)
	leal	-1000001(%rax), %ecx
	cmpl	$-999982, %ecx                  # imm = 0xFFF0BDD2
	ja	.LBB0_3
# %bb.9:                                #   in Loop: Header=BB0_2 Depth=1
	movl	$.L.str.2, %edi
	movl	$20, %esi
	movl	$1000000, %edx                  # imm = 0xF4240
	xorl	%eax, %eax
	callq	printf
	movl	tpoints(%rip), %eax
	leal	-1000001(%rax), %ecx
	cmpl	$-999981, %ecx                  # imm = 0xFFF0BDD3
	jb	.LBB0_2
.LBB0_3:                                # %.preheader
	movl	nsteps(%rip), %edx
	movl	$-1000001, %r14d                # imm = 0xFFF0BDBF
	leal	(%rdx,%r14), %ecx
	cmpl	%r14d, %ecx
	ja	.LBB0_8
# %bb.4:
	movq	%rsp, %rbx
.LBB0_5:                                # %.lr.ph4
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str.3, %edi
	movl	$1000000, %esi                  # imm = 0xF4240
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.1, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movq	%rbx, %rdi
	callq	atoi
	movl	%eax, %edx
	movl	%eax, nsteps(%rip)
	leal	(%rdx,%r14), %eax
	cmpl	%r14d, %eax
	ja	.LBB0_7
# %bb.6:                                #   in Loop: Header=BB0_5 Depth=1
	movl	$.L.str.4, %edi
	movl	$1000000, %esi                  # imm = 0xF4240
	xorl	%eax, %eax
	callq	printf
	movl	nsteps(%rip), %edx
	leal	-1000001(%rdx), %eax
	cmpl	$-1000000, %eax                 # imm = 0xFFF0BDC0
	jb	.LBB0_5
.LBB0_7:                                # %._crit_edge.loopexit
	movl	tpoints(%rip), %eax
.LBB0_8:                                # %._crit_edge
	movl	$.L.str.5, %edi
	movl	%eax, %esi
                                        # kill: def $edx killed $edx killed $rdx
	xorl	%eax, %eax
	callq	printf
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z11check_paramv, .Lfunc_end0-_Z11check_paramv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z9init_linev
.LCPI1_0:
	.long	0x40c90fdb                      # float 6.28318548
.LCPI1_1:
	.long	0x3f800000                      # float 1
	.text
	.globl	_Z9init_linev
	.type	_Z9init_linev,@function
_Z9init_linev:                          # @_Z9init_linev
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	movl	tpoints(%rip), %eax
	testl	%eax, %eax
	jle	.LBB1_4
# %bb.1:                                # %.lr.ph.preheader
	decl	%eax
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, 12(%rsp)                 # 4-byte Spill
	xorps	%xmm0, %xmm0
	xorl	%ebx, %ebx
.LBB1_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movss	%xmm0, 8(%rsp)                  # 4-byte Spill
	movss	8(%rsp), %xmm0                  # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	divss	12(%rsp), %xmm0                 # 4-byte Folded Reload
	mulss	.LCPI1_0(%rip), %xmm0
	callq	sinf
	movss	%xmm0, values+4(,%rbx,4)
	movss	%xmm0, v+4(,%rbx,4)
	movss	8(%rsp), %xmm0                  # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	addss	.LCPI1_1(%rip), %xmm0
	movslq	tpoints(%rip), %rax
	incq	%rbx
	cmpq	%rax, %rbx
	jl	.LBB1_2
# %bb.3:                                # %.preheader
	movl	%eax, %ebx
	testl	%ebx, %ebx
	jle	.LBB1_4
# %bb.5:                                # %.lr.ph23.preheader
	shlq	$2, %rbx
	movl	$oldval+4, %edi
	movl	$values+4, %esi
	movq	%rbx, %rdx
	callq	memcpy@PLT
	movl	$o+4, %edi
	movl	$v+4, %esi
	movq	%rbx, %rdx
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	memcpy@PLT                      # TAILCALL
.LBB1_4:                                # %._crit_edge
	.cfi_def_cfa_offset 32
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z9init_linev, .Lfunc_end1-_Z9init_linev
	.cfi_endproc
                                        # -- End function
	.globl	_Z29__device_stub__do_math_kernelPfS_S_ii # -- Begin function _Z29__device_stub__do_math_kernelPfS_S_ii
	.type	_Z29__device_stub__do_math_kernelPfS_S_ii,@function
_Z29__device_stub__do_math_kernelPfS_S_ii: # @_Z29__device_stub__do_math_kernelPfS_S_ii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	movq	%rsp, %rcx
	movl	%r8d, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%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	$_Z14do_math_kernelPfS_S_ii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z29__device_stub__do_math_kernelPfS_S_ii, .Lfunc_end2-_Z29__device_stub__do_math_kernelPfS_S_ii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z7do_mathi
.LCPI3_0:
	.quad	0xbfc70a3d80000000              # double -0.18000000715255737
	.text
	.globl	_Z7do_mathi
	.type	_Z7do_mathi,@function
_Z7do_mathi:                            # @_Z7do_mathi
	.cfi_startproc
# %bb.0:
	movslq	%edi, %rax
	cvtss2sd	values(,%rax,4), %xmm0
	movaps	%xmm0, %xmm1
	cvtss2sd	oldval(,%rax,4), %xmm2
	addsd	%xmm0, %xmm1
	subsd	%xmm2, %xmm1
	mulsd	.LCPI3_0(%rip), %xmm0
	addsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, newval(,%rax,4)
	retq
.Lfunc_end3:
	.size	_Z7do_mathi, .Lfunc_end3-_Z7do_mathi
	.cfi_endproc
                                        # -- End function
	.globl	_Z14updateOnDevicev             # -- Begin function _Z14updateOnDevicev
	.type	_Z14updateOnDevicev,@function
_Z14updateOnDevicev:                    # @_Z14updateOnDevicev
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	tpoints(%rip), %eax
	leal	-8(,%rax,4), %eax
	movslq	%eax, %rbx
	movq	%rsp, %r14
	movq	%r14, %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movl	$values+8, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	16(%rsp), %r14
	movq	%r14, %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movl	$oldval+8, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	8(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movl	tpoints(%rip), %eax
	leal	1023(%rax), %edi
	testl	%eax, %eax
	cmovnsl	%eax, %edi
	sarl	$10, %edi
	incl	%edi
	movl	$1024, %edx                     # imm = 0x400
	cmpl	%edx, %eax
	cmovll	%eax, %edx
	btsq	$32, %rdx
	btsq	$32, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_2
# %bb.1:
	movq	(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	movl	nsteps(%rip), %ecx
	movl	tpoints(%rip), %r8d
	callq	_Z29__device_stub__do_math_kernelPfS_S_ii
.LBB4_2:
	movq	(%rsp), %rsi
	movl	$values+8, %edi
	movq	%rbx, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z14updateOnDevicev, .Lfunc_end4-_Z14updateOnDevicev
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z6updatev
.LCPI5_0:
	.quad	0xbfc70a3d80000000              # double -0.18000000715255737
	.text
	.globl	_Z6updatev
	.type	_Z6updatev,@function
_Z6updatev:                             # @_Z6updatev
	.cfi_startproc
# %bb.0:
	movl	nsteps(%rip), %eax
	testl	%eax, %eax
	jle	.LBB5_12
# %bb.1:                                # %.preheader18.lr.ph
	movl	tpoints(%rip), %ecx
	leal	1(%rcx), %edx
	leaq	-4(,%rcx,4), %rsi
	leaq	-4(,%rdx,4), %rdi
	shlq	$2, %rdx
	movl	$1, %r8d
	movsd	.LCPI5_0(%rip), %xmm0           # xmm0 = mem[0],zero
.LBB5_2:                                # %.preheader18
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_4 Depth 2
                                        #     Child Loop BB5_10 Depth 2
	testl	%ecx, %ecx
	jle	.LBB5_11
# %bb.3:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB5_2 Depth=1
	xorl	%r9d, %r9d
.LBB5_4:                                # %.lr.ph
                                        #   Parent Loop BB5_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm1, %xmm1
	testq	%r9, %r9
	je	.LBB5_7
# %bb.5:                                # %.lr.ph
                                        #   in Loop: Header=BB5_4 Depth=2
	cmpq	%r9, %rsi
	je	.LBB5_7
# %bb.6:                                #   in Loop: Header=BB5_4 Depth=2
	xorps	%xmm1, %xmm1
	cvtss2sd	values+4(%r9), %xmm1
	movaps	%xmm1, %xmm2
	addsd	%xmm1, %xmm2
	xorps	%xmm3, %xmm3
	cvtss2sd	oldval+4(%r9), %xmm3
	subsd	%xmm3, %xmm2
	mulsd	%xmm0, %xmm1
	addsd	%xmm2, %xmm1
	cvtsd2ss	%xmm1, %xmm1
.LBB5_7:                                #   in Loop: Header=BB5_4 Depth=2
	movss	%xmm1, newval+4(%r9)
	addq	$4, %r9
	cmpq	%r9, %rdi
	jne	.LBB5_4
# %bb.8:                                # %.preheader
                                        #   in Loop: Header=BB5_2 Depth=1
	testl	%ecx, %ecx
	jle	.LBB5_11
# %bb.9:                                # %.lr.ph23.preheader
                                        #   in Loop: Header=BB5_2 Depth=1
	movl	$4, %r9d
.LBB5_10:                               # %.lr.ph23
                                        #   Parent Loop BB5_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	values(%r9), %xmm1              # xmm1 = mem[0],zero,zero,zero
	movss	%xmm1, oldval(%r9)
	movss	newval(%r9), %xmm1              # xmm1 = mem[0],zero,zero,zero
	movss	%xmm1, values(%r9)
	addq	$4, %r9
	cmpq	%r9, %rdx
	jne	.LBB5_10
.LBB5_11:                               # %._crit_edge
                                        #   in Loop: Header=BB5_2 Depth=1
	leal	1(%r8), %r9d
	cmpl	%eax, %r8d
	movl	%r9d, %r8d
	jne	.LBB5_2
.LBB5_12:                               # %._crit_edge26
	retq
.Lfunc_end5:
	.size	_Z6updatev, .Lfunc_end5-_Z6updatev
	.cfi_endproc
                                        # -- End function
	.globl	_Z10printfinalv                 # -- Begin function _Z10printfinalv
	.type	_Z10printfinalv,@function
_Z10printfinalv:                        # @_Z10printfinalv
	.cfi_startproc
# %bb.0:
	cmpl	$0, tpoints(%rip)
	jle	.LBB6_6
# %bb.1:                                # %.lr.ph.preheader
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$1, %ebx
	xorl	%r14d, %r14d
	movl	$3435973837, %r15d              # imm = 0xCCCCCCCD
.LBB6_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%ebx, %eax
	imulq	%r15, %rax
	shrq	$35, %rax
	leal	(%rax,%rax,4), %eax
	leal	-1(,%rax,2), %ebp
	xorps	%xmm0, %xmm0
	cvtss2sd	values+4(,%r14,4), %xmm0
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	cmpl	%r14d, %ebp
	jne	.LBB6_4
# %bb.3:                                #   in Loop: Header=BB6_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
.LBB6_4:                                #   in Loop: Header=BB6_2 Depth=1
	movslq	tpoints(%rip), %rax
	incq	%r14
	incl	%ebx
	cmpq	%rax, %r14
	jl	.LBB6_2
# %bb.5:
	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
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
	.cfi_restore %rbp
.LBB6_6:                                # %._crit_edge
	retq
.Lfunc_end6:
	.size	_Z10printfinalv, .Lfunc_end6-_Z10printfinalv
	.cfi_endproc
                                        # -- End function
	.globl	_Z12check_answerv               # -- Begin function _Z12check_answerv
	.type	_Z12check_answerv,@function
_Z12check_answerv:                      # @_Z12check_answerv
	.cfi_startproc
# %bb.0:
	movl	tpoints(%rip), %eax
	testl	%eax, %eax
	jle	.LBB7_4
# %bb.1:                                # %.lr.ph.preheader
	leaq	4(,%rax,4), %rax
	xorl	%esi, %esi
	movl	$4, %ecx
	movl	$1, %edx
	xorl	%edi, %edi
.LBB7_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movss	values(%rcx), %xmm0             # xmm0 = mem[0],zero,zero,zero
	movss	v(%rcx), %xmm1                  # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm1, %xmm0
	cmpneqss	%xmm1, %xmm0
	cmovnel	%edx, %edi
	cmovpl	%edx, %edi
	movd	%xmm0, %r8d
	subl	%r8d, %esi
	addq	$4, %rcx
	cmpq	%rcx, %rax
	jne	.LBB7_2
# %bb.3:                                # %._crit_edge
	testl	%edi, %edi
	je	.LBB7_4
# %bb.5:
	movl	$.L.str.9, %edi
	xorl	%eax, %eax
	jmp	printf                          # TAILCALL
.LBB7_4:                                # %._crit_edge.thread
	movl	$.Lstr, %edi
	jmp	puts@PLT                        # TAILCALL
.Lfunc_end7:
	.size	_Z12check_answerv, .Lfunc_end7-_Z12check_answerv
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rsi, %rbx
	movq	8(%rsi), %rdi
	movl	$.L.str.10, %esi
	movl	$tpoints, %edx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	movq	16(%rbx), %rdi
	movl	$.L.str.10, %esi
	movl	$nsteps, %edx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	callq	_Z11check_paramv
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	callq	_Z9init_linev
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	callq	_Z14updateOnDevicev
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	callq	_Z10printfinalv
	movl	$.Lstr.4, %edi
	callq	puts@PLT
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end8:
	.size	main, .Lfunc_end8-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:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB9_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB9_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14do_math_kernelPfS_S_ii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end9:
	.size	__hip_module_ctor, .Lfunc_end9-__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	.LBB10_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
.LBB10_2:
	retq
.Lfunc_end10:
	.size	__hip_module_dtor, .Lfunc_end10-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	nsteps,@object                  # @nsteps
	.bss
	.globl	nsteps
	.p2align	2, 0x0
nsteps:
	.long	0                               # 0x0
	.size	nsteps, 4

	.type	tpoints,@object                 # @tpoints
	.globl	tpoints
	.p2align	2, 0x0
tpoints:
	.long	0                               # 0x0
	.size	tpoints, 4

	.type	rcode,@object                   # @rcode
	.globl	rcode
	.p2align	2, 0x0
rcode:
	.long	0                               # 0x0
	.size	rcode, 4

	.type	values,@object                  # @values
	.globl	values
	.p2align	4, 0x0
values:
	.zero	4000008
	.size	values, 4000008

	.type	oldval,@object                  # @oldval
	.globl	oldval
	.p2align	4, 0x0
oldval:
	.zero	4000008
	.size	oldval, 4000008

	.type	newval,@object                  # @newval
	.globl	newval
	.p2align	4, 0x0
newval:
	.zero	4000008
	.size	newval, 4000008

	.type	v,@object                       # @v
	.globl	v
	.p2align	4, 0x0
v:
	.zero	4000008
	.size	v, 4000008

	.type	o,@object                       # @o
	.globl	o
	.p2align	4, 0x0
o:
	.zero	4000008
	.size	o, 4000008

	.type	n,@object                       # @n
	.globl	n
	.p2align	4, 0x0
n:
	.zero	4000008
	.size	n, 4000008

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Enter number of points along vibrating string [%d-%d]: "
	.size	.L.str, 56

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

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Invalid. Please enter value between %d and %d\n"
	.size	.L.str.2, 47

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Enter number of time steps [1-%d]: "
	.size	.L.str.3, 36

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Invalid. Please enter value between 1 and %d\n"
	.size	.L.str.4, 46

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Using points = %d, steps = %d\n"
	.size	.L.str.5, 31

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

	.type	.L.str.6,@object                # @.str.6
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.6:
	.asciz	"%6.4f "
	.size	.L.str.6, 7

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"%d are wrong\n"
	.size	.L.str.9, 14

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"%d"
	.size	.L.str.10, 3

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z14do_math_kernelPfS_S_ii"
	.size	.L__unnamed_1, 27

	.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	"right"
	.size	.Lstr, 6

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Initializing points on the line..."
	.size	.Lstr.1, 35

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Updating all points for all time steps..."
	.size	.Lstr.2, 42

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Printing final results..."
	.size	.Lstr.3, 26

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"\nDone.\n"
	.size	.Lstr.4, 8

	.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 _Z29__device_stub__do_math_kernelPfS_S_ii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym nsteps
	.addrsig_sym tpoints
	.addrsig_sym values
	.addrsig_sym oldval
	.addrsig_sym _Z14do_math_kernelPfS_S_ii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14do_math_kernelPfS_S_ii ; -- Begin function _Z14do_math_kernelPfS_S_ii
	.globl	_Z14do_math_kernelPfS_S_ii
	.p2align	8
	.type	_Z14do_math_kernelPfS_S_ii,@function
_Z14do_math_kernelPfS_S_ii:             ; @_Z14do_math_kernelPfS_S_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x2c
	s_load_b128 s[4:7], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_load_b32 s2, s[0:1], 0x18
	v_lshlrev_b32_e32 v0, 2, v0
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[3:4], 2, v[1:2]
	v_add_co_u32 v1, vcc_lo, s4, v3
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v2, vcc_lo, s5, v4, vcc_lo
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s2, 1
	global_load_b32 v5, v[1:2], off
	s_waitcnt vmcnt(0)
	ds_store_b32 v0, v5
	s_cbranch_scc1 .LBB0_4
; %bb.1:                                ; %.lr.ph.preheader
	v_add_co_u32 v3, vcc_lo, s6, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s7, v4, vcc_lo
	s_brev_b32 s0, 1
	s_mov_b32 s1, 0xbfc70a3d
	global_load_b32 v3, v[3:4], off
.LBB0_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mov_b32_e32 v8, v5
	s_waitcnt vmcnt(0)
	v_cvt_f64_f32_e32 v[6:7], v3
	s_add_i32 s2, s2, -1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	s_cmp_eq_u32 s2, 0
	v_cvt_f64_f32_e32 v[4:5], v8
	v_fma_f64 v[6:7], v[4:5], 2.0, -v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[3:4], v[4:5], s[0:1], v[6:7]
	v_cvt_f32_f64_e32 v5, v[3:4]
	v_mov_b32_e32 v3, v8
	s_cbranch_scc0 .LBB0_2
; %bb.3:                                ; %._crit_edge
	ds_store_b32 v0, v5
.LBB0_4:
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	ds_load_b32 v0, v0
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[1:2], v0, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14do_math_kernelPfS_S_ii
		.amdhsa_group_segment_fixed_size 4096
		.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 9
		.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	_Z14do_math_kernelPfS_S_ii, .Lfunc_end0-_Z14do_math_kernelPfS_S_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 272
; NumSgprs: 18
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 4096 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 9
; 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
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .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: 4096
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14do_math_kernelPfS_S_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z14do_math_kernelPfS_S_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
