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

int csv_check(char* path)
{
    if (access(path, F_OK))
    {   
        printf("Cannot find the file at %s\n", path);
        return -1;
    } 
    if (access(path, R_OK)) 
    {
        printf("Cannot read the file at %s\n", path);
        return -1;
    }
    return 0;
}
/* this flie takes three parameters:
 *      char* file: path to the txt file formatted in csv
 *      int** output: pointer stores data in the csv file
 *      int* line: pointer to line count
 */
int read_csv(char* file, int** output, int *line)
{
    if (csv_check(file))
    {
        //error detected
        printf("RuntimeError: Cannot access the file at %s\n", file);
        return -1;
    } 
    else 
    {
        // check passed
        // allocate memory
        *line = 0;

        // read the csv file
        //printf("GOOD TILL HERE\n");
	FILE* f = fopen(file, "r");
        //printf("Still good\n");
	char *tmp = (char *)calloc(10, sizeof(char));
        char *token;
        if (f)
        {
		//printf("test\n");
		while(fgets(tmp, 10, f))
            	{
			//printf("line=%d\n",*line);
			//printf("boom\n");
		        *(output+*line) = (int *)calloc(3, sizeof(int));
			token = strtok(tmp, ",");
                	//printf("line=%d\n",*line);
			int i = 0;
                	while(token!=NULL)
                	{
                    		*(*(output+*line)+i) = atoi(token);
                    		token = strtok(NULL, ",");
                    		i++;
                	}
		        *line = *line + 1;
            	}
        }
	
        fclose(f);
	//printf("error\n");
        tmp = NULL;
        free(tmp);

        return 0;
    }
}

int read_csv_array(char* file, int* output, int *line)
{
	if (csv_check(file))
	{
		printf("RuntimeError: Cannot access the file at %s\n", file);
		return -1;
	}
	else
	{
		*line = 0;
		FILE* f = fopen(file, "r");
		char *tmp = (char *)calloc(10, sizeof(char));
		char *token;
		if (f) 
		{
			while(fgets(tmp,10,f))
			{
				token = strtok(tmp, ",");
				for(int i = 0; i<3; i++)
				{
					*(output + *line * 3 + i) = atoi(token);
					token = strtok(NULL, ",");
				}
				*line = *line + 1;
			}
		}
		fclose(f);

		tmp = NULL;
		free(tmp);

		return 0;
	}
}	

int save(char* file, int* results, int size)
{
    FILE *f = fopen(file, "w");
    if (f)
    {
        for(int i=0; i<size; i++)
        {
            fprintf(f, "%d\n", *(results+i));
        }
    }
    fclose(f);
    return 0;
}

// an example of how to use this read_csv and save
/*
int main(){
 	char *test="../res/input_10000.txt";
 	int line = 0;
 	int **output = (int **)calloc(1000000, sizeof(int *));
 	read_csv(test, output, &line);
 	for(int i=0; i<line; i++){
 		printf("line %d: input1: %d, linput2: %d, type: %d\n", i, **(output+i), *(*(output+i)+1), *(*(output+i)+2));
     }
 	printf("Total: %d\n", line);
 	output = NULL;
 	free(output);

	int result[3] = {1,2,3};
      	save("./test.txt", result, 3);

 	return 0;
}
*/

	.file	"tmpxft_0028b9cd_00000000-6_reader.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2046:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2046:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Cannot find the file at %s\n"
.LC1:
	.string	"Cannot read the file at %s\n"
	.text
	.globl	_Z9csv_checkPc
	.type	_Z9csv_checkPc, @function
_Z9csv_checkPc:
.LFB2040:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	xorl	%esi, %esi
	movq	%rdi, %rbx
	call	access@PLT
	movq	%rbx, %rdx
	leaq	.LC0(%rip), %rsi
	testl	%eax, %eax
	jne	.L10
	movl	$4, %esi
	movq	%rbx, %rdi
	call	access@PLT
	testl	%eax, %eax
	je	.L2
	movq	%rbx, %rdx
	leaq	.LC1(%rip), %rsi
