#include <stdio.h>
#include <stdlib.h>

__global__ void emptyKernel()
{
}

#define cudaCheck(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true)
{
   if (code != cudaSuccess) 
   {
      printf("CUDA error: %s - %s(%d)\n", cudaGetErrorString(code), file, line);
      if (abort) exit(code);
   }
}

int main(int argc, char* argv[])
{
	// Initialization
	/*----------------------------------------------------------------------------------------*/
	int device = atoi(argv[1]);
	cudaCheck(cudaSetDevice(device));
	cudaSetDeviceFlags(cudaDeviceMapHost);

	int runtime_version;
	int driver_version;
	cudaDeviceProp properties;
	cudaGetDeviceProperties(&properties, device);
	cudaRuntimeGetVersion(&runtime_version);
	cudaDriverGetVersion(&driver_version);

	emptyKernel<<<1,1>>>();
	cudaDeviceSynchronize();
	
	// Pool size
	/*----------------------------------------------------------------------------------------*/
	int pool_size = 1;
	char *h_data;
	break_01: __attribute__((unused));
	cudaHostAlloc((void**)&h_data, 1, cudaHostAllocMapped);
	cudaFreeHost(h_data);
	
	// Maximum allocations and granularity
	/*----------------------------------------------------------------------------------------*/
	char **h_data_array = (char**) malloc(pool_size * sizeof(char*));
	cudaHostAlloc((void**)&h_data_array[0], 1, cudaHostAllocMapped);
	break_02: __attribute__((unused));
	int granularity = 0, iteration = 0, flag = 0;
	while(!flag && iteration < pool_size)
	{
		iteration++; 
		cudaHostAlloc((void**)&h_data_array[iteration], 1, cudaHostAllocMapped);
	}
	for(int i = 0; i <= iteration; i++)
	{
		cudaFreeHost(h_data_array[i]);
	}
	free(h_data_array);
	
	// Size classes
	/*----------------------------------------------------------------------------------------*/
	char *h_data_inf, *h_data_sup;
	int inf_size = granularity, sup_size = granularity, finished = 1, class_finished = 0;
	break_03: __attribute__((unused));
	cudaHostAlloc((void**)&h_data_inf, inf_size, cudaHostAllocMapped);
	while(!finished)
	{
		sup_size = sup_size + granularity;
		cudaHostAlloc((void**)&h_data_sup, sup_size, cudaHostAllocMapped);
		cudaFreeHost(h_data_sup);
		if(class_finished)
		{
			class_finished = 0;
			cudaFreeHost(h_data_inf);
			inf_size = sup_size;
			cudaHostAlloc((void**)&h_data_inf, inf_size, cudaHostAllocMapped);
		}
	}
	cudaFreeHost(h_data_inf);
	
	// Larger allocations
	/*----------------------------------------------------------------------------------------*/
	break_04: __attribute__((unused));
	cudaHostAlloc((void**)&h_data, pool_size + 1, cudaHostAllocMapped);
	cudaFreeHost(h_data);

	// Allocator policy
	/*----------------------------------------------------------------------------------------*/
	char *chunk_1, *chunk_2, *chunk_3, *chunk_4, *chunk_5, *chunk_6, *chunk_7, *chunk_8, *chunk_9, *chunk_10;
	cudaHostAlloc((void**)&chunk_1, granularity * 2, cudaHostAllocMapped);
	cudaHostAlloc((void**)&chunk_2, granularity, cudaHostAllocMapped);
	cudaHostAlloc((void**)&chunk_3, granularity * 2, cudaHostAllocMapped);
	cudaHostAlloc((void**)&chunk_4, granularity, cudaHostAllocMapped);
	cudaHostAlloc((void**)&chunk_5, granularity, cudaHostAllocMapped);
	cudaHostAlloc((void**)&chunk_6, granularity, cudaHostAllocMapped);
	cudaFreeHost(chunk_1);
	cudaFreeHost(chunk_3);
	cudaFreeHost(chunk_5);
	cudaHostAlloc((void**)&chunk_7, granularity, cudaHostAllocMapped);
	cudaHostAlloc((void**)&chunk_8, granularity, cudaHostAllocMapped);
	break_05: __attribute__((unused));
	cudaFreeHost(chunk_2);
	cudaFreeHost(chunk_4);
	cudaFreeHost(chunk_6);
	cudaFreeHost(chunk_7);
	cudaFreeHost(chunk_8);

	// Coalescing support
	/*----------------------------------------------------------------------------------------*/
	cudaHostAlloc((void**)&chunk_1, granularity, cudaHostAllocMapped);
	cudaHostAlloc((void**)&chunk_2, granularity, cudaHostAllocMapped);
	cudaHostAlloc((void**)&chunk_3, granularity, cudaHostAllocMapped);
	cudaFreeHost(chunk_1);
	cudaFreeHost(chunk_2);
	cudaHostAlloc((void**)&chunk_4, granularity * 2, cudaHostAllocMapped);
	break_06: __attribute__((unused));
	cudaFreeHost(chunk_3);
	cudaFreeHost(chunk_4);

	// Splitting support
	/*----------------------------------------------------------------------------------------*/
	cudaHostAlloc((void**)&chunk_1, granularity * 2, cudaHostAllocMapped);
	cudaHostAlloc((void**)&chunk_2, granularity, cudaHostAllocMapped);
	cudaFreeHost(chunk_1);
	cudaHostAlloc((void**)&chunk_3, granularity, cudaHostAllocMapped);
	break_07: __attribute__((unused));
	cudaFreeHost(chunk_2);
	cudaFreeHost(chunk_3);

	// Expansion policy
	/*----------------------------------------------------------------------------------------*/
	int max_allocations = pool_size / granularity;
	h_data_array = (char**) malloc(max_allocations * sizeof(char*));
	cudaHostAlloc((void**)&h_data_array[0], granularity, cudaHostAllocMapped);
	break_08: __attribute__((unused));
	int index;
	for(index = 1; index < max_allocations; index++)
	{
		cudaHostAlloc((void**)&h_data_array[index], granularity, cudaHostAllocMapped);
	}
	for(index = 0; index < max_allocations; index++)
	{
		cudaFreeHost(h_data_array[index]);
	}
	free(h_data_array);


	// Pool usage
	/*----------------------------------------------------------------------------------------*/
	int quarter = pool_size / 4;
	cudaHostAlloc((void**)&chunk_1, quarter, cudaHostAllocMapped);
	cudaHostAlloc((void**)&chunk_2, quarter, cudaHostAllocMapped);
	cudaHostAlloc((void**)&chunk_3, quarter, cudaHostAllocMapped);
	cudaHostAlloc((void**)&chunk_4, quarter, cudaHostAllocMapped);
	cudaHostAlloc((void**)&chunk_5, quarter, cudaHostAllocMapped);
	cudaHostAlloc((void**)&chunk_6, quarter, cudaHostAllocMapped);
	cudaHostAlloc((void**)&chunk_7, quarter, cudaHostAllocMapped);
	cudaHostAlloc((void**)&chunk_8, quarter, cudaHostAllocMapped);
	cudaHostAlloc((void**)&chunk_9, quarter, cudaHostAllocMapped);
	cudaFreeHost(chunk_1);
	cudaFreeHost(chunk_2);
	cudaFreeHost(chunk_5);
	cudaHostAlloc((void**)&chunk_10, quarter, cudaHostAllocMapped);
	break_09: __attribute__((unused));
	cudaFreeHost(chunk_10);

	// Shrinking support
	/*----------------------------------------------------------------------------------------*/
	flag = 0;
	break_10: __attribute__((unused));
	cudaFreeHost(chunk_6);
	cudaFreeHost(chunk_7);
	cudaFreeHost(chunk_8);
	flag = 1;
	cudaFreeHost(chunk_9);
	flag = 2;
	cudaFreeHost(chunk_3);
	cudaFreeHost(chunk_4);

	// Finalization
	/*----------------------------------------------------------------------------------------*/
	cudaDeviceReset();
	return 0;
}
	.file	"tmpxft_0026f6e0_00000000-6_get_alloc_info.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z30__device_stub__Z11emptyKernelvv
	.type	_Z30__device_stub__Z11emptyKernelvv, @function
