#include <stdio.h>
#include <cuda_runtime.h>
// #include <helper_cuda.h>

#define THREADS_PER_BLOCK 3

double f(double x){
	return x*x;
}

__global__ void calculate(double *buffer, double start, double step, int N, double (*f) (double)){
	int i = blockIdx.x * blockDim.x + threadIdx.x;
	if(i < N){
		double x = start + i * step;
		buffer[i] = f(x);
	}
}

double integrate(double *buffer, double start, double end, int div, double (*f) (double)){
	int N = div;
	double step = (end - start) / div;

	cudaMallocManaged(&buffer, sizeof(double) * N);
	calculate<<<(N + THREADS_PER_BLOCK - 1) / THREADS_PER_BLOCK, THREADS_PER_BLOCK>>>(buffer, start, step, N, f);

	cudaDeviceSynchronize();

	for(int i = 0; i < N; i++)
		printf("%d ", buffer[i]);
	printf("\n");

	double result = (f(start) + f(end)) / 2;
	for(int i = 0; i < N; i++)
		result += buffer[i]; // f(start + i * step);
	return result;
}

int main(void){
	cudaError_t err = cudaSuccess;

	double *buffer = NULL;

	double result = integrate(buffer, 0, 10, 100, f);

	if ((err = cudaGetLastError()) != cudaSuccess){
		fprintf(stderr, "Failed to launch kernel: %s\n", cudaGetErrorString(err));
		exit(EXIT_FAILURE);
	}

	printf("Result: %d\n", result);

	cudaFree(buffer);

	return 0;
}
	.file	"tmpxft_0025cb0d_00000000-6_integrate.cudafe1.cpp"
	.text
#APP

#NO_APP
	.globl	_Z1fd
	.type	_Z1fd, @function
_Z1fd:
.LFB2027:
	.cfi_startproc
	endbr64
	mulsd	%xmm0, %xmm0
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z1fd, .-_Z1fd
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z36__device_stub__Z9calculatePdddiPFddEPdddiPFddE
	.type	_Z36__device_stub__Z9calculatePdddiPFddEPdddiPFddE, @function
