#include <iostream>
#include <stdio.h>
#include <time.h>
using namespace std;

#define PI 3.1415926535897932384
#define mu0 4*PI*1e-7
#define threadsPerBlock 1024

__global__ void init(double *rod_new, double imax, double ldr, double rlength, int rod_size){
  int rem = rod_size%threadsPerBlock;
  int divi = rod_size/threadsPerBlock;
  int start, fin;
  if(threadIdx.x<rem){
    start = threadIdx.x*(divi+1);
    fin = start + divi + 1;
  }
  else{
    start = threadIdx.x*divi + rem;
    fin = start + divi;
  }
  for(int i = start; i<fin; i++){
    rod_new[i] = (1-(i*i*ldr*ldr/(3*rlength*rlength)))*3*mu0*imax*i*ldr/(4*PI*rlength*rlength);
  }
}

__global__ void run(double *rod_new, double aug, long int maxSteps, int rod_size){
  int rem = rod_size%threadsPerBlock;
  int divi = rod_size/threadsPerBlock;
  int start, fin;
  if(threadIdx.x<rem){
    start = threadIdx.x*(divi+1);
    fin = start + divi + 1;
  }
  else{
    start = threadIdx.x*divi + rem;
    fin = start + divi;
  }
  long int steps = 0;
  extern __shared__ double rod_new_s[];
  extern __shared__ double rod_old_s[];
  for(int i = start; i<fin; i++){
    rod_new_s[i] = rod_new[i];
  }
  __syncthreads();

  while(steps<maxSteps){
    for(int i = start; i<fin; i++){
      rod_old_s[i] = rod_new_s[i];
    }
    __syncthreads();
    for(int i = start; i<fin; i++){
      if(i==1)
        rod_new_s[1]+= aug*(2*rod_old_s[2] - 4*rod_old_s[1]);
      else if(i<(rod_size - 1) && i > 1)
        rod_new_s[i] += aug*((1+(1/(2*i)))*rod_old_s[i+1] + (-2-(1/(i*i)))*rod_old_s[i] + (1-(1/(2*i)))*rod_old_s[i-1]);
      }
    steps++;
    __syncthreads();
  }
  for(int i = start; i<fin; i++){
    rod_new[i] = rod_new_s[i];
  }
}

int main(){
  FILE *myfile;
  myfile = fopen("results.txt", "w");
  double imax, rlength, eta, tstep, ldr, tottime;
  int numseg;
  printf("What is your I max? ");
  scanf("%lf", &imax);
  printf("What is the length of your rod? ");
  scanf("%lf", &rlength);
  printf("What is eta? ");
  scanf("%lf", &eta);
  printf("How many segments would you like? ");
  scanf("%d", &numseg);
  ldr = rlength/(numseg+1);
  tstep = 0.25*ldr*ldr*mu0/eta;
  printf("How long would you like to run? ");
  scanf("%lf", &tottime);

  double *h_rod, *d_rod;
  size_t rod_size = (numseg + 2) * sizeof(double);
  h_rod = (double*)malloc(rod_size);
  cudaMalloc(&d_rod, rod_size);

  init<<<1,threadsPerBlock>>>(d_rod, imax, ldr, rlength, numseg + 2);

  int out;
  //output r values
  for(out = 0; out<numseg+1; out++){
    fprintf( myfile, "%lf ", out*ldr );
  }
  fprintf( myfile, "%lf\n", out*ldr );

  cudaMemcpy(h_rod, d_rod, rod_size, cudaMemcpyDeviceToHost);

  for(out = 0; out<numseg+1; out++){
    fprintf( myfile, "%lf ", *(h_rod+out) );
  }
  fprintf( myfile, "%lf\n", *(h_rod+out) );

  double aug = eta*tstep/(mu0*ldr*ldr);
  long int total_steps = tottime / tstep;
  printf("\nSteps: %ld\n", total_steps);


  clock_t begin, end;
  double time_spent;
  begin = clock();

  //run
  run<<<1,threadsPerBlock, (numseg+2)*sizeof(double)>>>(d_rod, aug, total_steps, numseg+2);
  cudaDeviceSynchronize();

  end = clock();
  time_spent = (double)(end - begin) / CLOCKS_PER_SEC;

  cudaMemcpy(h_rod, d_rod, rod_size, cudaMemcpyDeviceToHost);

  for(out = 0; out<numseg+1; out++){
    fprintf( myfile, "%lf ", *(h_rod+out) );
  }
  fprintf( myfile, "%lf\n", *(h_rod+out) );

  fprintf(myfile, "STOP\n");
  fclose(myfile);

  free(h_rod);
  cudaFree(d_rod);



  cout << "\n------------------------------------\nExecution took: "<<  time_spent << " sec\n";

  return 0;
}

	.file	"tmpxft_0020d435_00000000-6_run.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3638:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3638:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z27__device_stub__Z4initPddddiPddddi
	.type	_Z27__device_stub__Z4initPddddiPddddi, @function