_Z30__device_stub__Z11emptyKernelvv:
.LFB2053:
	.cfi_startproc
	endbr64
	subq	$88, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	movabsq	$4294967297, %rax
	leaq	8(%rsp), %rcx
	movq	%rsp, %rdx
	leaq	28(%rsp), %rsi
	leaq	16(%rsp), %rdi
	movl	$1, 24(%rsp)
	movl	$1, 36(%rsp)
	movq	%rax, 16(%rsp)
	movq	%rax, 28(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	8(%rsp)
	.cfi_def_cfa_offset 104
	leaq	_Z11emptyKernelv(%rip), %rdi
	pushq	8(%rsp)
	.cfi_def_cfa_offset 112
	movq	44(%rsp), %rcx
	movl	52(%rsp), %r8d
	movq	32(%rsp), %rsi
	movl	40(%rsp), %edx
	leaq	80(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 104
	popq	%rdx
	.cfi_def_cfa_offset 96
.L2:
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$88, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2053:
	.size	_Z30__device_stub__Z11emptyKernelvv, .-_Z30__device_stub__Z11emptyKernelvv
	.globl	_Z11emptyKernelv
	.type	_Z11emptyKernelv, @function
_Z11emptyKernelv:
.LFB2054:
	.cfi_startproc
	endbr64
	jmp	_Z30__device_stub__Z11emptyKernelvv
	.cfi_endproc
.LFE2054:
	.size	_Z11emptyKernelv, .-_Z11emptyKernelv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/ajcalderont/gmai/master/CUDA/src/get_alloc_info.cu"
.LC1:
	.string	"CUDA error: %s - %s(%d)\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$1160, %rsp
	.cfi_def_cfa_offset 1200
	movq	8(%rsi), %rdi
	movq	%fs:40, %rax
	movq	%rax, 1144(%rsp)
	xorl	%eax, %eax
	call	atoi@PLT
	movl	%eax, %edi
	movl	%eax, %ebp
	call	cudaSetDevice@PLT
	testl	%eax, %eax
	je	.L9
	movl	%eax, %edi
	movl	%eax, %ebx
	call	cudaGetErrorString@PLT
	movl	$2, %edi
	movl	$23, %r8d
	leaq	.LC0(%rip), %rcx
	movq	%rax, %rdx
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%ebx, %edi
	call	exit@PLT
.L9:
	movl	$8, %edi
	call	cudaSetDeviceFlags@PLT
	movl	%ebp, %esi
	leaq	112(%rsp), %rdi
	call	cudaGetDeviceProperties_v2@PLT
	leaq	8(%rsp), %rdi
	call	cudaRuntimeGetVersion@PLT
	leaq	12(%rsp), %rdi
	call	cudaDriverGetVersion@PLT
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movabsq	$4294967297, %rdi
	movl	$1, %esi
	movl	$1, 104(%rsp)
	movq	%rdi, %rdx
	movq	%rdi, 96(%rsp)
	movq	%rdi, 80(%rsp)
	movl	$1, 88(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L10
	call	_Z30__device_stub__Z11emptyKernelvv
.L10:
	call	cudaDeviceSynchronize@PLT
	leaq	16(%rsp), %rbp
	movl	$2, %edx
	movl	$1, %esi
	movq	%rbp, %rdi
	leaq	32(%rsp), %r12
	leaq	56(%rsp), %r13
	call	cudaHostAlloc@PLT
	movq	16(%rsp), %rdi
	call	cudaFreeHost@PLT
	movl	$8, %edi
	call	malloc@PLT
	movl	$2, %edx
	movl	$1, %esi
	movq	%rax, %rbx
	movq	%rax, %rdi
	call	cudaHostAlloc@PLT
	movl	$2, %edx
	movl	$1, %esi
	leaq	8(%rbx), %rdi
	call	cudaHostAlloc@PLT
	movq	(%rbx), %rdi
	call	cudaFreeHost@PLT
	movq	8(%rbx), %rdi
	call	cudaFreeHost@PLT
	movq	%rbx, %rdi
	leaq	48(%rsp), %rbx
	call	free@PLT
	xorl	%esi, %esi
	leaq	24(%rsp), %rdi
	movl	$2, %edx
	call	cudaHostAlloc@PLT
	movq	24(%rsp), %rdi
	call	cudaFreeHost@PLT
	movl	$2, %edx
	movl	$2, %esi
	movq	%rbp, %rdi
	call	cudaHostAlloc@PLT
	movq	16(%rsp), %rdi
	leaq	40(%rsp), %rbp
	call	cudaFreeHost@PLT
	xorl	%esi, %esi
	movq	%r12, %rdi
	movl	$2, %edx
	call	cudaHostAlloc@PLT
	xorl	%esi, %esi
	movq	%rbp, %rdi
	movl	$2, %edx
	call	cudaHostAlloc@PLT
	xorl	%esi, %esi
	movq	%rbx, %rdi
	movl	$2, %edx
	call	cudaHostAlloc@PLT
	xorl	%esi, %esi
	movq	%r13, %rdi
	movl	$2, %edx
	call	cudaHostAlloc@PLT
	leaq	64(%rsp), %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	call	cudaHostAlloc@PLT
	xorl	%esi, %esi
	movl	$2, %edx
	leaq	72(%rsp), %rdi
	call	cudaHostAlloc@PLT
	movq	32(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	48(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	64(%rsp), %rdi
	call	cudaFreeHost@PLT
	leaq	80(%rsp), %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	call	cudaHostAlloc@PLT
	movl	$2, %edx
	xorl	%esi, %esi
	leaq	96(%rsp), %rdi
	call	cudaHostAlloc@PLT
	movq	40(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	56(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	72(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	80(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	96(%rsp), %rdi
	call	cudaFreeHost@PLT
	xorl	%esi, %esi
	movq	%r12, %rdi
	movl	$2, %edx
	call	cudaHostAlloc@PLT
	xorl	%esi, %esi
	movq	%rbp, %rdi
	movl	$2, %edx
	call	cudaHostAlloc@PLT
	xorl	%esi, %esi
	movl	$2, %edx
	movq	%rbx, %rdi
	call	cudaHostAlloc@PLT
	movq	32(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	40(%rsp), %rdi
	call	cudaFreeHost@PLT
	xorl	%esi, %esi
	movl	$2, %edx
	movq	%r13, %rdi
	call	cudaHostAlloc@PLT
	movq	48(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	56(%rsp), %rdi
	call	cudaFreeHost@PLT
	xorl	%esi, %esi
	movq	%r12, %rdi
	movl	$2, %edx
	call	cudaHostAlloc@PLT
	xorl	%esi, %esi
	movl	$2, %edx
	movq	%rbp, %rdi
	call	cudaHostAlloc@PLT
	movq	32(%rsp), %rdi
	call	cudaFreeHost@PLT
	movl	$2, %edx
	xorl	%esi, %esi
	movq	%rbx, %rdi
	call	cudaHostAlloc@PLT
	movq	40(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	48(%rsp), %rdi
	call	cudaFreeHost@PLT
	ud2
	.cfi_endproc
.LFE2028:
	.size	main, .-main
	.section	.rodata.str1.1
.LC2:
	.string	"_Z11emptyKernelv"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2056:
	.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	.LC2(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z11emptyKernelv(%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
.LFE2056:
	.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>
#include <stdio.h>
#include <stdlib.h>

__global__ void emptyKernel()
{
}

#define cudaCheck(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(hipError_t code, const char *file, int line, bool abort=true)
{
   if (code != hipSuccess) 
   {
      printf("CUDA error: %s - %s(%d)\n", hipGetErrorString(code), file, line);
      if (abort) exit(code);
   }
}

int main(int argc, char* argv[])
{
	// Initialization
	/*----------------------------------------------------------------------------------------*/
	int device = atoi(argv[1]);
	cudaCheck(hipSetDevice(device));
	hipSetDeviceFlags(hipDeviceMapHost);

	int runtime_version;
	int driver_version;
	hipDeviceProp_t properties;
	hipGetDeviceProperties(&properties, device);
	hipRuntimeGetVersion(&runtime_version);
	hipDriverGetVersion(&driver_version);

	emptyKernel<<<1,1>>>();
	hipDeviceSynchronize();
	
	// Pool size
	/*----------------------------------------------------------------------------------------*/
	int pool_size = 1;
	char *h_data;
	break_01: __attribute__((unused));
	hipHostAlloc((void**)&h_data, 1, hipHostMallocMapped);
	hipHostFree(h_data);
	
	// Maximum allocations and granularity
	/*----------------------------------------------------------------------------------------*/
	char **h_data_array = (char**) malloc(pool_size * sizeof(char*));
	hipHostAlloc((void**)&h_data_array[0], 1, hipHostMallocMapped);
	break_02: __attribute__((unused));
	int granularity = 0, iteration = 0, flag = 0;
	while(!flag && iteration < pool_size)
	{
		iteration++; 
		hipHostAlloc((void**)&h_data_array[iteration], 1, hipHostMallocMapped);
	}
	for(int i = 0; i <= iteration; i++)
	{
		hipHostFree(h_data_array[i]);
	}
	free(h_data_array);
	
	// Size classes
	/*----------------------------------------------------------------------------------------*/
	char *h_data_inf, *h_data_sup;
	int inf_size = granularity, sup_size = granularity, finished = 1, class_finished = 0;
	break_03: __attribute__((unused));
	hipHostAlloc((void**)&h_data_inf, inf_size, hipHostMallocMapped);
	while(!finished)
	{
		sup_size = sup_size + granularity;
		hipHostAlloc((void**)&h_data_sup, sup_size, hipHostMallocMapped);
		hipHostFree(h_data_sup);
		if(class_finished)
		{
			class_finished = 0;
			hipHostFree(h_data_inf);
			inf_size = sup_size;
			hipHostAlloc((void**)&h_data_inf, inf_size, hipHostMallocMapped);
		}
	}
	hipHostFree(h_data_inf);
	
	// Larger allocations
	/*----------------------------------------------------------------------------------------*/
	break_04: __attribute__((unused));
	hipHostAlloc((void**)&h_data, pool_size + 1, hipHostMallocMapped);
	hipHostFree(h_data);

	// Allocator policy
	/*----------------------------------------------------------------------------------------*/
	char *chunk_1, *chunk_2, *chunk_3, *chunk_4, *chunk_5, *chunk_6, *chunk_7, *chunk_8, *chunk_9, *chunk_10;
	hipHostAlloc((void**)&chunk_1, granularity * 2, hipHostMallocMapped);
	hipHostAlloc((void**)&chunk_2, granularity, hipHostMallocMapped);
	hipHostAlloc((void**)&chunk_3, granularity * 2, hipHostMallocMapped);
	hipHostAlloc((void**)&chunk_4, granularity, hipHostMallocMapped);
	hipHostAlloc((void**)&chunk_5, granularity, hipHostMallocMapped);
	hipHostAlloc((void**)&chunk_6, granularity, hipHostMallocMapped);
	hipHostFree(chunk_1);
	hipHostFree(chunk_3);
	hipHostFree(chunk_5);
	hipHostAlloc((void**)&chunk_7, granularity, hipHostMallocMapped);
	hipHostAlloc((void**)&chunk_8, granularity, hipHostMallocMapped);
	break_05: __attribute__((unused));
	hipHostFree(chunk_2);
	hipHostFree(chunk_4);
	hipHostFree(chunk_6);
	hipHostFree(chunk_7);
	hipHostFree(chunk_8);

	// Coalescing support
	/*----------------------------------------------------------------------------------------*/
	hipHostAlloc((void**)&chunk_1, granularity, hipHostMallocMapped);
	hipHostAlloc((void**)&chunk_2, granularity, hipHostMallocMapped);
	hipHostAlloc((void**)&chunk_3, granularity, hipHostMallocMapped);
	hipHostFree(chunk_1);
	hipHostFree(chunk_2);
	hipHostAlloc((void**)&chunk_4, granularity * 2, hipHostMallocMapped);
	break_06: __attribute__((unused));
	hipHostFree(chunk_3);
	hipHostFree(chunk_4);

	// Splitting support
	/*----------------------------------------------------------------------------------------*/
	hipHostAlloc((void**)&chunk_1, granularity * 2, hipHostMallocMapped);
	hipHostAlloc((void**)&chunk_2, granularity, hipHostMallocMapped);
	hipHostFree(chunk_1);
	hipHostAlloc((void**)&chunk_3, granularity, hipHostMallocMapped);
	break_07: __attribute__((unused));
	hipHostFree(chunk_2);
	hipHostFree(chunk_3);

	// Expansion policy
	/*----------------------------------------------------------------------------------------*/
	int max_allocations = pool_size / granularity;
	h_data_array = (char**) malloc(max_allocations * sizeof(char*));
	hipHostAlloc((void**)&h_data_array[0], granularity, hipHostMallocMapped);
	break_08: __attribute__((unused));
	int index;
	for(index = 1; index < max_allocations; index++)
	{
		hipHostAlloc((void**)&h_data_array[index], granularity, hipHostMallocMapped);
	}
	for(index = 0; index < max_allocations; index++)
	{
		hipHostFree(h_data_array[index]);
	}
	free(h_data_array);


	// Pool usage
	/*----------------------------------------------------------------------------------------*/
	int quarter = pool_size / 4;
	hipHostAlloc((void**)&chunk_1, quarter, hipHostMallocMapped);
	hipHostAlloc((void**)&chunk_2, quarter, hipHostMallocMapped);
	hipHostAlloc((void**)&chunk_3, quarter, hipHostMallocMapped);
	hipHostAlloc((void**)&chunk_4, quarter, hipHostMallocMapped);
	hipHostAlloc((void**)&chunk_5, quarter, hipHostMallocMapped);
	hipHostAlloc((void**)&chunk_6, quarter, hipHostMallocMapped);
	hipHostAlloc((void**)&chunk_7, quarter, hipHostMallocMapped);
	hipHostAlloc((void**)&chunk_8, quarter, hipHostMallocMapped);
	hipHostAlloc((void**)&chunk_9, quarter, hipHostMallocMapped);
	hipHostFree(chunk_1);
	hipHostFree(chunk_2);
	hipHostFree(chunk_5);
	hipHostAlloc((void**)&chunk_10, quarter, hipHostMallocMapped);
	break_09: __attribute__((unused));
	hipHostFree(chunk_10);

	// Shrinking support
	/*----------------------------------------------------------------------------------------*/
	flag = 0;
	break_10: __attribute__((unused));
	hipHostFree(chunk_6);
	hipHostFree(chunk_7);
	hipHostFree(chunk_8);
	flag = 1;
	hipHostFree(chunk_9);
	flag = 2;
	hipHostFree(chunk_3);
	hipHostFree(chunk_4);

	// Finalization
	/*----------------------------------------------------------------------------------------*/
	hipDeviceReset();
	return 0;
}
	.text
	.file	"get_alloc_info.hip"
	.globl	_Z26__device_stub__emptyKernelv # -- Begin function _Z26__device_stub__emptyKernelv
	.type	_Z26__device_stub__emptyKernelv,@function
_Z26__device_stub__emptyKernelv:        # @_Z26__device_stub__emptyKernelv
	.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	$56, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rbx
	leaq	24(%rsp), %r14
	leaq	16(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%rbx, %rdi
	movq	%r14, %rsi
	movq	%r15, %rdx
	movq	%r12, %rcx
	callq	__hipPopCallConfiguration
	movq	(%rbx), %rsi
	movl	8(%rbx), %edx
	movq	(%r14), %rcx
	movl	8(%r14), %r8d
	movq	%rsp, %r9
	movl	$_Z11emptyKernelv, %edi
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	pushq	(%r15)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$72, %rsp
	.cfi_adjust_cfa_offset -72
	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_end0:
	.size	_Z26__device_stub__emptyKernelv, .Lfunc_end0-_Z26__device_stub__emptyKernelv
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function 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	$1560, %rsp                     # imm = 0x618
	.cfi_def_cfa_offset 1616
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %ebp
	movl	%eax, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	je	.LBB1_1
# %bb.4:
	movl	%eax, %ebx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %edi
	movl	$.L.str, %edx
	movq	%rax, %rsi
	movl	$25, %ecx
	xorl	%eax, %eax
	callq	printf
	movl	%ebx, %edi
	callq	exit
.LBB1_1:                                # %_Z9gpuAssert10hipError_tPKcib.exit
	movl	$8, %edi
	callq	hipSetDeviceFlags
	leaq	88(%rsp), %rdi
	movl	%ebp, %esi
	callq	hipGetDevicePropertiesR0600
	leaq	20(%rsp), %rdi
	callq	hipRuntimeGetVersion
	leaq	16(%rsp), %rdi
	callq	hipDriverGetVersion
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	movl	$1, %esi
	movq	%rdi, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_3
# %bb.2:
	callq	_Z26__device_stub__emptyKernelv
.LBB1_3:                                # %.critedge
	callq	hipDeviceSynchronize
	leaq	80(%rsp), %rbx
	movl	$1, %esi
	movq	%rbx, %rdi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	(%rbx), %rdi
	callq	hipHostFree
	movl	$8, %edi
	callq	malloc
	movq	%rax, %r14
	movl	$1, %esi
	movq	%rax, %rdi
	movl	$2, %edx
	callq	hipHostAlloc
	leaq	8(%r14), %rdi
	movl	$1, %esi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	(%r14), %rdi
	callq	hipHostFree
	movq	8(%r14), %rdi
	callq	hipHostFree
	movq	%r14, %rdi
	callq	free
	leaq	72(%rsp), %r14
	movq	%r14, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	(%r14), %rdi
	callq	hipHostFree
	movl	$2, %esi
	movq	%rbx, %rdi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	(%rbx), %rdi
	callq	hipHostFree
	leaq	64(%rsp), %r15
	movq	%r15, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	hipHostAlloc
	leaq	56(%rsp), %r14
	movq	%r14, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	%rsp, %rdi
	movq	%rdi, %rbx
	xorl	%esi, %esi
	movl	$2, %edx
	callq	hipHostAlloc
	leaq	8(%rsp), %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	hipHostAlloc
	leaq	48(%rsp), %rbp
	movq	%rbp, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	hipHostAlloc
	leaq	40(%rsp), %r13
	movq	%r13, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	(%r15), %rdi
	callq	hipHostFree
	movq	(%rbx), %rdi
	callq	hipHostFree
	movq	(%rbp), %rdi
	callq	hipHostFree
	leaq	32(%rsp), %rbp
	movq	%rbp, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	hipHostAlloc
	leaq	24(%rsp), %r12
	movq	%r12, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	(%r14), %rdi
	callq	hipHostFree
	leaq	8(%rsp), %rbx
	movq	(%rbx), %rdi
	callq	hipHostFree
	movq	(%r13), %rdi
	callq	hipHostFree
	movq	(%rbp), %rdi
	callq	hipHostFree
	movq	(%r12), %rdi
	callq	hipHostFree
	movq	%r15, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	%r14, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	%rsp, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	(%r15), %rdi
	callq	hipHostFree
	movq	(%r14), %rdi
	callq	hipHostFree
	movq	%rbx, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	%rsp, %r12
	movq	(%r12), %rdi
	callq	hipHostFree
	movq	(%rbx), %rdi
	callq	hipHostFree
	movq	%r15, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	%r14, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	(%r15), %rdi
	callq	hipHostFree
	movq	%r12, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	(%r14), %rdi
	callq	hipHostFree
	movq	(%r12), %rdi
	callq	hipHostFree
	callq	malloc
	movq	%rax, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	hipHostAlloc
.Lfunc_end1:
	.size	main, .Lfunc_end1-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	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z11emptyKernelv, %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_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__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	.LBB3_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
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z11emptyKernelv,@object        # @_Z11emptyKernelv
	.section	.rodata,"a",@progbits
	.globl	_Z11emptyKernelv
	.p2align	3, 0x0
_Z11emptyKernelv:
	.quad	_Z26__device_stub__emptyKernelv
	.size	_Z11emptyKernelv, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/ajcalderont/gmai/master/CUDA/src/get_alloc_info.hip"
	.size	.L.str, 114

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"CUDA error: %s - %s(%d)\n"
	.size	.L.str.1, 25

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z11emptyKernelv"
	.size	.L__unnamed_1, 17

	.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 _Z26__device_stub__emptyKernelv
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z11emptyKernelv
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z11emptyKernelv        ; -- Begin function _Z11emptyKernelv
	.globl	_Z11emptyKernelv
	.p2align	8
	.type	_Z11emptyKernelv,@function
_Z11emptyKernelv:                       ; @_Z11emptyKernelv
; %bb.0:
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z11emptyKernelv
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 0
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 0
		.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 1
		.amdhsa_next_free_sgpr 1
		.amdhsa_reserve_vcc 0
		.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	_Z11emptyKernelv, .Lfunc_end0-_Z11emptyKernelv
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 4
; NumSgprs: 0
; NumVgprs: 0
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 0
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 1
; NumVGPRsForWavesPerEU: 1
; 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:           []
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 4
    .kernarg_segment_size: 0
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z11emptyKernelv
    .private_segment_fixed_size: 0
    .sgpr_count:     0
    .sgpr_spill_count: 0
    .symbol:         _Z11emptyKernelv.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     0
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
