/*
 * Noopur Maheshwari : 111464061
 * Rahul Rane : 111465246
 */
#include <pthread.h>
#include <iostream>
using namespace std;
extern pthread_mutex_t lock;

int get_shared_var_value(int *ptr) {
    int ret;
    pthread_mutex_lock(&lock);
    ret = *ptr;
    pthread_mutex_unlock(&lock);
    return ret;
}

void set_shared_var_value(int *ptr, int val) {
    pthread_mutex_lock(&lock);
    (*ptr) = val;
    pthread_mutex_unlock(&lock); 
}

void dec_shared_var_value(int *ptr) {
    pthread_mutex_lock(&lock);
    (*ptr)--;
    pthread_mutex_unlock(&lock); 
}

	.file	"tmpxft_003968d8_00000000-6_atomic.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3640:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3640:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z20get_shared_var_valuePi
	.type	_Z20get_shared_var_valuePi, @function
_Z20get_shared_var_valuePi:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	lock(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	movq	%rbp, %rdi
	pushq	%rax
	.cfi_def_cfa_offset 32
	call	pthread_mutex_lock@PLT
	movl	(%rbx), %ebx
	movq	%rbp, %rdi
	call	pthread_mutex_unlock@PLT
	popq	%rdx
	.cfi_def_cfa_offset 24
	movl	%ebx, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3635:
	.size	_Z20get_shared_var_valuePi, .-_Z20get_shared_var_valuePi
	.globl	_Z20set_shared_var_valuePii
	.type	_Z20set_shared_var_valuePii, @function
_Z20set_shared_var_valuePii:
.LFB3636:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	lock(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	movq	%r12, %rdi
	call	pthread_mutex_lock@PLT
	movl	%ebp, (%rbx)
	movq	%r12, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	pthread_mutex_unlock@PLT
	.cfi_endproc
.LFE3636:
	.size	_Z20set_shared_var_valuePii, .-_Z20set_shared_var_valuePii
	.globl	_Z20dec_shared_var_valuePi
	.type	_Z20dec_shared_var_valuePi, @function
_Z20dec_shared_var_valuePi:
.LFB3637:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	lock(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	movq	%rbp, %rdi
	pushq	%rax
	.cfi_def_cfa_offset 32
	call	pthread_mutex_lock@PLT
	decl	(%rbx)
	movq	%rbp, %rdi
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	pthread_mutex_unlock@PLT
	.cfi_endproc
.LFE3637:
	.size	_Z20dec_shared_var_valuePi, .-_Z20dec_shared_var_valuePi
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3663:
	.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
.LFE3663:
	.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:

/*
 * Noopur Maheshwari : 111464061
 * Rahul Rane : 111465246
 */

#include <hip/hip_runtime.h>
#include <pthread.h>
#include <iostream>
using namespace std;
extern pthread_mutex_t lock;

int get_shared_var_value(int *ptr) {
    int ret;
    pthread_mutex_lock(&lock);
    ret = *ptr;
    pthread_mutex_unlock(&lock);
    return ret;
}

void set_shared_var_value(int *ptr, int val) {
    pthread_mutex_lock(&lock);
    (*ptr) = val;
    pthread_mutex_unlock(&lock); 
}

void dec_shared_var_value(int *ptr) {
    pthread_mutex_lock(&lock);
    (*ptr)--;
    pthread_mutex_unlock(&lock); 
}

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

                                        # End of file scope inline assembly
	.globl	_Z20get_shared_var_valuePi      # -- Begin function _Z20get_shared_var_valuePi
	.type	_Z20get_shared_var_valuePi,@function
_Z20get_shared_var_valuePi:             # @_Z20get_shared_var_valuePi
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	movl	$lock, %edi
	callq	pthread_mutex_lock
	movl	(%rbx), %ebx
	movl	$lock, %edi
	callq	pthread_mutex_unlock
	movl	%ebx, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z20get_shared_var_valuePi, .Lfunc_end0-_Z20get_shared_var_valuePi
	.cfi_endproc
                                        # -- End function
	.globl	_Z20set_shared_var_valuePii     # -- Begin function _Z20set_shared_var_valuePii
	.type	_Z20set_shared_var_valuePii,@function
_Z20set_shared_var_valuePii:            # @_Z20set_shared_var_valuePii
	.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
	movl	%esi, %ebx
	movq	%rdi, %r14
	movl	$lock, %edi
	callq	pthread_mutex_lock
	movl	%ebx, (%r14)
	movl	$lock, %edi
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	pthread_mutex_unlock            # TAILCALL
.Lfunc_end1:
	.size	_Z20set_shared_var_valuePii, .Lfunc_end1-_Z20set_shared_var_valuePii
	.cfi_endproc
                                        # -- End function
	.globl	_Z20dec_shared_var_valuePi      # -- Begin function _Z20dec_shared_var_valuePi
	.type	_Z20dec_shared_var_valuePi,@function
_Z20dec_shared_var_valuePi:             # @_Z20dec_shared_var_valuePi
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	movl	$lock, %edi
	callq	pthread_mutex_lock
	decl	(%rbx)
	movl	$lock, %edi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	pthread_mutex_unlock            # TAILCALL
.Lfunc_end2:
	.size	_Z20dec_shared_var_valuePi, .Lfunc_end2-_Z20dec_shared_var_valuePi
	.cfi_endproc
                                        # -- End function
	.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 lock
	.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
