#include "addition.cuh"
#include <stdio.h>

__global__ void addition(int* a, int* b, int* c){
    *c = *a + *b;
}

void setupCuda(int* &D_A, int* &D_B, int* &D_C, int* &A, int* &B, int* &C){
    cudaMalloc((void**)&D_A, sizeof(int));
    cudaMalloc((void**)&D_B, sizeof(int));
    cudaMalloc((void**)&D_C, sizeof(int));

    cudaMemcpy(D_A, A, sizeof(int), cudaMemcpyHostToDevice);
    cudaMemcpy(D_B, B, sizeof(int), cudaMemcpyHostToDevice);
    cudaMemcpy(D_C, C, sizeof(int), cudaMemcpyHostToDevice);
}

void copyInputToDevice(int* D_A, int* D_B, int* D_C, int* A, int* B, int* C){
    cudaMemcpy(D_A, A, sizeof(int), cudaMemcpyHostToDevice);
    cudaMemcpy(D_B, B, sizeof(int), cudaMemcpyHostToDevice);
}

void executeKernel(int* D_A, int* D_B, int* D_C, int* A, int* B, int* C){
    addition<<<1,1>>>(D_A, D_B, D_C);
}

void copyOutputToHost(int* D_A, int* D_B, int* D_C, int* A, int* B, int* C){
    cudaMemcpy(C, D_C, sizeof(int), cudaMemcpyDeviceToHost);
}

void cleanupCuda(int* D_A, int* D_B, int* D_C){
    cudaFree(D_A);
    cudaFree(D_B);
    cudaFree(D_C);
}

	.file	"tmpxft_00239042_00000000-6_addition.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z9setupCudaRPiS0_S0_S0_S0_S0_
	.type	_Z9setupCudaRPiS0_S0_S0_S0_S0_, @function
_Z9setupCudaRPiS0_S0_S0_S0_S0_:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rcx, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%r8, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%r9, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rsi, %rbp
	movl	$4, %esi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdx, %rbx
	pushq	%rax
	.cfi_def_cfa_offset 64
	call	cudaMalloc@PLT
	movq	%rbp, %rdi
	movl	$4, %esi
	call	cudaMalloc@PLT
	movq	%rbx, %rdi
	movl	$4, %esi
	call	cudaMalloc@PLT
	movq	(%r15), %rsi
	movq	(%r12), %rdi
	movl	$1, %ecx
	movl	$4, %edx
	call	cudaMemcpy@PLT
	movq	(%r14), %rsi
	movq	0(%rbp), %rdi
	movl	$1, %ecx
	movl	$4, %edx
	call	cudaMemcpy@PLT
	movq	0(%r13), %rsi
	movq	(%rbx), %rdi
	movl	$1, %ecx
	popq	%r8
	.cfi_def_cfa_offset 56
	movl	$4, %edx
	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
	jmp	cudaMemcpy@PLT
	.cfi_endproc
.LFE2027:
	.size	_Z9setupCudaRPiS0_S0_S0_S0_S0_, .-_Z9setupCudaRPiS0_S0_S0_S0_S0_
	.globl	_Z17copyInputToDevicePiS_S_S_S_S_
	.type	_Z17copyInputToDevicePiS_S_S_S_S_, @function
_Z17copyInputToDevicePiS_S_S_S_S_:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%r8, %rbp
	movl	$4, %edx
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rsi, %rbx
	movq	%rcx, %rsi
	movl	$1, %ecx
	pushq	%rax
	.cfi_def_cfa_offset 32
	call	cudaMemcpy@PLT
	popq	%r8
	.cfi_def_cfa_offset 24
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	movl	$1, %ecx
	popq	%rbx
	.cfi_def_cfa_offset 16
	movl	$4, %edx
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	cudaMemcpy@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z17copyInputToDevicePiS_S_S_S_S_, .-_Z17copyInputToDevicePiS_S_S_S_S_
	.globl	_Z16copyOutputToHostPiS_S_S_S_S_
	.type	_Z16copyOutputToHostPiS_S_S_S_S_, @function
_Z16copyOutputToHostPiS_S_S_S_S_:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	%rdx, %rsi
	movq	%r9, %rdi
	movl	$2, %ecx
	movl	$4, %edx
	jmp	cudaMemcpy@PLT
	.cfi_endproc
.LFE2030:
	.size	_Z16copyOutputToHostPiS_S_S_S_S_, .-_Z16copyOutputToHostPiS_S_S_S_S_
	.globl	_Z11cleanupCudaPiS_S_
	.type	_Z11cleanupCudaPiS_S_, @function
_Z11cleanupCudaPiS_S_:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdx, %rbx
	pushq	%rax
	.cfi_def_cfa_offset 32
	call	cudaFree@PLT
	movq	%rbp, %rdi
	call	cudaFree@PLT
	popq	%rdx
	.cfi_def_cfa_offset 24
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	cudaFree@PLT
	.cfi_endproc
.LFE2031:
	.size	_Z11cleanupCudaPiS_S_, .-_Z11cleanupCudaPiS_S_
	.globl	_Z31__device_stub__Z8additionPiS_S_PiS_S_
	.type	_Z31__device_stub__Z8additionPiS_S_PiS_S_, @function
_Z31__device_stub__Z8additionPiS_S_PiS_S_:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L9
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z8additionPiS_S_(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L9:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L11
	call	__stack_chk_fail@PLT
.L11:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z31__device_stub__Z8additionPiS_S_PiS_S_, .-_Z31__device_stub__Z8additionPiS_S_PiS_S_
	.globl	_Z8additionPiS_S_
	.type	_Z8additionPiS_S_, @function
_Z8additionPiS_S_:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z31__device_stub__Z8additionPiS_S_PiS_S_
	.cfi_endproc
.LFE2057:
	.size	_Z8additionPiS_S_, .-_Z8additionPiS_S_
	.globl	_Z13executeKernelPiS_S_S_S_S_
	.type	_Z13executeKernelPiS_S_S_S_S_, @function
_Z13executeKernelPiS_S_S_S_S_:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	xorl	%r9d, %r9d
	movq	%rdx, %r12
	xorl	%r8d, %r8d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	$1, %ecx
	movq	%rsi, %rbp
	movl	$1, %esi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	movabsq	$4294967297, %rdi
	movq	%rdi, %rdx
	subq	$32, %rsp
	.cfi_def_cfa_offset 64
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L15
	addq	$32, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	movq	%r12, %rdx
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	_Z31__device_stub__Z8additionPiS_S_PiS_S_
.L15:
	.cfi_restore_state
	addq	$32, %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
.LFE2029:
	.size	_Z13executeKernelPiS_S_S_S_S_, .-_Z13executeKernelPiS_S_S_S_S_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"_Z8additionPiS_S_"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2059:
	.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	.LC0(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z8additionPiS_S_(%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
.LFE2059:
	.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
	.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>


void setupCuda(int* &D_A, int* &D_B, int* &D_C, int* &A, int* &B, int* &C);

void copyInputToDevice(int* D_A, int* D_B, int* D_C, int* A, int* B, int* C);

void executeKernel(int* D_A, int* D_B, int* D_C, int* A, int* B, int* C);

void copyOutputToHost(int* D_A, int* D_B, int* D_C, int* A, int* B, int* C);

void cleanupCuda(int* D_A, int* D_B, int* D_C);

	.text
	.file	"addition.hip"
	.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 __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
