#include <iostream>
#include <fstream>
#include <cstdio>
#include <chrono>
#include <cmath>

void init(double* const __restrict__ a, double* const __restrict__ at, const int ncells)
{
    for (int i=0; i<ncells; ++i)
    {
        a[i] = pow(i,2)/pow(i+1,2);
        at[i] = 0.;
    }
}

void diff(double* const __restrict__ at, const double* const __restrict__ a, const double visc,
          const double dxidxi, const double dyidyi, const double dzidzi,
          const int itot, const int jtot, const int ktot)
{
    const int ii = 1;
    const int jj = itot;
    const int kk = itot*jtot;

    #pragma acc parallel loop present(a, at) collapse(3)
    for (int k=1; k<ktot-1; ++k)
        for (int j=1; j<jtot-1; ++j)
            for (int i=1; i<itot-1; ++i)
            {
                const int ijk = i + j*jj + k*kk;
                at[ijk] += visc * (
                        + ( (a[ijk+ii] - a[ijk   ])
                          - (a[ijk   ] - a[ijk-ii]) ) * dxidxi
                        + ( (a[ijk+jj] - a[ijk   ])
                          - (a[ijk   ] - a[ijk-jj]) ) * dyidyi
                        + ( (a[ijk+kk] - a[ijk   ])
                          - (a[ijk   ] - a[ijk-kk]) ) * dzidzi
                        );
            }
}

int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        std::cout << "Add the grid size as an argument!" << std::endl;
        return 1;
    }

    const int nloop = 30;
    const int itot = std::stoi(argv[1]);
    const int jtot = std::stoi(argv[1]);
    const int ktot = std::stoi(argv[1]);
    const int ncells = itot*jtot*ktot;

    double *a  = new double[ncells];
    double *at = new double[ncells];
   
    init(a, at, ncells);

    #pragma acc data copyin(at[0:ncells], a[0:ncells]) copyout(at[0:ncells])
    {
        // Check results
        diff(
                at, a,
                0.1, 0.1, 0.1, 0.1,
                itot, jtot, ktot);
    }
 
    printf("at=%.20f\n",at[itot*jtot+itot+itot/2]);
 
    #pragma acc data copyin(at[0:ncells], a[0:ncells]) copyout(at[0:ncells])
    {
        // Time performance
        auto start = std::chrono::high_resolution_clock::now();

        for (int i=0; i<nloop; ++i)
            diff(
                    at, a,
                    0.1, 0.1, 0.1, 0.1,
                    itot, jtot, ktot);

        auto end = std::chrono::high_resolution_clock::now();
        double duration = std::chrono::duration_cast<std::chrono::duration<double>>(end - start).count();

        printf("time/iter = %E s (%i iters)\n",duration/(double)nloop, nloop);
    }

    printf("at=%.20f\n", at[itot*jtot+itot+itot/4]);

    return 0;
}

	.file	"tmpxft_00321eb2_00000000-6_diff_acc.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3872:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3872:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z4initPdS_i
	.type	_Z4initPdS_i, @function
_Z4initPdS_i:
.LFB3865:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
.L3:
	cmpl	%eax, %edx
	jle	.L6
	cvtsi2sdl	%eax, %xmm0
	leal	1(%rax), %ecx
	movq	$0x000000000, (%rsi,%rax,8)
	cvtsi2sdl	%ecx, %xmm1
	mulsd	%xmm0, %xmm0
	mulsd	%xmm1, %xmm1
	divsd	%xmm1, %xmm0
	movsd	%xmm0, (%rdi,%rax,8)
	incq	%rax
	jmp	.L3
.L6:
	ret
	.cfi_endproc
.LFE3865:
	.size	_Z4initPdS_i, .-_Z4initPdS_i
	.globl	_Z4diffPdPKdddddiii
	.type	_Z4diffPdPKdddddiii, @function
_Z4diffPdPKdddddiii:
.LFB3866:
	.cfi_startproc
	endbr64
	movl	%edx, %r11d
	movl	%ecx, %eax
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movaps	%xmm0, %xmm6
	imull	%ecx, %r11d
	movslq	%edx, %rcx
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	decl	%eax
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	salq	$3, %rcx
	movq	%rsi, %r14
	movl	$1, %r10d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	(%rsi,%rcx), %r12
	leal	-1(%rdx), %r15d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	subq	%rcx, %rbx
	movslq	%r11d, %rcx
	movq	%rbx, %rbp
	leal	-1(%r8), %ebx
	salq	$3, %rcx
	movl	%ebx, -8(%rsp)
	leaq	(%rsi,%rcx), %r13
	subq	%rcx, %r14
	movl	%r11d, %ecx
	movl	%eax, -4(%rsp)
.L8:
	cmpl	%r10d, -8(%rsp)
	jle	.L7
	movslq	%ecx, %rax
	movl	%edx, %r9d
	movl	$1, %r8d
	movq	%rax, -16(%rsp)
.L13:
	cmpl	%r8d, -4(%rsp)
	jle	.L10
	movq	-16(%rsp), %rbx
	movslq	%r9d, %rax
	addq	%rbx, %rax
	movl	$1, %ebx
	salq	$3, %rax