_Z36__device_stub__Z9calculatePdddiPFddEPdddiPFddE:
.LFB2054:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 40(%rsp)
	leaq	56(%rsp), %rcx
	leaq	64(%rsp), %rdi
	movl	%esi, 20(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	48(%rsp), %rdx
	movsd	%xmm0, 32(%rsp)
	movsd	%xmm1, 24(%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	20(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	8(%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	.L3
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z9calculatePdddiPFddE(%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
.L3:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z36__device_stub__Z9calculatePdddiPFddEPdddiPFddE, .-_Z36__device_stub__Z9calculatePdddiPFddEPdddiPFddE
	.globl	_Z9calculatePdddiPFddE
	.type	_Z9calculatePdddiPFddE, @function
_Z9calculatePdddiPFddE:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z36__device_stub__Z9calculatePdddiPFddEPdddiPFddE
	.cfi_endproc
.LFE2055:
	.size	_Z9calculatePdddiPFddE, .-_Z9calculatePdddiPFddE
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d "
.LC1:
	.string	"\n"
	.text
	.globl	_Z9integratePdddiPFddE
	.type	_Z9integratePdddiPFddE, @function
_Z9integratePdddiPFddE:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movslq	%esi, %rsi
	movq	%xmm1, %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%rdx, %rbp
	movl	$1, %edx
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rsi, %rbx
	salq	$3, %rsi
	subq	$48, %rsp
	.cfi_def_cfa_offset 96
	movq	%rdi, 8(%rsp)
	leaq	8(%rsp), %rdi
	movsd	%xmm0, (%rsp)
	call	cudaMallocManaged@PLT
	leal	2(%rbx), %eax
	movl	$3, %esi
	xorl	%r9d, %r9d
	cltd
	xorl	%r8d, %r8d
	movabsq	$4294967299, %rcx
	movl	$1, 44(%rsp)
	idivl	%esi
	movq	%rcx, 36(%rsp)
	movq	%rcx, %rdx
	movl	$1, %ecx
	movl	%eax, 24(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 28(%rsp)
	movq	24(%rsp), %rdi
	movl	32(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L10
	cvtsi2sdl	%ebx, %xmm0
	movq	%r14, %xmm1
	subsd	(%rsp), %xmm1
	movl	%ebx, %esi
	movq	8(%rsp), %rdi
	movq	%rbp, %rdx
	divsd	%xmm0, %xmm1
	movsd	(%rsp), %xmm0
	call	_Z36__device_stub__Z9calculatePdddiPFddEPdddiPFddE
.L10:
	call	cudaDeviceSynchronize@PLT
	xorl	%r12d, %r12d
	leaq	.LC0(%rip), %r13
.L11:
	cmpl	%r12d, %ebx
	jle	.L16
	movq	8(%rsp), %rax
	movq	%r13, %rsi
	movl	$2, %edi
	movsd	(%rax,%r12,8), %xmm0
	movb	$1, %al
	incq	%r12
	call	__printf_chk@PLT
	jmp	.L11
.L16:
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movsd	(%rsp), %xmm0
	call	*%rbp
	movsd	%xmm0, (%rsp)
	movq	%r14, %xmm0
	call	*%rbp
	addsd	(%rsp), %xmm0
	movq	8(%rsp), %rdx
	xorl	%eax, %eax
	mulsd	.LC2(%rip), %xmm0
.L13:
	cmpl	%eax, %ebx
	jle	.L17
	addsd	(%rdx,%rax,8), %xmm0
	incq	%rax
	jmp	.L13
.L17:
	addq	$48, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z9integratePdddiPFddE, .-_Z9integratePdddiPFddE
	.section	.rodata.str1.1
.LC5:
	.string	"Failed to launch kernel: %s\n"
.LC6:
	.string	"Result: %d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	xorl	%edi, %edi
	xorps	%xmm0, %xmm0
	movl	$100, %esi
	movsd	.LC3(%rip), %xmm1
	leaq	_Z1fd(%rip), %rdx
	call	_Z9integratePdddiPFddE
	movsd	%xmm0, 8(%rsp)
	call	cudaGetLastError@PLT
	movsd	8(%rsp), %xmm0
	testl	%eax, %eax
	je	.L19
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC5(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L19:
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	call	__printf_chk@PLT
	xorl	%edi, %edi
	call	cudaFree@PLT
	xorl	%eax, %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	main, .-main
	.section	.rodata.str1.1
.LC7:
	.string	"_Z9calculatePdddiPFddE"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2057:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC7(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z9calculatePdddiPFddE(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2057:
	.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
.LC2:
	.long	0
	.long	1071644672
	.align 8
.LC3:
	.long	0
	.long	1076101120
	.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 <stdio.h>
#include <hip/hip_runtime.h>
// #include <helper_cuda.h>

#define THREADS_PER_BLOCK 3

double f(double x){
	return x*x;
}

__global__ void calculate(double *buffer, double start, double step, int N, double (*f) (double)){
	int i = blockIdx.x * blockDim.x + threadIdx.x;
	if(i < N){
		double x = start + i * step;
		buffer[i] = f(x);
	}
}

double integrate(double *buffer, double start, double end, int div, double (*f) (double)){
	int N = div;
	double step = (end - start) / div;

	hipMallocManaged(&buffer, sizeof(double) * N);
	calculate<<<(N + THREADS_PER_BLOCK - 1) / THREADS_PER_BLOCK, THREADS_PER_BLOCK>>>(buffer, start, step, N, f);

	hipDeviceSynchronize();

	for(int i = 0; i < N; i++)
		printf("%d ", buffer[i]);
	printf("\n");

	double result = (f(start) + f(end)) / 2;
	for(int i = 0; i < N; i++)
		result += buffer[i]; // f(start + i * step);
	return result;
}

int main(void){
	hipError_t err = hipSuccess;

	double *buffer = NULL;

	double result = integrate(buffer, 0, 10, 100, f);

	if ((err = hipGetLastError()) != hipSuccess){
		fprintf(stderr, "Failed to launch kernel: %s\n", hipGetErrorString(err));
		exit(EXIT_FAILURE);
	}

	printf("Result: %d\n", result);

	hipFree(buffer);

	return 0;
}
	.text
	.file	"integrate.hip"
	.globl	_Z1fd                           # -- Begin function _Z1fd
	.type	_Z1fd,@function
_Z1fd:                                  # @_Z1fd
	.cfi_startproc
# %bb.0:
	mulsd	%xmm0, %xmm0
	retq
.Lfunc_end0:
	.size	_Z1fd, .Lfunc_end0-_Z1fd
	.cfi_endproc
                                        # -- End function
	.globl	_Z24__device_stub__calculatePdddiPFddE # -- Begin function _Z24__device_stub__calculatePdddiPFddE
	.type	_Z24__device_stub__calculatePdddiPFddE,@function
_Z24__device_stub__calculatePdddiPFddE: # @_Z24__device_stub__calculatePdddiPFddE
	.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), %rdi
	movsd	%xmm1, (%rdi)
	leaq	12(%rsp), %r8
	movl	%esi, (%r8)
	leaq	32(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rdi, 16(%rbx)
	movq	%r8, 24(%rbx)
	movq	%rsi, 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	$_Z9calculatePdddiPFddE, %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_end1:
	.size	_Z24__device_stub__calculatePdddiPFddE, .Lfunc_end1-_Z24__device_stub__calculatePdddiPFddE
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z9integratePdddiPFddE
.LCPI2_0:
	.quad	0x3fe0000000000000              # double 0.5
	.text
	.globl	_Z9integratePdddiPFddE
	.type	_Z9integratePdddiPFddE,@function
_Z9integratePdddiPFddE:                 # @_Z9integratePdddiPFddE
	.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
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdx, %r14
	movl	%esi, %ebx
	movsd	%xmm1, 16(%rsp)                 # 8-byte Spill
	movsd	%xmm0, (%rsp)                   # 8-byte Spill
	leaq	8(%rsp), %rax
	movq	%rdi, (%rax)
	movslq	%esi, %r15
	leaq	(,%r15,8), %rsi
	movq	%rax, %rdi
	movl	$1, %edx
	callq	hipMallocManaged
	addl	$2, %r15d
	movslq	%r15d, %rax
	imulq	$1431655766, %rax, %rdi         # imm = 0x55555556
	movq	%rdi, %rax
	shrq	$63, %rax
	shrq	$32, %rdi
	addl	%eax, %edi
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$3, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_2
# %bb.1:
	movsd	16(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	subsd	%xmm0, %xmm1
	cvtsi2sd	%ebx, %xmm2
	divsd	%xmm2, %xmm1
	movq	8(%rsp), %rdi
	movl	%ebx, %esi
	movq	%r14, %rdx
	callq	_Z24__device_stub__calculatePdddiPFddE
.LBB2_2:
	callq	hipDeviceSynchronize
	movl	%ebx, %r15d
	testl	%ebx, %ebx
	jle	.LBB2_5
# %bb.3:                                # %.lr.ph.preheader
	xorl	%r12d, %r12d
.LBB2_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	8(%rsp), %rax
	movsd	(%rax,%r12,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str, %edi
	movb	$1, %al
	callq	printf
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB2_4
.LBB2_5:                                # %._crit_edge
	movl	$10, %edi
	callq	putchar@PLT
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	*%r14
	movsd	%xmm0, (%rsp)                   # 8-byte Spill
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	*%r14
	addsd	(%rsp), %xmm0                   # 8-byte Folded Reload
	mulsd	.LCPI2_0(%rip), %xmm0
	testl	%ebx, %ebx
	jle	.LBB2_8
# %bb.6:                                # %.lr.ph35
	movq	8(%rsp), %rax
	xorl	%ecx, %ecx
.LBB2_7:                                # =>This Inner Loop Header: Depth=1
	addsd	(%rax,%rcx,8), %xmm0
	incq	%rcx
	cmpq	%rcx, %r15
	jne	.LBB2_7
.LBB2_8:                                # %._crit_edge36
	addq	$24, %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_end2:
	.size	_Z9integratePdddiPFddE, .Lfunc_end2-_Z9integratePdddiPFddE
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI3_0:
	.quad	0x4024000000000000              # double 10
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	movsd	.LCPI3_0(%rip), %xmm1           # xmm1 = mem[0],zero
	xorps	%xmm0, %xmm0
	movl	$_Z1fd, %edx
	xorl	%edi, %edi
	movl	$100, %esi
	callq	_Z9integratePdddiPFddE
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB3_2
# %bb.1:
	movl	$.L.str.3, %edi
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$1, %al
	callq	printf
	xorl	%edi, %edi
	callq	hipFree
	xorl	%eax, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB3_2:
	.cfi_def_cfa_offset 32
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9calculatePdddiPFddE, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__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	.LBB5_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
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z9calculatePdddiPFddE,@object  # @_Z9calculatePdddiPFddE
	.section	.rodata,"a",@progbits
	.globl	_Z9calculatePdddiPFddE
	.p2align	3, 0x0
_Z9calculatePdddiPFddE:
	.quad	_Z24__device_stub__calculatePdddiPFddE
	.size	_Z9calculatePdddiPFddE, 8

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

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Failed to launch kernel: %s\n"
	.size	.L.str.2, 29

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z9calculatePdddiPFddE"
	.size	.L__unnamed_1, 23

	.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 _Z1fd
	.addrsig_sym _Z24__device_stub__calculatePdddiPFddE
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z9calculatePdddiPFddE
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z9calculatePdddiPFddE  ; -- Begin function _Z9calculatePdddiPFddE
	.globl	_Z9calculatePdddiPFddE
	.p2align	8
	.type	_Z9calculatePdddiPFddE,@function
_Z9calculatePdddiPFddE:                 ; @_Z9calculatePdddiPFddE
; %bb.0:
	s_mov_b64 s[10:11], s[4:5]
	s_clause 0x1
	s_load_b32 s4, s[2:3], 0x34
	s_load_b32 s5, s[2:3], 0x18
	v_and_b32_e32 v1, 0x3ff, v0
	s_mov_b32 s32, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[3:4], null, s13, s4, v[1:2]
	s_mov_b32 s4, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s5, v3
	s_cbranch_execz .LBB0_2
; %bb.1:
	v_cvt_f64_i32_e32 v[1:2], v3
	s_clause 0x1
	s_load_b128 s[4:7], s[2:3], 0x0
	s_load_b64 s[8:9], s[2:3], 0x10
	v_ashrrev_i32_e32 v4, 31, v3
	s_mov_b32 s12, s13
	s_mov_b32 s13, s14
	s_mov_b32 s14, s15
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[3:4], 3, v[3:4]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v40, vcc_lo, s4, v3
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v41, vcc_lo, s5, v4, vcc_lo
	s_mov_b64 s[4:5], s[0:1]
	v_fma_f64 v[1:2], v[1:2], s[8:9], s[6:7]
	s_load_b64 s[6:7], s[2:3], 0x20
	v_mov_b32_e32 v31, v0
	s_add_u32 s8, s2, 40
	s_addc_u32 s9, s3, 0
	s_delay_alu instid0(VALU_DEP_2)
	v_dual_mov_b32 v0, v1 :: v_dual_mov_b32 v1, v2
	s_waitcnt lgkmcnt(0)
	s_swappc_b64 s[30:31], s[6:7]
	global_store_b64 v[40:41], v[0:1], off
.LBB0_2:
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9calculatePdddiPFddE
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 13
		.amdhsa_user_sgpr_dispatch_ptr 1
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 1
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 1
		.amdhsa_enable_private_segment 1
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 1
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 2
		.amdhsa_next_free_vgpr 42
		.amdhsa_next_free_sgpr 33
		.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	_Z9calculatePdddiPFddE, .Lfunc_end0-_Z9calculatePdddiPFddE
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 216
; NumSgprs: 35
; NumVgprs: 42
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 4
; VGPRBlocks: 5
; NumSGPRsForWavesPerEU: 35
; NumVGPRsForWavesPerEU: 42
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 1
; COMPUTE_PGM_RSRC2:USER_SGPR: 13
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 1
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 2
	.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:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         120
        .size:           8
        .value_kind:     hidden_hostcall_buffer
      - .offset:         128
        .size:           8
        .value_kind:     hidden_multigrid_sync_arg
      - .offset:         136
        .size:           8
        .value_kind:     hidden_heap_v1
      - .offset:         144
        .size:           8
        .value_kind:     hidden_default_queue
      - .offset:         240
        .size:           8
        .value_kind:     hidden_queue_ptr
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z9calculatePdddiPFddE
    .private_segment_fixed_size: 0
    .sgpr_count:     35
    .sgpr_spill_count: 0
    .symbol:         _Z9calculatePdddiPFddE.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: true
    .vgpr_count:     42
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