_Z27__device_stub__Z4initPddddiPddddi:
.LFB3660:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 40(%rsp)
	leaq	56(%rsp), %rcx
	leaq	48(%rsp), %rdx
	movl	%esi, 12(%rsp)
	leaq	64(%rsp), %rdi
	leaq	76(%rsp), %rsi
	movsd	%xmm0, 32(%rsp)
	movsd	%xmm1, 24(%rsp)
	movsd	%xmm2, 16(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z4initPddddi(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 192
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L2:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3660:
	.size	_Z27__device_stub__Z4initPddddiPddddi, .-_Z27__device_stub__Z4initPddddiPddddi
	.globl	_Z4initPddddi
	.type	_Z4initPddddi, @function
_Z4initPddddi:
.LFB3661:
	.cfi_startproc
	endbr64
	jmp	_Z27__device_stub__Z4initPddddiPddddi
	.cfi_endproc
.LFE3661:
	.size	_Z4initPddddi, .-_Z4initPddddi
	.globl	_Z25__device_stub__Z3runPddliPddli
	.type	_Z25__device_stub__Z3runPddliPddli, @function
_Z25__device_stub__Z3runPddliPddli:
.LFB3662:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rcx
	leaq	56(%rsp), %rdi
	movq	%rsi, 8(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 4(%rsp)
	leaq	40(%rsp), %rdx
	movsd	%xmm0, 16(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L8
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z3runPddli(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L8:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3662:
	.size	_Z25__device_stub__Z3runPddliPddli, .-_Z25__device_stub__Z3runPddliPddli
	.globl	_Z3runPddli
	.type	_Z3runPddli, @function
_Z3runPddli:
.LFB3663:
	.cfi_startproc
	endbr64
	jmp	_Z25__device_stub__Z3runPddliPddli
	.cfi_endproc
.LFE3663:
	.size	_Z3runPddli, .-_Z3runPddli
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"w"
.LC1:
	.string	"results.txt"
.LC2:
	.string	"What is your I max? "
.LC3:
	.string	"%lf"
.LC4:
	.string	"What is the length of your rod? "
.LC5:
	.string	"What is eta? "
.LC6:
	.string	"How many segments would you like? "
.LC7:
	.string	"%d"
.LC12:
	.string	"How long would you like to run? "
.LC13:
	.string	"%lf "
.LC14:
	.string	"%lf\n"
.LC15:
	.string	"\nSteps: %ld\n"
.LC18:
	.string	"STOP\n"
.LC19:
	.string	"\n------------------------------------\nExecution took: "
.LC20:
	.string	" sec\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC0(%rip), %rsi
	leaq	.LC1(%rip), %rdi
	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
	leaq	.LC3(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rbx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	leaq	40(%rsp), %rsi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	leaq	48(%rsp), %rsi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	leaq	56(%rsp), %rsi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	36(%rsp), %rsi
	leaq	.LC7(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	movl	36(%rsp), %eax
	movsd	48(%rsp), %xmm1
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	incl	%eax
	cvtsi2sdl	%eax, %xmm0
	xorl	%eax, %eax
	divsd	%xmm0, %xmm1
	movsd	.LC8(%rip), %xmm0
	mulsd	%xmm1, %xmm0
	movsd	%xmm1, 8(%rsp)
	mulsd	%xmm1, %xmm0
	mulsd	.LC9(%rip), %xmm0
	mulsd	.LC10(%rip), %xmm0
	mulsd	.LC11(%rip), %xmm0
	divsd	56(%rsp), %xmm0
	movsd	%xmm0, 16(%rsp)
	call	__printf_chk@PLT
	leaq	64(%rsp), %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	movl	36(%rsp), %eax
	leal	2(%rax), %ebp
	movslq	%ebp, %rbp
	salq	$3, %rbp
	movq	%rbp, %rdi
	call	malloc@PLT
	leaq	72(%rsp), %rdi
	movq	%rbp, %rsi
	movq	%rax, %r12
	call	cudaMalloc@PLT
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$10, %rdx
	movl	$1, %ecx
	movabsq	$4294967297, %rdi
	movl	$1, %esi
	movq	%rdx, 92(%rsp)
	movl	$1, 100(%rsp)
	movq	%rdi, 80(%rsp)
	movl	$1, 88(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L14
	movl	36(%rsp), %eax
	movsd	48(%rsp), %xmm2
	movsd	8(%rsp), %xmm1
	movsd	40(%rsp), %xmm0
	movq	72(%rsp), %rdi
	leal	2(%rax), %esi
	call	_Z27__device_stub__Z4initPddddiPddddi
.L14:
	xorl	%r14d, %r14d
	leaq	.LC13(%rip), %r13
.L15:
	cvtsi2sdl	%r14d, %xmm0
	mulsd	8(%rsp), %xmm0
	cmpl	%r14d, 36(%rsp)
	jl	.L24
	movq	%r13, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	call	__fprintf_chk@PLT
	incl	%r14d
	jmp	.L15
.L24:
	leaq	.LC14(%rip), %r13
	movq	%rbx, %rdi
	movb	$1, %al
	xorl	%r14d, %r14d
	movq	%r13, %rdx
	movl	$2, %esi
	leaq	.LC13(%rip), %r15
	call	__fprintf_chk@PLT
	movq	72(%rsp), %rsi
	movq	%rbp, %rdx
	movq	%r12, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
.L17:
	movsd	(%r12,%r14,8), %xmm0
	cmpl	%r14d, 36(%rsp)
	jl	.L25
	movq	%r15, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	call	__fprintf_chk@PLT
	incq	%r14
	jmp	.L17
.L25:
	movq	%r13, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	call	__fprintf_chk@PLT
	movsd	64(%rsp), %xmm0
	divsd	16(%rsp), %xmm0
	xorl	%eax, %eax
	cvttsd2siq	%xmm0, %r15
	movsd	56(%rsp), %xmm5
	movl	$2, %edi
	leaq	.LC15(%rip), %rsi
	movsd	%xmm5, 24(%rsp)
	movq	%r15, %rdx
	call	__printf_chk@PLT
	call	clock@PLT
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	movabsq	$4294967297, %rdi
	movq	%rax, %r14
	movl	36(%rsp), %eax
	salq	$10, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	movq	%rdx, 92(%rsp)
	addl	$2, %eax
	movl	$1, 100(%rsp)
	cltq
	movq	%rdi, 80(%rsp)
	leaq	0(,%rax,8), %r8
	movl	$1, 88(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L19
	movsd	8(%rsp), %xmm1
	mulsd	.LC16(%rip), %xmm1
	movq	%r15, %rsi
	mulsd	8(%rsp), %xmm1
	movsd	24(%rsp), %xmm0
	mulsd	16(%rsp), %xmm0
	movl	36(%rsp), %eax
	movq	72(%rsp), %rdi
	leal	2(%rax), %edx
	divsd	%xmm1, %xmm0
	call	_Z25__device_stub__Z3runPddliPddli
.L19:
	call	cudaDeviceSynchronize@PLT
	leaq	.LC13(%rip), %r15
	call	clock@PLT
	movq	72(%rsp), %rsi
	movq	%rbp, %rdx
	movq	%r12, %rdi
	subq	%r14, %rax
	movl	$2, %ecx
	xorl	%ebp, %ebp
	cvtsi2sdq	%rax, %xmm0
	divsd	.LC17(%rip), %xmm0
	movq	%xmm0, %r14
	call	cudaMemcpy@PLT
.L20:
	movsd	(%r12,%rbp,8), %xmm0
	cmpl	%ebp, 36(%rsp)
	jl	.L26
	movq	%r15, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	call	__fprintf_chk@PLT
	incq	%rbp
	jmp	.L20
.L26:
	movq	%r13, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	call	__fprintf_chk@PLT
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	leaq	.LC18(%rip), %rdx
	call	__fprintf_chk@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	leaq	.LC19(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%r14, %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC20(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	addq	$120, %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
.LFE3635:
	.size	main, .-main
	.section	.rodata.str1.1
.LC21:
	.string	"_Z3runPddli"
.LC22:
	.string	"_Z4initPddddi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3665:
	.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	_Z3runPddli(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC22(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z4initPddddi(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.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
.LFE3665:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC8:
	.long	0
	.long	1070596096
	.align 8
.LC9:
	.long	0
	.long	1074790400
	.align 8
.LC10:
	.long	1413754136
	.long	1074340347
	.align 8
.LC11:
	.long	-1698910392
	.long	1048238066
	.align 8
.LC16:
	.long	261748427
	.long	1052054839
	.align 8
.LC17:
	.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 <iostream>
#include <stdio.h>
#include <time.h>
using namespace std;

#define PI 3.1415926535897932384
#define mu0 4*PI*1e-7
#define threadsPerBlock 1024

__global__ void init(double *rod_new, double imax, double ldr, double rlength, int rod_size){
  int rem = rod_size%threadsPerBlock;
  int divi = rod_size/threadsPerBlock;
  int start, fin;
  if(threadIdx.x<rem){
    start = threadIdx.x*(divi+1);
    fin = start + divi + 1;
  }
  else{
    start = threadIdx.x*divi + rem;
    fin = start + divi;
  }
  for(int i = start; i<fin; i++){
    rod_new[i] = (1-(i*i*ldr*ldr/(3*rlength*rlength)))*3*mu0*imax*i*ldr/(4*PI*rlength*rlength);
  }
}

__global__ void run(double *rod_new, double aug, long int maxSteps, int rod_size){
  int rem = rod_size%threadsPerBlock;
  int divi = rod_size/threadsPerBlock;
  int start, fin;
  if(threadIdx.x<rem){
    start = threadIdx.x*(divi+1);
    fin = start + divi + 1;
  }
  else{
    start = threadIdx.x*divi + rem;
    fin = start + divi;
  }
  long int steps = 0;
  extern __shared__ double rod_new_s[];
  extern __shared__ double rod_old_s[];
  for(int i = start; i<fin; i++){
    rod_new_s[i] = rod_new[i];
  }
  __syncthreads();

  while(steps<maxSteps){
    for(int i = start; i<fin; i++){
      rod_old_s[i] = rod_new_s[i];
    }
    __syncthreads();
    for(int i = start; i<fin; i++){
      if(i==1)
        rod_new_s[1]+= aug*(2*rod_old_s[2] - 4*rod_old_s[1]);
      else if(i<(rod_size - 1) && i > 1)
        rod_new_s[i] += aug*((1+(1/(2*i)))*rod_old_s[i+1] + (-2-(1/(i*i)))*rod_old_s[i] + (1-(1/(2*i)))*rod_old_s[i-1]);
      }
    steps++;
    __syncthreads();
  }
  for(int i = start; i<fin; i++){
    rod_new[i] = rod_new_s[i];
  }
}

int main(){
  FILE *myfile;
  myfile = fopen("results.txt", "w");
  double imax, rlength, eta, tstep, ldr, tottime;
  int numseg;
  printf("What is your I max? ");
  scanf("%lf", &imax);
  printf("What is the length of your rod? ");
  scanf("%lf", &rlength);
  printf("What is eta? ");
  scanf("%lf", &eta);
  printf("How many segments would you like? ");
  scanf("%d", &numseg);
  ldr = rlength/(numseg+1);
  tstep = 0.25*ldr*ldr*mu0/eta;
  printf("How long would you like to run? ");
  scanf("%lf", &tottime);

  double *h_rod, *d_rod;
  size_t rod_size = (numseg + 2) * sizeof(double);
  h_rod = (double*)malloc(rod_size);
  hipMalloc(&d_rod, rod_size);

  init<<<1,threadsPerBlock>>>(d_rod, imax, ldr, rlength, numseg + 2);

  int out;
  //output r values
  for(out = 0; out<numseg+1; out++){
    fprintf( myfile, "%lf ", out*ldr );
  }
  fprintf( myfile, "%lf\n", out*ldr );

  hipMemcpy(h_rod, d_rod, rod_size, hipMemcpyDeviceToHost);

  for(out = 0; out<numseg+1; out++){
    fprintf( myfile, "%lf ", *(h_rod+out) );
  }
  fprintf( myfile, "%lf\n", *(h_rod+out) );

  double aug = eta*tstep/(mu0*ldr*ldr);
  long int total_steps = tottime / tstep;
  printf("\nSteps: %ld\n", total_steps);


  clock_t begin, end;
  double time_spent;
  begin = clock();

  //run
  run<<<1,threadsPerBlock, (numseg+2)*sizeof(double)>>>(d_rod, aug, total_steps, numseg+2);
  hipDeviceSynchronize();

  end = clock();
  time_spent = (double)(end - begin) / CLOCKS_PER_SEC;

  hipMemcpy(h_rod, d_rod, rod_size, hipMemcpyDeviceToHost);

  for(out = 0; out<numseg+1; out++){
    fprintf( myfile, "%lf ", *(h_rod+out) );
  }
  fprintf( myfile, "%lf\n", *(h_rod+out) );

  fprintf(myfile, "STOP\n");
  fclose(myfile);

  free(h_rod);
  hipFree(d_rod);



  cout << "\n------------------------------------\nExecution took: "<<  time_spent << " sec\n";

  return 0;
}

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

                                        # End of file scope inline assembly
	.globl	_Z19__device_stub__initPddddi   # -- Begin function _Z19__device_stub__initPddddi
	.type	_Z19__device_stub__initPddddi,@function
_Z19__device_stub__initPddddi:          # @_Z19__device_stub__initPddddi
	.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	$144, %rsp
	.cfi_def_cfa_offset 192
	.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), %rcx
	movsd	%xmm0, (%rcx)
	leaq	40(%rsp), %rdx
	movsd	%xmm1, (%rdx)
	leaq	32(%rsp), %rdi
	movsd	%xmm2, (%rdi)
	leaq	12(%rsp), %r8
	movl	%esi, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rdx, 16(%rbx)
	movq	%rdi, 24(%rbx)
	movq	%r8, 32(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%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	$_Z4initPddddi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	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	_Z19__device_stub__initPddddi, .Lfunc_end0-_Z19__device_stub__initPddddi
	.cfi_endproc
                                        # -- End function
	.globl	_Z18__device_stub__runPddli     # -- Begin function _Z18__device_stub__runPddli
	.type	_Z18__device_stub__runPddli,@function
_Z18__device_stub__runPddli:            # @_Z18__device_stub__runPddli
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movsd	%xmm0, (%rcx)
	leaq	24(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	4(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rdi, 16(%rbx)
	movq	%rsi, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z3runPddli, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z18__device_stub__runPddli, .Lfunc_end1-_Z18__device_stub__runPddli
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI2_0:
	.quad	0x3fd0000000000000              # double 0.25
.LCPI2_1:
	.quad	0x4010000000000000              # double 4
.LCPI2_2:
	.quad	0x400921fb54442d18              # double 3.1415926535897931
.LCPI2_3:
	.quad	0x3e7ad7f29abcaf48              # double 9.9999999999999995E-8
.LCPI2_4:
	.quad	0x3eb515370f99f6cb              # double 1.2566370614359173E-6
.LCPI2_5:
	.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
	movabsq	$4294967297, %rbp               # imm = 0x100000001
	movl	$.L.str, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, %rbx
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	64(%rsp), %rsi
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movl	$.L.str.4, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	56(%rsp), %r12
	movl	$.L.str.3, %edi
	movq	%r12, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	48(%rsp), %r14
	movl	$.L.str.3, %edi
	movq	%r14, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	4(%rsp), %r15
	movl	$.L.str.7, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movsd	(%r12), %xmm1                   # xmm1 = mem[0],zero
	movl	(%r15), %eax
	incl	%eax
	cvtsi2sd	%eax, %xmm0
	divsd	%xmm0, %xmm1
	movsd	.LCPI2_0(%rip), %xmm0           # xmm0 = mem[0],zero
	mulsd	%xmm1, %xmm0
	movsd	%xmm1, 8(%rsp)                  # 8-byte Spill
	mulsd	%xmm1, %xmm0
	mulsd	.LCPI2_1(%rip), %xmm0
	mulsd	.LCPI2_2(%rip), %xmm0
	mulsd	.LCPI2_3(%rip), %xmm0
	divsd	(%r14), %xmm0
	movsd	%xmm0, 24(%rsp)                 # 8-byte Spill
	movl	$.L.str.8, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	40(%rsp), %rsi
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movslq	(%r15), %rax
	leaq	16(,%rax,8), %r12
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r14
	leaq	16(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	1023(%rbp), %r13
	movq	%rbp, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_2
# %bb.1:
	movq	16(%rsp), %rdi
	movsd	64(%rsp), %xmm0                 # xmm0 = mem[0],zero
	movsd	56(%rsp), %xmm2                 # xmm2 = mem[0],zero
	movl	4(%rsp), %esi
	addl	$2, %esi
	movsd	8(%rsp), %xmm1                  # 8-byte Reload
                                        # xmm1 = mem[0],zero
	callq	_Z19__device_stub__initPddddi
.LBB2_2:
	cmpl	$0, 4(%rsp)
	js	.LBB2_3
# %bb.4:                                # %.lr.ph.preheader
	movl	$-1, %ebp
	movsd	8(%rsp), %xmm1                  # 8-byte Reload
                                        # xmm1 = mem[0],zero
.LBB2_5:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	incl	%ebp
	xorps	%xmm0, %xmm0
	cvtsi2sd	%ebp, %xmm0
	mulsd	%xmm1, %xmm0
	movl	$.L.str.9, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	movsd	8(%rsp), %xmm1                  # 8-byte Reload
                                        # xmm1 = mem[0],zero
	cmpl	4(%rsp), %ebp
	jl	.LBB2_5
# %bb.6:                                # %._crit_edge.loopexit
	incl	%ebp
	xorps	%xmm0, %xmm0
	cvtsi2sd	%ebp, %xmm0
	jmp	.LBB2_7
.LBB2_3:
	xorpd	%xmm0, %xmm0
	movsd	8(%rsp), %xmm1                  # 8-byte Reload
                                        # xmm1 = mem[0],zero
.LBB2_7:                                # %._crit_edge
	mulsd	%xmm1, %xmm0
	movl	$.L.str.10, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	movq	16(%rsp), %rsi
	movq	%r14, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	cmpl	$0, 4(%rsp)
	js	.LBB2_8
# %bb.9:                                # %.lr.ph69.preheader
	xorl	%r15d, %r15d
.LBB2_10:                               # %.lr.ph69
                                        # =>This Inner Loop Header: Depth=1
	movsd	(%r14,%r15,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.9, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	leaq	1(%r15), %rax
	movslq	4(%rsp), %rcx
	cmpq	%rcx, %r15
	movq	%rax, %r15
	jl	.LBB2_10
	jmp	.LBB2_11
.LBB2_8:
	xorl	%eax, %eax
.LBB2_11:                               # %._crit_edge70
	movsd	(%r14,%rax,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.10, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	movsd	48(%rsp), %xmm0                 # xmm0 = mem[0],zero
	movsd	%xmm0, 32(%rsp)                 # 8-byte Spill
	movsd	40(%rsp), %xmm0                 # xmm0 = mem[0],zero
	divsd	24(%rsp), %xmm0                 # 8-byte Folded Reload
	cvttsd2si	%xmm0, %r15
	movl	$.L.str.11, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	printf
	callq	clock
	movq	%rax, %rbp
	movslq	4(%rsp), %rax
	leaq	16(,%rax,8), %r8
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_13
# %bb.12:
	movsd	24(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	mulsd	32(%rsp), %xmm0                 # 8-byte Folded Reload
	movsd	.LCPI2_4(%rip), %xmm2           # xmm2 = mem[0],zero
	movsd	8(%rsp), %xmm1                  # 8-byte Reload
                                        # xmm1 = mem[0],zero
	mulsd	%xmm1, %xmm2
	mulsd	%xmm1, %xmm2
	divsd	%xmm2, %xmm0
	movq	16(%rsp), %rdi
	movl	4(%rsp), %edx
	addl	$2, %edx
	movq	%r15, %rsi
	callq	_Z18__device_stub__runPddli
.LBB2_13:
	callq	hipDeviceSynchronize
	callq	clock
	movq	%rax, %r15
	movq	16(%rsp), %rsi
	movq	%r14, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	cmpl	$0, 4(%rsp)
	js	.LBB2_14
# %bb.15:                               # %.lr.ph75.preheader
	xorl	%r12d, %r12d
.LBB2_16:                               # %.lr.ph75
                                        # =>This Inner Loop Header: Depth=1
	movsd	(%r14,%r12,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.9, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	leaq	1(%r12), %rax
	movslq	4(%rsp), %rcx
	cmpq	%rcx, %r12
	movq	%rax, %r12
	jl	.LBB2_16
	jmp	.LBB2_17
.LBB2_14:
	xorl	%eax, %eax
.LBB2_17:                               # %._crit_edge76
	subq	%rbp, %r15
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r15, %xmm0
	divsd	.LCPI2_5(%rip), %xmm0
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	movsd	(%r14,%rax,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.10, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	movl	$.L.str.12, %edi
	movl	$5, %esi
	movl	$1, %edx
	movq	%rbx, %rcx
	callq	fwrite@PLT
	movq	%rbx, %rdi
	callq	fclose
	movq	%r14, %rdi
	callq	free
	movq	16(%rsp), %rdi
	callq	hipFree
	movl	$_ZSt4cout, %edi
	movl	$.L.str.13, %esi
	movl	$54, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movl	$.L.str.14, %esi
	movl	$5, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	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_end2:
	.size	main, .Lfunc_end2-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	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z4initPddddi, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z3runPddli, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__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	.LBB4_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
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z4initPddddi,@object           # @_Z4initPddddi
	.section	.rodata,"a",@progbits
	.globl	_Z4initPddddi
	.p2align	3, 0x0
_Z4initPddddi:
	.quad	_Z19__device_stub__initPddddi
	.size	_Z4initPddddi, 8

	.type	_Z3runPddli,@object             # @_Z3runPddli
	.globl	_Z3runPddli
	.p2align	3, 0x0
_Z3runPddli:
	.quad	_Z18__device_stub__runPddli
	.size	_Z3runPddli, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"results.txt"
	.size	.L.str, 12

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

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"What is your I max? "
	.size	.L.str.2, 21

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"%lf"
	.size	.L.str.3, 4

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"What is the length of your rod? "
	.size	.L.str.4, 33

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"What is eta? "
	.size	.L.str.5, 14

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"How many segments would you like? "
	.size	.L.str.6, 35

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

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"How long would you like to run? "
	.size	.L.str.8, 33

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"%lf "
	.size	.L.str.9, 5

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"%lf\n"
	.size	.L.str.10, 5

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"\nSteps: %ld\n"
	.size	.L.str.11, 13

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

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"\n------------------------------------\nExecution took: "
	.size	.L.str.13, 55

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	" sec\n"
	.size	.L.str.14, 6

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

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z3runPddli"
	.size	.L__unnamed_2, 12

	.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 _Z19__device_stub__initPddddi
	.addrsig_sym _Z18__device_stub__runPddli
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z4initPddddi
	.addrsig_sym _Z3runPddli
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z4initPddddi           ; -- Begin function _Z4initPddddi
	.globl	_Z4initPddddi
	.p2align	8
	.type	_Z4initPddddi,@function
_Z4initPddddi:                          ; @_Z4initPddddi
; %bb.0:
	s_load_b32 s2, s[0:1], 0x20
                                        ; implicit-def: $vgpr9
                                        ; implicit-def: $vgpr1
	s_waitcnt lgkmcnt(0)
	s_ashr_i32 s3, s2, 31
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_lshr_b32 s3, s3, 22
	s_add_i32 s4, s2, s3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s3, s4, 0xfffffc00
	s_sub_i32 s3, s2, s3
	s_ashr_i32 s2, s4, 10
	s_mov_b32 s4, exec_lo
	v_cmpx_le_u32_e64 s3, v0
	s_xor_b32 s4, exec_lo, s4
; %bb.1:
	v_mad_i32_i24 v1, s2, v0, s3
                                        ; implicit-def: $vgpr0
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v9, s2, v1
; %bb.2:                                ; %Flow46
	s_and_not1_saveexec_b32 s3, s4
; %bb.3:
	s_add_i32 s2, s2, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	v_mul_i32_i24_e32 v1, s2, v0
	v_mad_i32_i24 v9, s2, v0, s2
; %bb.4:
	s_or_b32 exec_lo, exec_lo, s3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_mov_b32 s2, exec_lo
	v_cmpx_lt_i32_e64 v1, v9
	s_cbranch_execz .LBB0_7
; %bb.5:                                ; %.lr.ph
	s_load_b256 s[0:7], s[0:1], 0x0
	s_mov_b32 s9, 0x402921fb
	s_mov_b32 s8, 0x54442d18
	s_waitcnt lgkmcnt(0)
	v_mul_f64 v[2:3], 0x40080000, s[6:7]
	v_mul_f64 v[5:6], s[6:7], s[8:9]
	s_mov_b32 s9, 0x400921fb
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f64 v[3:4], v[2:3], s[6:7]
	v_mul_f64 v[5:6], v[5:6], s[6:7]
	v_ashrrev_i32_e32 v2, 31, v1
	s_mov_b32 s6, 0x9abcaf48
	s_mov_b32 s7, 0x3e7ad7f2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[7:8], 3, v[1:2]
	v_add_co_u32 v7, vcc_lo, s0, v7
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v8, vcc_lo, s1, v8, vcc_lo
	s_mov_b32 s1, 0
.LBB0_6:                                ; =>This Inner Loop Header: Depth=1
	v_mul_lo_u32 v0, v1, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_f64_i32_e32 v[10:11], v0
	v_mul_f64 v[10:11], v[10:11], s[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[10:11], v[10:11], s[4:5]
	v_div_scale_f64 v[12:13], null, v[3:4], v[3:4], v[10:11]
	v_div_scale_f64 v[18:19], vcc_lo, v[10:11], v[3:4], v[10:11]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f64_e32 v[14:15], v[12:13]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[16:17], -v[12:13], v[14:15], 1.0
	v_fma_f64 v[14:15], v[14:15], v[16:17], v[14:15]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[16:17], -v[12:13], v[14:15], 1.0
	v_fma_f64 v[14:15], v[14:15], v[16:17], v[14:15]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[16:17], v[18:19], v[14:15]
	v_fma_f64 v[12:13], -v[12:13], v[16:17], v[18:19]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f64 v[12:13], v[12:13], v[14:15], v[16:17]
	v_div_fixup_f64 v[10:11], v[12:13], v[3:4], v[10:11]
	v_cvt_f64_i32_e32 v[12:13], v1
	v_add_nc_u32_e32 v1, 1, v1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f64 v[10:11], -v[10:11], 1.0
	v_mul_f64 v[10:11], 0x40080000, v[10:11]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[10:11], v[10:11], 4.0
	v_mul_f64 v[10:11], v[10:11], s[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[10:11], v[10:11], s[6:7]
	v_mul_f64 v[10:11], v[10:11], s[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[10:11], v[10:11], v[12:13]
	v_mul_f64 v[10:11], v[10:11], s[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_div_scale_f64 v[12:13], null, v[5:6], v[5:6], v[10:11]
	v_div_scale_f64 v[18:19], vcc_lo, v[10:11], v[5:6], v[10:11]
	v_rcp_f64_e32 v[14:15], v[12:13]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[16:17], -v[12:13], v[14:15], 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[14:15], v[14:15], v[16:17], v[14:15]
	v_fma_f64 v[16:17], -v[12:13], v[14:15], 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[14:15], v[14:15], v[16:17], v[14:15]
	v_mul_f64 v[16:17], v[18:19], v[14:15]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[12:13], -v[12:13], v[16:17], v[18:19]
	v_div_fmas_f64 v[12:13], v[12:13], v[14:15], v[16:17]
	v_cmp_ge_i32_e32 vcc_lo, v1, v9
	s_or_b32 s1, vcc_lo, s1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_div_fixup_f64 v[10:11], v[12:13], v[5:6], v[10:11]
	global_store_b64 v[7:8], v[10:11], off
	v_add_co_u32 v7, s0, v7, 8
	v_add_co_ci_u32_e64 v8, s0, 0, v8, s0
	s_and_not1_b32 exec_lo, exec_lo, s1
	s_cbranch_execnz .LBB0_6
.LBB0_7:                                ; %Flow45
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z4initPddddi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 36
		.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 20
		.amdhsa_next_free_sgpr 10
		.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	_Z4initPddddi, .Lfunc_end0-_Z4initPddddi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 648
; NumSgprs: 12
; NumVgprs: 20
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 12
; NumVGPRsForWavesPerEU: 20
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z3runPddli             ; -- Begin function _Z3runPddli
	.globl	_Z3runPddli
	.p2align	8
	.type	_Z3runPddli,@function
_Z3runPddli:                            ; @_Z3runPddli
; %bb.0:
	s_load_b32 s10, s[0:1], 0x18
	s_mov_b32 s4, exec_lo
                                        ; implicit-def: $vgpr4
                                        ; implicit-def: $vgpr1
	s_waitcnt lgkmcnt(0)
	s_ashr_i32 s2, s10, 31
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_lshr_b32 s2, s2, 22
	s_add_i32 s2, s10, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	s_and_b32 s3, s2, 0xfffffc00
	s_ashr_i32 s2, s2, 10
	s_sub_i32 s3, s10, s3
	v_cmpx_le_u32_e64 s3, v0
	s_xor_b32 s4, exec_lo, s4
; %bb.1:
	v_mad_i32_i24 v1, s2, v0, s3
                                        ; implicit-def: $vgpr0
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v4, s2, v1
; %bb.2:                                ; %Flow120
	s_and_not1_saveexec_b32 s3, s4
; %bb.3:
	s_add_i32 s2, s2, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	v_mul_i32_i24_e32 v1, s2, v0
	v_mad_i32_i24 v4, s2, v0, s2
; %bb.4:
	s_or_b32 exec_lo, exec_lo, s3
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[2:3], s[0:1], 0x10
	v_cmp_lt_i32_e64 s0, v1, v4
	v_lshl_add_u32 v0, v1, 3, 0
	s_delay_alu instid0(VALU_DEP_2)
	s_and_saveexec_b32 s8, s0
	s_cbranch_execz .LBB1_7
; %bb.5:                                ; %.lr.ph.preheader
	v_ashrrev_i32_e32 v2, 31, v1
	v_lshl_add_u32 v5, v1, 3, 0
	v_mov_b32_e32 v6, v1
	s_mov_b32 s9, 0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 3, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v2, vcc_lo, s4, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
.LBB1_6:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	global_load_b64 v[7:8], v[2:3], off
	v_add_nc_u32_e32 v6, 1, v6
	v_add_co_u32 v2, vcc_lo, v2, 8
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_ge_i32_e64 s1, v6, v4
	s_or_b32 s9, s1, s9
	s_waitcnt vmcnt(0)
	ds_store_b64 v5, v[7:8]
	v_add_nc_u32_e32 v5, 8, v5
	s_and_not1_b32 exec_lo, exec_lo, s9
	s_cbranch_execnz .LBB1_6
.LBB1_7:                                ; %Flow119
	s_or_b32 exec_lo, exec_lo, s8
	s_waitcnt lgkmcnt(0)
	v_cmp_lt_i64_e64 s1, s[2:3], 1
	s_barrier
	buffer_gl0_inv
	s_and_b32 vcc_lo, exec_lo, s1
	s_cbranch_vccnz .LBB1_24
; %bb.8:                                ; %.preheader59.lr.ph
	v_lshl_add_u32 v5, v1, 3, 0
	s_add_i32 s10, s10, -1
	s_mov_b64 s[8:9], 0
	s_add_i32 s11, 0, 8
	s_delay_alu instid0(VALU_DEP_1)
	v_dual_mov_b32 v7, 0 :: v_dual_add_nc_u32 v6, -8, v5
.LBB1_9:                                ; %.preheader59
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB1_11 Depth 2
                                        ;     Child Loop BB1_14 Depth 2
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB1_12
; %bb.10:                               ; %.lr.ph62.preheader
                                        ;   in Loop: Header=BB1_9 Depth=1
	v_mov_b32_e32 v2, v5
	v_mov_b32_e32 v3, v5
	v_mov_b32_e32 v8, v1
	s_mov_b32 s12, 0
.LBB1_11:                               ; %.lr.ph62
                                        ;   Parent Loop BB1_9 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	ds_load_b64 v[9:10], v3
	v_add_nc_u32_e32 v8, 1, v8
	v_add_nc_u32_e32 v3, 8, v3
	s_delay_alu instid0(VALU_DEP_2)
	v_cmp_ge_i32_e32 vcc_lo, v8, v4
	s_or_b32 s12, vcc_lo, s12
	s_waitcnt lgkmcnt(0)
	ds_store_b64 v2, v[9:10]
	v_add_nc_u32_e32 v2, 8, v2
	s_and_not1_b32 exec_lo, exec_lo, s12
	s_cbranch_execnz .LBB1_11
.LBB1_12:                               ; %Flow115
                                        ;   in Loop: Header=BB1_9 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s12, s0
	s_cbranch_execz .LBB1_23
; %bb.13:                               ; %.lr.ph66.preheader
                                        ;   in Loop: Header=BB1_9 Depth=1
	v_dual_mov_b32 v8, v5 :: v_dual_mov_b32 v9, v6
	v_mov_b32_e32 v10, v1
	s_mov_b32 s13, 0
.LBB1_14:                               ; %.lr.ph66
                                        ;   Parent Loop BB1_9 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_mov_b32 s1, 0
	s_mov_b32 s14, exec_lo
                                        ; implicit-def: $vgpr2_vgpr3
                                        ; implicit-def: $vgpr11
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_ne_u32_e32 1, v10
	s_xor_b32 s14, exec_lo, s14
	s_cbranch_execz .LBB1_18
; %bb.15:                               ;   in Loop: Header=BB1_14 Depth=2
	v_cmp_gt_i32_e32 vcc_lo, s10, v10
	v_cmp_lt_i32_e64 s1, 1, v10
                                        ; implicit-def: $vgpr2_vgpr3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	s_and_b32 s15, vcc_lo, s1
	s_mov_b32 s1, 0
	s_and_saveexec_b32 s16, s15
	s_xor_b32 s15, exec_lo, s16
	s_cbranch_execz .LBB1_17
; %bb.16:                               ;   in Loop: Header=BB1_14 Depth=2
	v_mul_lo_u32 v2, v10, v10
	ds_load_b64 v[15:16], v9 offset:16
	ds_load_2addr_b64 v[11:14], v9 offset1:1
	s_mov_b32 s1, exec_lo
	v_add_nc_u32_e32 v3, 1, v2
	v_sub_nc_u32_e32 v2, -2, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_u32_e32 vcc_lo, 3, v3
	v_cndmask_b32_e32 v2, -2, v2, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cvt_f64_i32_e32 v[2:3], v2
	s_waitcnt lgkmcnt(0)
	v_fma_f64 v[2:3], v[13:14], v[2:3], v[15:16]
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f64 v[2:3], v[11:12], v[2:3]
.LBB1_17:                               ; %Flow110
                                        ;   in Loop: Header=BB1_14 Depth=2
	s_or_b32 exec_lo, exec_lo, s15
	v_mov_b32_e32 v11, v8
	s_and_b32 s1, s1, exec_lo
.LBB1_18:                               ; %Flow109
                                        ;   in Loop: Header=BB1_14 Depth=2
	s_and_not1_saveexec_b32 s14, s14
	s_cbranch_execz .LBB1_20
; %bb.19:                               ;   in Loop: Header=BB1_14 Depth=2
	ds_load_2addr_b64 v[11:14], v7 offset0:1 offset1:2
	s_or_b32 s1, s1, exec_lo
	s_waitcnt lgkmcnt(0)
	v_mul_f64 v[2:3], v[11:12], -4.0
	v_mov_b32_e32 v11, s11
	s_delay_alu instid0(VALU_DEP_2)
	v_fma_f64 v[2:3], v[13:14], 2.0, v[2:3]
.LBB1_20:                               ; %Flow111
                                        ;   in Loop: Header=BB1_14 Depth=2
	s_or_b32 exec_lo, exec_lo, s14
	s_and_saveexec_b32 s14, s1
	s_cbranch_execz .LBB1_22
; %bb.21:                               ; %.sink.split
                                        ;   in Loop: Header=BB1_14 Depth=2
	ds_load_b64 v[12:13], v11
	s_waitcnt lgkmcnt(0)
	v_fma_f64 v[2:3], v[2:3], s[6:7], v[12:13]
	ds_store_b64 v11, v[2:3]
.LBB1_22:                               ;   in Loop: Header=BB1_14 Depth=2
	s_or_b32 exec_lo, exec_lo, s14
	v_add_nc_u32_e32 v10, 1, v10
	v_add_nc_u32_e32 v9, 8, v9
	v_add_nc_u32_e32 v8, 8, v8
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_ge_i32_e32 vcc_lo, v10, v4
	s_or_b32 s13, vcc_lo, s13
	s_and_not1_b32 exec_lo, exec_lo, s13
	s_cbranch_execnz .LBB1_14
.LBB1_23:                               ; %Flow113
                                        ;   in Loop: Header=BB1_9 Depth=1
	s_or_b32 exec_lo, exec_lo, s12
	s_add_u32 s8, s8, 1
	s_addc_u32 s9, s9, 0
	s_waitcnt lgkmcnt(0)
	s_cmp_eq_u64 s[8:9], s[2:3]
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB1_9
.LBB1_24:                               ; %.preheader
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB1_27
; %bb.25:                               ; %.lr.ph70.preheader
	v_ashrrev_i32_e32 v2, 31, v1
	s_mov_b32 s1, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 3, v[1:2]
	v_add_co_u32 v2, vcc_lo, s4, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
.LBB1_26:                               ; %.lr.ph70
                                        ; =>This Inner Loop Header: Depth=1
	ds_load_b64 v[5:6], v0
	v_add_nc_u32_e32 v1, 1, v1
	v_add_nc_u32_e32 v0, 8, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	v_cmp_ge_i32_e32 vcc_lo, v1, v4
	s_or_b32 s1, vcc_lo, s1
	s_waitcnt lgkmcnt(0)
	global_store_b64 v[2:3], v[5:6], off
	v_add_co_u32 v2, s0, v2, 8
	v_add_co_ci_u32_e64 v3, s0, 0, v3, s0
	s_and_not1_b32 exec_lo, exec_lo, s1
	s_cbranch_execnz .LBB1_26
.LBB1_27:                               ; %Flow108
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z3runPddli
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 28
		.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 17
		.amdhsa_next_free_sgpr 17
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z3runPddli, .Lfunc_end1-_Z3runPddli
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 892
; NumSgprs: 19
; NumVgprs: 17
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 19
; NumVGPRsForWavesPerEU: 17
; 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
      - .offset:         8
        .size:           8
        .value_kind:     by_value
      - .offset:         16
        .size:           8
        .value_kind:     by_value
      - .offset:         24
        .size:           8
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 36
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z4initPddddi
    .private_segment_fixed_size: 0
    .sgpr_count:     12
    .sgpr_spill_count: 0
    .symbol:         _Z4initPddddi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     20
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           8
        .value_kind:     by_value
      - .offset:         16
        .size:           8
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 28
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z3runPddli
    .private_segment_fixed_size: 0
    .sgpr_count:     19
    .sgpr_spill_count: 0
    .symbol:         _Z3runPddli.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     17
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