.L10:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	orl	$-1, %eax
.L2:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2040:
	.size	_Z9csv_checkPc, .-_Z9csv_checkPc
	.section	.rodata.str1.1
.LC2:
	.string	"RuntimeError: Cannot access the file at %s\n"
.LC3:
	.string	"r"
.LC4:
	.string	","
	.text
	.globl	_Z8read_csvPcPPiS0_
	.type	_Z8read_csvPcPPiS0_, @function
_Z8read_csvPcPPiS0_:
.LFB2041:
	.cfi_startproc
	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
	movq	%rsi, %r13
	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
	movq	%rdx, %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	%rdi, 8(%rsp)
	call	_Z9csv_checkPc
	movq	8(%rsp), %rdi
	testl	%eax, %eax
	je	.L13
	movq	%rdi, %rdx
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	orl	$-1, %ebp
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L12
.L13:
	movl	%eax, %ebp
	xorl	%eax, %eax
	leaq	.LC3(%rip), %rsi
	movl	%eax, (%rbx)
	call	fopen@PLT
	movl	$1, %esi
	movl	$10, %edi
	movq	%rax, %r12
	call	calloc@PLT
	movq	%rax, 8(%rsp)
	testq	%r12, %r12
	jne	.L15
.L19:
	movq	%r12, %rdi
	call	fclose@PLT
	jmp	.L12
.L22:
	incl	%eax
	movl	%eax, (%rbx)
.L15:
	movq	8(%rsp), %rdi
	movq	%r12, %rcx
	movl	$10, %edx
	movl	$10, %esi
	call	__fgets_chk@PLT
	testq	%rax, %rax
	je	.L19
	movslq	(%rbx), %rax
	movl	$4, %esi
	movl	$3, %edi
	xorl	%r14d, %r14d
	leaq	0(%r13,%rax,8), %r15
	call	calloc@PLT
	movq	8(%rsp), %rdi
	leaq	.LC4(%rip), %rsi
	movq	%rax, (%r15)
	call	strtok@PLT
	movq	%rax, %rdi
.L16:
	movslq	(%rbx), %rax
	testq	%rdi, %rdi
	je	.L22
	movq	0(%r13,%rax,8), %r15
	call	atoi@PLT
	xorl	%edi, %edi
	leaq	.LC4(%rip), %rsi
	addq	%r14, %r15
	addq	$4, %r14
	movl	%eax, (%r15)
	call	strtok@PLT
	movq	%rax, %rdi
	jmp	.L16
.L12:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	movl	%ebp, %eax
	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
.LFE2041:
	.size	_Z8read_csvPcPPiS0_, .-_Z8read_csvPcPPiS0_
	.globl	_Z14read_csv_arrayPcPiS0_
	.type	_Z14read_csv_arrayPcPiS0_, @function
_Z14read_csv_arrayPcPiS0_:
.LFB2042:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rsi, %r14
	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
	movq	%rdx, %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	%rdi, 8(%rsp)
	call	_Z9csv_checkPc
	movq	8(%rsp), %rdi
	testl	%eax, %eax
	je	.L24
	movq	%rdi, %rdx
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	orl	$-1, %ebp
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L23
.L24:
	movl	%eax, %ebp
	xorl	%eax, %eax
	leaq	.LC3(%rip), %rsi
	movl	%eax, (%rbx)
	call	fopen@PLT
	movl	$1, %esi
	movl	$10, %edi
	movq	%rax, %r12
	call	calloc@PLT
	movq	%rax, 8(%rsp)
	testq	%r12, %r12
	jne	.L26
.L29:
	movq	%r12, %rdi
	call	fclose@PLT
	jmp	.L23
.L27:
	imull	$3, (%rbx), %eax
	cltq
	addq	%r13, %rax
	incq	%r13
	leaq	(%r14,%rax,4), %r15
	call	atoi@PLT
	xorl	%edi, %edi
	leaq	.LC4(%rip), %rsi
	movl	%eax, (%r15)
	call	strtok@PLT
	movq	%rax, %rdi
	cmpq	$3, %r13
	jne	.L27
	incl	(%rbx)