.L11:
	addq	$8, %rax
	cmpl	%ebx, %r15d
	jle	.L15
	movsd	(%rsi,%rax), %xmm4
	movsd	8(%rsi,%rax), %xmm0
	incl	%ebx
	subsd	%xmm4, %xmm0
	movaps	%xmm4, %xmm5
	subsd	-8(%rsi,%rax), %xmm5
	movaps	%xmm4, %xmm7
	subsd	0(%rbp,%rax), %xmm7
	subsd	%xmm5, %xmm0
	movsd	(%r12,%rax), %xmm5
	subsd	%xmm4, %xmm5
	mulsd	%xmm1, %xmm0
	subsd	%xmm7, %xmm5
	mulsd	%xmm2, %xmm5
	addsd	%xmm5, %xmm0
	movsd	0(%r13,%rax), %xmm5
	subsd	%xmm4, %xmm5
	subsd	(%r14,%rax), %xmm4
	subsd	%xmm4, %xmm5
	movaps	%xmm5, %xmm4
	mulsd	%xmm3, %xmm4
	addsd	%xmm4, %xmm0
	mulsd	%xmm6, %xmm0
	addsd	(%rdi,%rax), %xmm0
	movsd	%xmm0, (%rdi,%rax)
	jmp	.L11
.L15:
	incl	%r8d
	addl	%edx, %r9d
	jmp	.L13
.L10:
	incl	%r10d
	addl	%r11d, %ecx
	jmp	.L8
.L7:
	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
.LFE3866:
	.size	_Z4diffPdPKdddddiii, .-_Z4diffPdPKdddddiii
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3895:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3895:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text._ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev,"axG",@progbits,_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD5Ev,comdat
	.align 2
	.weak	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev
	.type	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev, @function
_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev:
.LFB3974:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	call	__errno_location@PLT
	cmpl	$0, (%rax)
	jne	.L18
	movl	(%rbx), %edx
	movl	%edx, (%rax)
.L18:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3974:
	.size	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev, .-_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev
	.weak	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD1Ev
	.set	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD1Ev,_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"stoi"
	.text
	.type	_ZNSt7__cxx114stoiERKNS_12basic_stringIcSt11char_traitsIcESaIcEEEPmi.isra.0, @function
_ZNSt7__cxx114stoiERKNS_12basic_stringIcSt11char_traitsIcESaIcEEEPmi.isra.0:
.LFB4597:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4597
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdi, %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 96
	movl	%edx, 12(%rsp)
	leaq	28(%rsp), %r13
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	__errno_location@PLT
	movl	12(%rsp), %edx
	leaq	32(%rsp), %rsi
	movq	%rbx, %rdi
	movq	%rax, %rbp
	movl	(%rax), %eax
	movl	%eax, 28(%rsp)
	xorl	%eax, %eax
	movl	%eax, 0(%rbp)
	call	__isoc23_strtol@PLT
	movq	32(%rsp), %rdx
	cmpq	%rdx, %rbx
	jne	.L22
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L35
	leaq	.LC1(%rip), %rdi
.LEHB0:
	call	_ZSt24__throw_invalid_argumentPKc@PLT
.L22:
	cmpl	$34, 0(%rbp)
	je	.L24
	movl	$2147483648, %ecx
	movl	$4294967295, %esi
	addq	%rax, %rcx
	cmpq	%rcx, %rsi
	jnb	.L25
.L24:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L35
	leaq	.LC1(%rip), %rdi
	call	_ZSt20__throw_out_of_rangePKc@PLT
.LEHE0:
.L25:
	testq	%r12, %r12
	je	.L27
	subq	%rbx, %rdx
	movq	%rdx, (%r12)
.L27:
	movq	%r13, %rdi
	movl	%eax, 12(%rsp)
	call	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD1Ev
	movl	12(%rsp), %eax
	movq	40(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L30
	jmp	.L35
.L31:
	endbr64
	movq	%rax, %rbx
.L28:
	movq	%r13, %rdi
	call	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD1Ev
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L35
	movq	%rbx, %rdi
.LEHB1:
	call	_Unwind_Resume@PLT
.LEHE1:
.L35:
	call	__stack_chk_fail@PLT
.L30:
	addq	$56, %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
.LFE4597:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA4597:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4597-.LLSDACSB4597
.LLSDACSB4597:
	.uleb128 .LEHB0-.LFB4597
	.uleb128 .LEHE0-.LEHB0
	.uleb128 .L31-.LFB4597
	.uleb128 0
	.uleb128 .LEHB1-.LFB4597
	.uleb128 .LEHE1-.LEHB1
	.uleb128 0
	.uleb128 0
.LLSDACSE4597:
	.text
	.size	_ZNSt7__cxx114stoiERKNS_12basic_stringIcSt11char_traitsIcESaIcEEEPmi.isra.0, .-_ZNSt7__cxx114stoiERKNS_12basic_stringIcSt11char_traitsIcESaIcEEEPmi.isra.0
	.section	.rodata._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_.str1.1,"aMS",@progbits,1
.LC2:
	.string	"basic_string: construction from null is not valid"
	.section	.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,"axG",@progbits,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC5IS3_EEPKcRKS3_,comdat
	.align 2
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.type	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_, @function
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_:
.LFB4243:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	16(%rdi), %rax
	movq	%rax, (%rdi)
	testq	%rsi, %rsi
	jne	.L39
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L44
	leaq	.LC2(%rip), %rdi
	call	_ZSt19__throw_logic_errorPKc@PLT
.L39:
	movq	%rdi, %rbx
	movq	%rsi, %rdi
	movq	%rsi, %rbp
	call	strlen@PLT
	movq	%rax, (%rsp)
	leaq	0(%rbp,%rax), %r12
	cmpq	$15, %rax
	jbe	.L41
	movq	%rsp, %rsi
	xorl	%edx, %edx
	movq	%rbx, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm@PLT
	movq	%rax, (%rbx)
	movq	(%rsp), %rax
	movq	%rax, 16(%rbx)
.L41:
	movq	(%rbx), %rdi
	movq	%r12, %rdx
	movq	%rbp, %rsi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE13_S_copy_charsEPcPKcS7_@PLT
	movq	(%rsp), %rax
	movq	(%rbx), %rdx
	movq	%rax, 8(%rbx)
	movb	$0, (%rdx,%rax)
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L42
.L44:
	call	__stack_chk_fail@PLT
.L42:
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4243:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_, .-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_
	.set	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.section	.rodata.str1.1
.LC3:
	.string	"Add the grid size as an argument!"
.LC5:
	.string	"at=%.20f\n"
.LC8:
	.string	"time/iter = %E s (%i iters)\n"
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB3867:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3867
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	cmpl	$2, %edi
	je	.L46
	leaq	.LC3(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
.LEHB2:
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movl	$1, %eax
	jmp	.L45
.L46:
	movq	%rsi, %r12
	leaq	23(%rsp), %r14
	movq	8(%rsi), %rsi
	leaq	24(%rsp), %rbp
	movq	%r14, %rdx
	movq	%rbp, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_
.LEHE2:
	movq	24(%rsp), %rdi
	movl	$10, %edx
	xorl	%esi, %esi
.LEHB3:
	call	_ZNSt7__cxx114stoiERKNS_12basic_stringIcSt11char_traitsIcESaIcEEEPmi.isra.0
.LEHE3:
	movq	%rbp, %rdi
	movl	%eax, %ebx
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	8(%r12), %rsi
	movq	%r14, %rdx
	movq	%rbp, %rdi
.LEHB4:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_
.LEHE4:
	movq	24(%rsp), %rdi
	movl	$10, %edx
	xorl	%esi, %esi
.LEHB5:
	call	_ZNSt7__cxx114stoiERKNS_12basic_stringIcSt11char_traitsIcESaIcEEEPmi.isra.0
.LEHE5:
	movq	%rbp, %rdi
	movl	%eax, %r13d
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	8(%r12), %rsi
	movq	%r14, %rdx
	movq	%rbp, %rdi
.LEHB6:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_
.LEHE6:
	movq	24(%rsp), %rdi
	movl	$10, %edx
	xorl	%esi, %esi
.LEHB7:
	call	_ZNSt7__cxx114stoiERKNS_12basic_stringIcSt11char_traitsIcESaIcEEEPmi.isra.0
.LEHE7:
	movl	%ebx, %r12d
	movl	%eax, %r14d
	movq	%rbp, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	imull	%r13d, %r12d
	movabsq	$1152921504606846975, %rax
	movl	%r12d, %r15d
	imull	%r14d, %r15d
	movslq	%r15d, %rbp
	cmpq	%rbp, %rax
	jb	.L48
	salq	$3, %rbp
	addl	%ebx, %r12d
	movq	%rbp, %rdi
.LEHB8:
	call	_Znam@PLT
	movq	%rbp, %rdi
	movq	%rax, (%rsp)
	call	_Znam@PLT
	movq	(%rsp), %rdi
	movl	%r15d, %edx
	movl	%r14d, %r8d
	movq	%rax, %rsi
	movq	%rax, %rbp
	call	_Z4initPdS_i
	movq	(%rsp), %rsi
	movl	%r13d, %ecx
	movl	%ebx, %edx
	movsd	.LC4(%rip), %xmm3
	movq	%rbp, %rdi
	movaps	%xmm3, %xmm0
	movaps	%xmm3, %xmm2
	movaps	%xmm3, %xmm1
	call	_Z4diffPdPKdddddiii
	movl	%ebx, %eax
	movl	$2, %ecx
	leaq	.LC5(%rip), %rsi
	cltd
	movl	$2, %edi
	idivl	%ecx
	addl	%r12d, %eax
	cltq
	movsd	0(%rbp,%rax,8), %xmm0
	movb	$1, %al
	call	__printf_chk@PLT
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movq	%rax, %r15
	movl	$30, %eax
	jmp	.L49
.L48:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L64
	call	__cxa_throw_bad_array_new_length@PLT
.L49:
	movsd	.LC4(%rip), %xmm3
	movl	%r14d, %r8d
	movl	%r13d, %ecx
	movl	%ebx, %edx
	movq	(%rsp), %rsi
	movq	%rbp, %rdi
	movl	%eax, 12(%rsp)
	movaps	%xmm3, %xmm2
	movaps	%xmm3, %xmm1
	movaps	%xmm3, %xmm0
	call	_Z4diffPdPKdddddiii
	movl	12(%rsp), %eax
	decl	%eax
	jne	.L49
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	$30, %edx
	movl	$2, %edi
	leaq	.LC8(%rip), %rsi
	subq	%r15, %rax
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	divsd	.LC6(%rip), %xmm0
	divsd	.LC7(%rip), %xmm0
	call	__printf_chk@PLT
	movl	%ebx, %eax
	movl	$4, %ecx
	leaq	.LC5(%rip), %rsi
	cltd
	movl	$2, %edi
	idivl	%ecx
	addl	%r12d, %eax
	cltq
	movsd	0(%rbp,%rax,8), %xmm0
	movb	$1, %al
	call	__printf_chk@PLT
	xorl	%eax, %eax
	jmp	.L45
.L58:
	endbr64
	jmp	.L65
.L59:
	endbr64
	jmp	.L65
.L60:
	endbr64
.L65:
	movq	%rax, %rbx
.L55:
	movq	%rbp, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L64
	movq	%rbx, %rdi
	call	_Unwind_Resume@PLT
.LEHE8:
.L45:
	movq	56(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L57
.L64:
	call	__stack_chk_fail@PLT
.L57:
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3867:
	.section	.gcc_except_table
.LLSDA3867:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3867-.LLSDACSB3867
.LLSDACSB3867:
	.uleb128 .LEHB2-.LFB3867
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB3-.LFB3867
	.uleb128 .LEHE3-.LEHB3
	.uleb128 .L58-.LFB3867
	.uleb128 0
	.uleb128 .LEHB4-.LFB3867
	.uleb128 .LEHE4-.LEHB4
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB5-.LFB3867
	.uleb128 .LEHE5-.LEHB5
	.uleb128 .L59-.LFB3867
	.uleb128 0
	.uleb128 .LEHB6-.LFB3867
	.uleb128 .LEHE6-.LEHB6
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB7-.LFB3867
	.uleb128 .LEHE7-.LEHB7
	.uleb128 .L60-.LFB3867
	.uleb128 0
	.uleb128 .LEHB8-.LFB3867
	.uleb128 .LEHE8-.LEHB8
	.uleb128 0
	.uleb128 0
.LLSDACSE3867:
	.section	.text.startup
	.size	main, .-main
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC4:
	.long	-1717986918
	.long	1069128089
	.align 8
.LC6:
	.long	0
	.long	1104006501
	.align 8
.LC7:
	.long	0
	.long	1077805056
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <iostream>
#include <fstream>
#include <cstdio>
#include <chrono>
#include <cmath>

void init(double* const __restrict__ a, double* const __restrict__ at, const int ncells)
{
    for (int i=0; i<ncells; ++i)
    {
        a[i] = pow(i,2)/pow(i+1,2);
        at[i] = 0.;
    }
}

void diff(double* const __restrict__ at, const double* const __restrict__ a, const double visc,
          const double dxidxi, const double dyidyi, const double dzidzi,
          const int itot, const int jtot, const int ktot)
{
    const int ii = 1;
    const int jj = itot;
    const int kk = itot*jtot;

    #pragma acc parallel loop present(a, at) collapse(3)
    for (int k=1; k<ktot-1; ++k)
        for (int j=1; j<jtot-1; ++j)
            for (int i=1; i<itot-1; ++i)
            {
                const int ijk = i + j*jj + k*kk;
                at[ijk] += visc * (
                        + ( (a[ijk+ii] - a[ijk   ])
                          - (a[ijk   ] - a[ijk-ii]) ) * dxidxi
                        + ( (a[ijk+jj] - a[ijk   ])
                          - (a[ijk   ] - a[ijk-jj]) ) * dyidyi
                        + ( (a[ijk+kk] - a[ijk   ])
                          - (a[ijk   ] - a[ijk-kk]) ) * dzidzi
                        );
            }
}

int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        std::cout << "Add the grid size as an argument!" << std::endl;
        return 1;
    }

    const int nloop = 30;
    const int itot = std::stoi(argv[1]);
    const int jtot = std::stoi(argv[1]);
    const int ktot = std::stoi(argv[1]);
    const int ncells = itot*jtot*ktot;

    double *a  = new double[ncells];
    double *at = new double[ncells];
   
    init(a, at, ncells);

    #pragma acc data copyin(at[0:ncells], a[0:ncells]) copyout(at[0:ncells])
    {
        // Check results
        diff(
                at, a,
                0.1, 0.1, 0.1, 0.1,
                itot, jtot, ktot);
    }
 
    printf("at=%.20f\n",at[itot*jtot+itot+itot/2]);
 
    #pragma acc data copyin(at[0:ncells], a[0:ncells]) copyout(at[0:ncells])
    {
        // Time performance
        auto start = std::chrono::high_resolution_clock::now();

        for (int i=0; i<nloop; ++i)
            diff(
                    at, a,
                    0.1, 0.1, 0.1, 0.1,
                    itot, jtot, ktot);

        auto end = std::chrono::high_resolution_clock::now();
        double duration = std::chrono::duration_cast<std::chrono::duration<double>>(end - start).count();

        printf("time/iter = %E s (%i iters)\n",duration/(double)nloop, nloop);
    }

    printf("at=%.20f\n", at[itot*jtot+itot+itot/4]);

    return 0;
}

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

                                        # End of file scope inline assembly
	.globl	_Z4initPdS_i                    # -- Begin function _Z4initPdS_i
	.type	_Z4initPdS_i,@function
_Z4initPdS_i:                           # @_Z4initPdS_i
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB0_4
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	%edx, %r14d
	leaq	(,%r14,8), %rdx
	xorl	%r15d, %r15d
	movq	%rsi, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r15d, %xmm0
	mulsd	%xmm0, %xmm0
	leaq	1(%r15), %rax
	xorps	%xmm1, %xmm1
	cvtsi2sd	%eax, %xmm1
	mulsd	%xmm1, %xmm1
	divsd	%xmm1, %xmm0
	movsd	%xmm0, (%rbx,%r15,8)
	movq	%rax, %r15
	cmpq	%rax, %r14
	jne	.LBB0_2
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB0_4:                                # %._crit_edge
	retq
.Lfunc_end0:
	.size	_Z4initPdS_i, .Lfunc_end0-_Z4initPdS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z4diffPdPKdddddiii             # -- Begin function _Z4diffPdPKdddddiii
	.type	_Z4diffPdPKdddddiii,@function
_Z4diffPdPKdddddiii:                    # @_Z4diffPdPKdddddiii
	.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
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
                                        # kill: def $ecx killed $ecx def $rcx
	movq	%rcx, -64(%rsp)                 # 8-byte Spill
                                        # kill: def $edx killed $edx def $rdx
	movl	%r8d, -68(%rsp)                 # 4-byte Spill
	cmpl	$3, %r8d
	jl	.LBB1_9
# %bb.1:                                # %.preheader52.lr.ph
	movq	-64(%rsp), %r8                  # 8-byte Reload
	movl	%r8d, %ecx
	imull	%edx, %ecx
	leal	-1(%rdx), %eax
	leal	-2(%r8), %r9d
	addl	$-2, -68(%rsp)                  # 4-byte Folded Spill
	leal	1(%r8), %r10d
	imull	%edx, %r10d
	movq	%r10, -24(%rsp)                 # 8-byte Spill
	movl	%ecx, %ecx
	movl	%edx, %ebx
	leal	2(%r8), %r10d
	imull	%edx, %r10d
	movq	%r10, -32(%rsp)                 # 8-byte Spill
	leal	1(,%r8,2), %r8d
	imull	%edx, %r8d
	movq	%r8, -40(%rsp)                  # 8-byte Spill
	movl	$1, %r8d
	movq	%rbx, -48(%rsp)                 # 8-byte Spill
	movq	%rcx, -16(%rsp)                 # 8-byte Spill
	movq	%rcx, -56(%rsp)                 # 8-byte Spill
.LBB1_2:                                # %.preheader52
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_4 Depth 2
                                        #       Child Loop BB1_6 Depth 3
	movq	%r8, -8(%rsp)                   # 8-byte Spill
	cmpl	$3, -64(%rsp)                   # 4-byte Folded Reload
	jl	.LBB1_8
# %bb.3:                                # %.preheader.lr.ph
                                        #   in Loop: Header=BB1_2 Depth=1
	movl	$1, %ebp
	movq	-48(%rsp), %r12                 # 8-byte Reload
	movq	-40(%rsp), %r15                 # 8-byte Reload
	movq	-56(%rsp), %r13                 # 8-byte Reload
	movq	-32(%rsp), %r14                 # 8-byte Reload
	movq	-24(%rsp), %r10                 # 8-byte Reload
.LBB1_4:                                # %.preheader
                                        #   Parent Loop BB1_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_6 Depth 3
	cmpl	$3, %edx
	jl	.LBB1_7
# %bb.5:                                # %.lr.ph
                                        #   in Loop: Header=BB1_4 Depth=2
	movl	$1, %r8d
.LBB1_6:                                #   Parent Loop BB1_2 Depth=1
                                        #     Parent Loop BB1_4 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	leal	(%r10,%r8), %r11d
	movslq	%r11d, %r11
	movsd	(%rsi,%r11,8), %xmm4            # xmm4 = mem[0],zero
	movsd	8(%rsi,%r11,8), %xmm6           # xmm6 = mem[0],zero
	subsd	%xmm4, %xmm6
	movapd	%xmm4, %xmm5
	subsd	-8(%rsi,%r11,8), %xmm5
	subsd	%xmm5, %xmm6
	mulsd	%xmm1, %xmm6
	leal	(%r14,%r8), %ecx
	movslq	%ecx, %rcx
	movsd	(%rsi,%rcx,8), %xmm5            # xmm5 = mem[0],zero
	subsd	%xmm4, %xmm5
	leal	(%r13,%r8), %ecx
	movslq	%ecx, %rcx
	movapd	%xmm4, %xmm7
	subsd	(%rsi,%rcx,8), %xmm7
	subsd	%xmm7, %xmm5
	mulsd	%xmm2, %xmm5
	addsd	%xmm6, %xmm5
	leal	(%r15,%r8), %ecx
	movslq	%ecx, %rcx
	movsd	(%rsi,%rcx,8), %xmm6            # xmm6 = mem[0],zero
	subsd	%xmm4, %xmm6
	leal	(%r12,%r8), %ecx
	movslq	%ecx, %rcx
	subsd	(%rsi,%rcx,8), %xmm4
	subsd	%xmm4, %xmm6
	mulsd	%xmm3, %xmm6
	addsd	%xmm5, %xmm6
	mulsd	%xmm0, %xmm6
	addsd	(%rdi,%r11,8), %xmm6
	movsd	%xmm6, (%rdi,%r11,8)
	incq	%r8
	cmpq	%r8, %rax
	jne	.LBB1_6
.LBB1_7:                                # %._crit_edge
                                        #   in Loop: Header=BB1_4 Depth=2
	leal	1(%rbp), %r8d
	addq	%rbx, %r10
	addq	%rbx, %r14
	addq	%rbx, %r13
	addq	%rbx, %r15
	addq	%rbx, %r12
	cmpl	%r9d, %ebp
	movl	%r8d, %ebp
	jne	.LBB1_4
.LBB1_8:                                # %._crit_edge55
                                        #   in Loop: Header=BB1_2 Depth=1
	movq	-8(%rsp), %r10                  # 8-byte Reload
	leal	1(%r10), %r8d
	movq	-16(%rsp), %rcx                 # 8-byte Reload
	addq	%rcx, -24(%rsp)                 # 8-byte Folded Spill
	addq	%rcx, -32(%rsp)                 # 8-byte Folded Spill
	addq	%rcx, -56(%rsp)                 # 8-byte Folded Spill
	addq	%rcx, -40(%rsp)                 # 8-byte Folded Spill
	addq	%rcx, -48(%rsp)                 # 8-byte Folded Spill
	cmpl	-68(%rsp), %r10d                # 4-byte Folded Reload
                                        # kill: def $r8d killed $r8d def $r8
	jne	.LBB1_2
.LBB1_9:                                # %._crit_edge57
	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_end1:
	.size	_Z4diffPdPKdddddiii, .Lfunc_end1-_Z4diffPdPKdddddiii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI2_0:
	.quad	0x3fb999999999999a              # double 0.10000000000000001
.LCPI2_1:
	.quad	0x41cdcd6500000000              # double 1.0E+9
.LCPI2_2:
	.quad	0x403e000000000000              # double 30
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %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
	cmpl	$2, %edi
	jne	.LBB2_1
# %bb.3:
	movq	%rsi, %r12
	movq	8(%rsi), %rsi
.Ltmp0:
	leaq	16(%rsp), %rdi
	leaq	11(%rsp), %rdx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
.Ltmp1:
# %bb.4:
	movq	16(%rsp), %r15
	callq	__errno_location
	movq	%rax, %r14
	movl	(%rax), %ebp
	movl	$0, (%rax)
	leaq	56(%rsp), %r13
	movq	%r15, %rdi
	movq	%r13, %rsi
	movl	$10, %edx
	callq	__isoc23_strtol
	cmpq	%r15, (%r13)
	je	.LBB2_5
# %bb.12:
	movslq	%eax, %rcx
	movq	%rax, 48(%rsp)                  # 8-byte Spill
	cmpq	%rax, %rcx
	jne	.LBB2_14
# %bb.13:
	movl	(%r14), %eax
	cmpl	$34, %eax
	je	.LBB2_14
# %bb.16:
	testl	%eax, %eax
	jne	.LBB2_18
# %bb.17:
	movl	%ebp, (%r14)
.LBB2_18:
	leaq	32(%rsp), %rbx
	movq	-16(%rbx), %rdi
	cmpq	%rbx, %rdi
	je	.LBB2_20
# %bb.19:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i
	callq	_ZdlPv
.LBB2_20:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit
	movq	8(%r12), %rsi
.Ltmp3:
	leaq	16(%rsp), %rdi
	leaq	11(%rsp), %rdx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
.Ltmp4:
# %bb.21:
	movq	16(%rsp), %r13
	movl	(%r14), %eax
	movl	%eax, 12(%rsp)                  # 4-byte Spill
	movl	$0, (%r14)
	leaq	56(%rsp), %rbp
	movq	%r13, %rdi
	movq	%rbp, %rsi
	movl	$10, %edx
	callq	__isoc23_strtol
	cmpq	%r13, (%rbp)
	je	.LBB2_22
# %bb.27:
	movq	%rax, %r15
	movabsq	$-4294967296, %rcx              # imm = 0xFFFFFFFF00000000
	addq	$-2147483648, %rax              # imm = 0x80000000
	cmpq	%rcx, %rax
	jb	.LBB2_29
# %bb.28:
	movl	(%r14), %eax
	cmpl	$34, %eax
	je	.LBB2_29
# %bb.31:
	testl	%eax, %eax
	jne	.LBB2_33
# %bb.32:
	movl	12(%rsp), %eax                  # 4-byte Reload
	movl	%eax, (%r14)
.LBB2_33:
	movq	16(%rsp), %rdi
	cmpq	%rbx, %rdi
	je	.LBB2_35
# %bb.34:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i57
	callq	_ZdlPv
.LBB2_35:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit59
	movq	8(%r12), %rsi
.Ltmp6:
	leaq	16(%rsp), %rdi
	leaq	11(%rsp), %rdx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
.Ltmp7:
# %bb.36:
	movq	16(%rsp), %r13
	movl	(%r14), %eax
	movl	%eax, 12(%rsp)                  # 4-byte Spill
	movl	$0, (%r14)
	leaq	56(%rsp), %rbp
	movq	%r13, %rdi
	movq	%rbp, %rsi
	movl	$10, %edx
	callq	__isoc23_strtol
	cmpq	%r13, (%rbp)
	je	.LBB2_37
# %bb.42:
	movq	%rax, %r12
	addq	$-2147483648, %rax              # imm = 0x80000000
	movabsq	$-4294967296, %rcx              # imm = 0xFFFFFFFF00000000
	cmpq	%rcx, %rax
	movq	48(%rsp), %rbx                  # 8-byte Reload
	jb	.LBB2_44
# %bb.43:
	movl	(%r14), %eax
	cmpl	$34, %eax
	je	.LBB2_44
# %bb.46:
	testl	%eax, %eax
	jne	.LBB2_48
# %bb.47:
	movl	12(%rsp), %eax                  # 4-byte Reload
	movl	%eax, (%r14)
.LBB2_48:
	movq	16(%rsp), %rdi
	leaq	32(%rsp), %rax
	cmpq	%rax, %rdi
	je	.LBB2_50
# %bb.49:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i66
	callq	_ZdlPv
.LBB2_50:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit68
	movl	%r15d, %eax
	imull	%ebx, %eax
	movl	%eax, 12(%rsp)                  # 4-byte Spill
	movl	%eax, %ebp
	imull	%r12d, %ebp
	leaq	(,%rbp,8), %rbx
	testl	%ebp, %ebp
	movq	$-1, %r14
	cmovnsq	%rbx, %r14
	movq	%r14, %rdi
	callq	_Znam
	movq	%rax, %r13
	movq	%r14, %rdi
	callq	_Znam
	movq	%rax, %r14
	testl	%ebp, %ebp
	jle	.LBB2_53
# %bb.51:                               # %.lr.ph.preheader.i
	movq	%rbx, %rdx
	xorl	%ebx, %ebx
	movq	%r14, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
.LBB2_52:                               # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2sd	%ebx, %xmm0
	mulsd	%xmm0, %xmm0
	leaq	1(%rbx), %rax
	xorps	%xmm1, %xmm1
	cvtsi2sd	%eax, %xmm1
	mulsd	%xmm1, %xmm1
	divsd	%xmm1, %xmm0
	movsd	%xmm0, (%r13,%rbx,8)
	movq	%rax, %rbx
	cmpq	%rax, %rbp
	jne	.LBB2_52
.LBB2_53:                               # %_Z4initPdS_i.exit
	movsd	.LCPI2_0(%rip), %xmm0           # xmm0 = mem[0],zero
	movq	%r14, %rdi
	movq	%r13, %rsi
	movaps	%xmm0, %xmm1
	movaps	%xmm0, %xmm2
	movaps	%xmm0, %xmm3
	movq	48(%rsp), %rbp                  # 8-byte Reload
	movl	%ebp, %edx
	movl	%r15d, %ecx
	movl	%r12d, %r8d
	callq	_Z4diffPdPKdddddiii
	movl	12(%rsp), %ecx                  # 4-byte Reload
	addl	%ebp, %ecx
	movl	%ebp, %eax
	shrl	$31, %eax
	addl	%ebp, %eax
	sarl	%eax
	movl	%ecx, 12(%rsp)                  # 4-byte Spill
	addl	%ecx, %eax
	cltq
	movsd	(%r14,%rax,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.1, %edi
	movb	$1, %al
	callq	printf
	movl	$30, %ebx
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, 64(%rsp)                  # 8-byte Spill
.LBB2_54:                               # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	movq	%r13, %rsi
	movsd	.LCPI2_0(%rip), %xmm0           # xmm0 = mem[0],zero
	movaps	%xmm0, %xmm1
	movaps	%xmm0, %xmm2
	movaps	%xmm0, %xmm3
	movl	%ebp, %edx
	movl	%r15d, %ecx
	movl	%r12d, %r8d
	callq	_Z4diffPdPKdddddiii
	decl	%ebx
	jne	.LBB2_54
# %bb.55:
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	subq	64(%rsp), %rax                  # 8-byte Folded Reload
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI2_1(%rip), %xmm0
	divsd	.LCPI2_2(%rip), %xmm0
	movl	$.L.str.2, %edi
	movl	$30, %esi
	movb	$1, %al
	callq	printf
	leal	3(%rbp), %eax
	testl	%ebp, %ebp
	cmovnsl	%ebp, %eax
	sarl	$2, %eax
	movl	12(%rsp), %ecx                  # 4-byte Reload
	addl	%eax, %ecx
	movslq	%ecx, %rax
	movsd	(%r14,%rax,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.1, %edi
	movb	$1, %al
	callq	printf
	xorl	%eax, %eax
	jmp	.LBB2_2
.LBB2_1:
	movl	$_ZSt4cout, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$33, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$1, %eax
.LBB2_2:
	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
.LBB2_5:
	.cfi_def_cfa_offset 128
.Ltmp21:
	movl	$.L.str.3, %edi
	callq	_ZSt24__throw_invalid_argumentPKc
.Ltmp22:
# %bb.6:
.LBB2_14:                               # %.critedge.i.i
.Ltmp19:
	movl	$.L.str.3, %edi
	callq	_ZSt20__throw_out_of_rangePKc
.Ltmp20:
# %bb.15:
.LBB2_22:
.Ltmp16:
	movq	%rbx, %r15
	movl	$.L.str.3, %edi
	callq	_ZSt24__throw_invalid_argumentPKc
.Ltmp17:
# %bb.23:
.LBB2_29:                               # %.critedge.i.i52
.Ltmp14:
	movq	%rbx, %r15
	movl	$.L.str.3, %edi
	callq	_ZSt20__throw_out_of_rangePKc
.Ltmp15:
# %bb.30:
.LBB2_37:
.Ltmp11:
	movl	$.L.str.3, %edi
	callq	_ZSt24__throw_invalid_argumentPKc
.Ltmp12:
# %bb.38:
.LBB2_44:                               # %.critedge.i.i61
.Ltmp9:
	movl	$.L.str.3, %edi
	callq	_ZSt20__throw_out_of_rangePKc
.Ltmp10:
# %bb.45:
.LBB2_58:
.Ltmp8:
	jmp	.LBB2_59
.LBB2_57:
.Ltmp5:
	jmp	.LBB2_59
.LBB2_56:
.Ltmp2:
.LBB2_59:
	movq	%rax, %rbx
	jmp	.LBB2_60
.LBB2_39:
.Ltmp13:
	movq	%rax, %rbx
	cmpl	$0, (%r14)
	jne	.LBB2_41
# %bb.40:
	movl	12(%rsp), %eax                  # 4-byte Reload
	movl	%eax, (%r14)
.LBB2_41:                               # %_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev.exit.i.i62
	movq	16(%rsp), %rdi
	leaq	32(%rsp), %rax
	jmp	.LBB2_10
.LBB2_24:
.Ltmp18:
	movq	%rax, %rbx
	cmpl	$0, (%r14)
	jne	.LBB2_26
# %bb.25:
	movl	12(%rsp), %eax                  # 4-byte Reload
	movl	%eax, (%r14)
.LBB2_26:                               # %_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev.exit.i.i53
	movq	16(%rsp), %rdi
	cmpq	%r15, %rdi
	jne	.LBB2_11
	jmp	.LBB2_60
.LBB2_7:
.Ltmp23:
	movq	%rax, %rbx
	cmpl	$0, (%r14)
	jne	.LBB2_9
# %bb.8:
	movl	%ebp, (%r14)
.LBB2_9:                                # %_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev.exit.i.i
	leaq	32(%rsp), %rax
	movq	-16(%rax), %rdi
.LBB2_10:                               # %_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev.exit.i.i
	cmpq	%rax, %rdi
	je	.LBB2_60
.LBB2_11:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i69
	callq	_ZdlPv
.LBB2_60:
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table2:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 1 <<
	.uleb128 .Ltmp1-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp1
	.uleb128 .Ltmp2-.Lfunc_begin0           #     jumps to .Ltmp2
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp3-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp4-.Ltmp3                  #   Call between .Ltmp3 and .Ltmp4
	.uleb128 .Ltmp5-.Lfunc_begin0           #     jumps to .Ltmp5
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp6-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Ltmp7-.Ltmp6                  #   Call between .Ltmp6 and .Ltmp7
	.uleb128 .Ltmp8-.Lfunc_begin0           #     jumps to .Ltmp8
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp7-.Lfunc_begin0           # >> Call Site 4 <<
	.uleb128 .Ltmp21-.Ltmp7                 #   Call between .Ltmp7 and .Ltmp21
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp21-.Lfunc_begin0          # >> Call Site 5 <<
	.uleb128 .Ltmp20-.Ltmp21                #   Call between .Ltmp21 and .Ltmp20
	.uleb128 .Ltmp23-.Lfunc_begin0          #     jumps to .Ltmp23
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp16-.Lfunc_begin0          # >> Call Site 6 <<
	.uleb128 .Ltmp15-.Ltmp16                #   Call between .Ltmp16 and .Ltmp15
	.uleb128 .Ltmp18-.Lfunc_begin0          #     jumps to .Ltmp18
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp11-.Lfunc_begin0          # >> Call Site 7 <<
	.uleb128 .Ltmp10-.Ltmp11                #   Call between .Ltmp11 and .Ltmp10
	.uleb128 .Ltmp13-.Lfunc_begin0          #     jumps to .Ltmp13
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp10-.Lfunc_begin0          # >> Call Site 8 <<
	.uleb128 .Lfunc_end2-.Ltmp10            #   Call between .Ltmp10 and .Lfunc_end2
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.section	.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,"axG",@progbits,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,comdat
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_ # -- Begin function _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.p2align	1, 0x90
	.type	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,@function
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_: # @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	leaq	16(%rdi), %rax
	movq	%rax, (%rdi)
	testq	%rsi, %rsi
	je	.LBB3_1
# %bb.2:
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movq	%rsi, %rdi
	callq	strlen
	leaq	(%rax,%rbx), %rdx
	movq	%r14, %rdi
	movq	%rbx, %rsi
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag # TAILCALL
.LBB3_1:
	.cfi_def_cfa_offset 32
	movl	$.L.str.4, %edi
	callq	_ZSt19__throw_logic_errorPKc
.Lfunc_end3:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_, .Lfunc_end3-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag,"axG",@progbits,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag,comdat
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag # -- Begin function _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag
	.p2align	1, 0x90
	.type	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag,@function
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag: # @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.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 %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdx, %r14
	movq	%rsi, %r15
	movq	%rdi, %rbx
	subq	%rsi, %r14
	movq	%r14, (%rsp)
	cmpq	$15, %r14
	jbe	.LBB4_1
# %bb.2:
	movq	%rsp, %r12
	movq	%rbx, %rdi
	movq	%r12, %rsi
	xorl	%edx, %edx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm
	movq	%rax, (%rbx)
	movq	(%r12), %rcx
	movq	%rcx, 16(%rbx)
	jmp	.LBB4_3
.LBB4_1:                                # %._crit_edge
	movq	(%rbx), %rax
.LBB4_3:
	testq	%r14, %r14
	je	.LBB4_7
# %bb.4:
	cmpq	$1, %r14
	jne	.LBB4_6
# %bb.5:
	movb	(%r15), %cl
	movb	%cl, (%rax)
	jmp	.LBB4_7
.LBB4_6:
	movq	%rax, %rdi
	movq	%r15, %rsi
	movq	%r14, %rdx
	callq	memcpy@PLT
.LBB4_7:                                # %_ZZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tagEN6_GuardD2Ev.exit
	movq	(%rsp), %rax
	movq	%rax, 8(%rbx)
	movq	(%rbx), %rcx
	movb	$0, (%rcx,%rax)
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag, .Lfunc_end4-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Add the grid size as an argument!"
	.size	.L.str, 34

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"at=%.20f\n"
	.size	.L.str.1, 10

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"time/iter = %E s (%i iters)\n"
	.size	.L.str.2, 29

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"stoi"
	.size	.L.str.3, 5

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"basic_string: construction from null is not valid"
	.size	.L.str.4, 50

	.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 __gxx_personality_v0
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_cuid_

	.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_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