.L26:
	movq	8(%rsp), %rdi
	movq	%r12, %rcx
	movl	$10, %edx
	movl	$10, %esi
	call	__fgets_chk@PLT
	testq	%rax, %rax
	je	.L29
	movq	8(%rsp), %rdi
	leaq	.LC4(%rip), %rsi
	xorl	%r13d, %r13d
	call	strtok@PLT
	movq	%rax, %rdi
	jmp	.L27
.L23:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	movl	%ebp, %eax
	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
.LFE2042:
	.size	_Z14read_csv_arrayPcPiS0_, .-_Z14read_csv_arrayPcPiS0_
	.section	.rodata.str1.1
.LC5:
	.string	"w"
.LC6:
	.string	"%d\n"
	.text
	.globl	_Z4savePcPii
	.type	_Z4savePcPii, @function
_Z4savePcPii:
.LFB2043:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC6(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%rsi, %r13
	leaq	.LC5(%rip), %rsi
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	call	fopen@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	je	.L36
.L34:
	cmpl	%ebp, %r12d
	jle	.L36
	movl	0(%r13,%rbp,4), %ecx
	movq	%r14, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	incq	%rbp
	call	__fprintf_chk@PLT
	jmp	.L34
.L36:
	movq	%rbx, %rdi
	call	fclose@PLT
	popq	%rbx
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	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
.LFE2043:
	.size	_Z4savePcPii, .-_Z4savePcPii
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2069:
	.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
.LFE2069:
	.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>
#include <unistd.h>
#include <string.h>

int csv_check(char* path)
{
    if (access(path, F_OK))
    {   
        printf("Cannot find the file at %s\n", path);
        return -1;
    } 
    if (access(path, R_OK)) 
    {
        printf("Cannot read the file at %s\n", path);
        return -1;
    }
    return 0;
}
/* this flie takes three parameters:
 *      char* file: path to the txt file formatted in csv
 *      int** output: pointer stores data in the csv file
 *      int* line: pointer to line count
 */
int read_csv(char* file, int** output, int *line)
{
    if (csv_check(file))
    {
        //error detected
        printf("RuntimeError: Cannot access the file at %s\n", file);
        return -1;
    } 
    else 
    {
        // check passed
        // allocate memory
        *line = 0;

        // read the csv file
        //printf("GOOD TILL HERE\n");
	FILE* f = fopen(file, "r");
        //printf("Still good\n");
	char *tmp = (char *)calloc(10, sizeof(char));
        char *token;
        if (f)
        {
		//printf("test\n");
		while(fgets(tmp, 10, f))
            	{
			//printf("line=%d\n",*line);
			//printf("boom\n");
		        *(output+*line) = (int *)calloc(3, sizeof(int));
			token = strtok(tmp, ",");
                	//printf("line=%d\n",*line);
			int i = 0;
                	while(token!=NULL)
                	{
                    		*(*(output+*line)+i) = atoi(token);
                    		token = strtok(NULL, ",");
                    		i++;
                	}
		        *line = *line + 1;
            	}
        }
	
        fclose(f);
	//printf("error\n");
        tmp = NULL;
        free(tmp);

        return 0;
    }
}

int read_csv_array(char* file, int* output, int *line)
{
	if (csv_check(file))
	{
		printf("RuntimeError: Cannot access the file at %s\n", file);
		return -1;
	}
	else
	{
		*line = 0;
		FILE* f = fopen(file, "r");
		char *tmp = (char *)calloc(10, sizeof(char));
		char *token;
		if (f) 
		{
			while(fgets(tmp,10,f))
			{
				token = strtok(tmp, ",");
				for(int i = 0; i<3; i++)
				{
					*(output + *line * 3 + i) = atoi(token);
					token = strtok(NULL, ",");
				}
				*line = *line + 1;
			}
		}
		fclose(f);

		tmp = NULL;
		free(tmp);

		return 0;
	}
}	

int save(char* file, int* results, int size)
{
    FILE *f = fopen(file, "w");
    if (f)
    {
        for(int i=0; i<size; i++)
        {
            fprintf(f, "%d\n", *(results+i));
        }
    }
    fclose(f);
    return 0;
}

// an example of how to use this read_csv and save
/*
int main(){
 	char *test="../res/input_10000.txt";
 	int line = 0;
 	int **output = (int **)calloc(1000000, sizeof(int *));
 	read_csv(test, output, &line);
 	for(int i=0; i<line; i++){
 		printf("line %d: input1: %d, linput2: %d, type: %d\n", i, **(output+i), *(*(output+i)+1), *(*(output+i)+2));
     }
 	printf("Total: %d\n", line);
 	output = NULL;
 	free(output);

	int result[3] = {1,2,3};
      	save("./test.txt", result, 3);

 	return 0;
}
*/

	.text
	.file	"reader.hip"
	.globl	_Z9csv_checkPc                  # -- Begin function _Z9csv_checkPc
	.type	_Z9csv_checkPc,@function
_Z9csv_checkPc:                         # @_Z9csv_checkPc
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.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 %rbp, -16
	movq	%rdi, %rbx
	xorl	%ebp, %ebp
	xorl	%esi, %esi
	callq	access
	movl	$.L.str, %edi
	testl	%eax, %eax
	jne	.LBB0_2
# %bb.1:
	movq	%rbx, %rdi
	movl	$4, %esi
	callq	access
	movl	$.L.str.1, %edi
	testl	%eax, %eax
	je	.LBB0_3
.LBB0_2:                                # %.sink.split
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$-1, %ebp
.LBB0_3:
	movl	%ebp, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z9csv_checkPc, .Lfunc_end0-_Z9csv_checkPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z8read_csvPcPPiS0_             # -- Begin function _Z8read_csvPcPPiS0_
	.type	_Z8read_csvPcPPiS0_,@function
_Z8read_csvPcPPiS0_:                    # @_Z8read_csvPcPPiS0_
	.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
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdx, %rbx
	movq	%rsi, %r14
	movq	%rdi, %r15
	callq	_Z9csv_checkPc
	testl	%eax, %eax
	je	.LBB1_2
# %bb.1:
	movl	$.L.str.2, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$-1, %eax
	jmp	.LBB1_10
.LBB1_2:
	movl	$0, (%rbx)
	movl	$.L.str.3, %esi
	movq	%r15, %rdi
	callq	fopen
	movq	%rax, %r15
	movl	$10, %edi
	movl	$1, %esi
	callq	calloc
	testq	%r15, %r15
	je	.LBB1_9
# %bb.3:                                # %.preheader
	movq	%rax, %r12
.LBB1_4:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_7 Depth 2
	movq	%r12, %rdi
	movl	$10, %esi
	movq	%r15, %rdx
	callq	fgets
	testq	%rax, %rax
	je	.LBB1_9
# %bb.5:                                # %.lr.ph29
                                        #   in Loop: Header=BB1_4 Depth=1
	movl	$3, %edi
	movl	$4, %esi
	callq	calloc
	movslq	(%rbx), %rcx
	movq	%rax, (%r14,%rcx,8)
	movl	$.L.str.4, %esi
	movq	%r12, %rdi
	callq	strtok
	testq	%rax, %rax
	je	.LBB1_8
# %bb.6:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB1_4 Depth=1
	xorl	%r13d, %r13d
.LBB1_7:                                # %.lr.ph
                                        #   Parent Loop BB1_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%rax, %rdi
	callq	atoi
	movslq	(%rbx), %rcx
	movq	(%r14,%rcx,8), %rcx
	movl	%eax, (%rcx,%r13)
	movl	$.L.str.4, %esi
	xorl	%edi, %edi
	callq	strtok
	addq	$4, %r13
	testq	%rax, %rax
	jne	.LBB1_7
.LBB1_8:                                # %._crit_edge
                                        #   in Loop: Header=BB1_4 Depth=1
	incl	(%rbx)
	jmp	.LBB1_4
.LBB1_9:                                # %.loopexit
	movq	%r15, %rdi
	callq	fclose
	xorl	%eax, %eax
.LBB1_10:
	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	_Z8read_csvPcPPiS0_, .Lfunc_end1-_Z8read_csvPcPPiS0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z14read_csv_arrayPcPiS0_       # -- Begin function _Z14read_csv_arrayPcPiS0_
	.type	_Z14read_csv_arrayPcPiS0_,@function
_Z14read_csv_arrayPcPiS0_:              # @_Z14read_csv_arrayPcPiS0_
	.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
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdx, %rbx
	movq	%rsi, %r14
	movq	%rdi, %r15
	callq	_Z9csv_checkPc
	testl	%eax, %eax
	je	.LBB2_2
# %bb.1:
	movl	$.L.str.2, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$-1, %eax
	jmp	.LBB2_9
.LBB2_2:
	movl	$0, (%rbx)
	movl	$.L.str.3, %esi
	movq	%r15, %rdi
	callq	fopen
	movq	%rax, %r15
	movl	$10, %edi
	movl	$1, %esi
	callq	calloc
	testq	%r15, %r15
	je	.LBB2_8
# %bb.3:                                # %.preheader
	movq	%rax, %r12
.LBB2_4:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_6 Depth 2
	movq	%r12, %rdi
	movl	$10, %esi
	movq	%r15, %rdx
	callq	fgets
	testq	%rax, %rax
	je	.LBB2_8
# %bb.5:                                # %.lr.ph
                                        #   in Loop: Header=BB2_4 Depth=1
	movl	$.L.str.4, %esi
	movq	%r12, %rdi
	callq	strtok
	xorl	%r13d, %r13d
.LBB2_6:                                #   Parent Loop BB2_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%rax, %rdi
	callq	atoi
	movslq	(%rbx), %rcx
	leaq	(%rcx,%rcx,2), %rcx
	leaq	(%r14,%rcx,4), %rcx
	movl	%eax, (%rcx,%r13,4)
	movl	$.L.str.4, %esi
	xorl	%edi, %edi
	callq	strtok
	incq	%r13
	cmpq	$3, %r13
	jne	.LBB2_6
# %bb.7:                                #   in Loop: Header=BB2_4 Depth=1
	incl	(%rbx)
	jmp	.LBB2_4
.LBB2_8:                                # %.loopexit
	movq	%r15, %rdi
	callq	fclose
	xorl	%eax, %eax
.LBB2_9:
	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_end2:
	.size	_Z14read_csv_arrayPcPiS0_, .Lfunc_end2-_Z14read_csv_arrayPcPiS0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z4savePcPii                    # -- Begin function _Z4savePcPii
	.type	_Z4savePcPii,@function
_Z4savePcPii:                           # @_Z4savePcPii
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebp
	movq	%rsi, %rbx
	movl	$.L.str.5, %esi
	callq	fopen
	movq	%rax, %r14
	testq	%rax, %rax
	je	.LBB3_4
# %bb.1:
	testl	%ebp, %ebp
	jle	.LBB3_4
# %bb.2:                                # %.lr.ph.preheader
	movl	%ebp, %r15d
	xorl	%r12d, %r12d
.LBB3_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	(%rbx,%r12,4), %edx
	movl	$.L.str.6, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB3_3
.LBB3_4:                                # %.loopexit
	movq	%r14, %rdi
	callq	fclose
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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_end3:
	.size	_Z4savePcPii, .Lfunc_end3-_Z4savePcPii
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Cannot find the file at %s\n"
	.size	.L.str, 28

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Cannot read the file at %s\n"
	.size	.L.str.1, 28

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"RuntimeError: Cannot access the file at %s\n"
	.size	.L.str.2, 44

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"r"
	.size	.L.str.3, 2

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	","
	.size	.L.str.4, 2

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"w"
	.size	.L.str.5, 2

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"%d\n"
	.size	.L.str.6, 4

	.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
