// File: /workspace/github_c_makefile_star2_O0/mikecat[P]x86_interpreter/read_file.c
// Function: read_whole_file
void* read_whole_file(size_t* size, const char* filename) {
	FILE* fp;
	size_t read_size = 0;
	char* buffer = NULL;
	fp = fopen(filename, "rb");
	if (fp == NULL) {
		fprintf(stderr, "input file open failed\n");
		return NULL;
	}
	for (;;) {
		char data[BUFFER_SIZE];
		size_t new_read_size = fread(data, sizeof(*data), BUFFER_SIZE, fp);
		if (ferror(fp)) {
			fprintf(stderr, "input file read error\n");
			fclose(fp);
			free(buffer);
			return NULL;
		} else if (new_read_size == 0) {
			break;
		} else {
			char *new_buffer;
			if (SIZE_MAX - read_size < new_read_size) {
				fprintf(stderr, "input file too big\n");
				fclose(fp);
				free(buffer);
				return NULL;
			}
			new_buffer = realloc(buffer, read_size + new_read_size);
			if (new_buffer == NULL) {
				perror("realloc");
				free(buffer);
				fclose(fp);
				return NULL;
			}
			buffer = new_buffer;
			memcpy(buffer + read_size, data, new_read_size);
			read_size += new_read_size;
		}
	}
	fclose(fp);
	if (size != NULL) *size = read_size;
	return buffer;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1040, %rsp           # imm = 0x1040
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x18(%rbp), %rdi
leaq 0x5882(%rip), %rsi      # 0x12050
callq 0x1160
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0xc803
movq 0x880b(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
leaq 0x5864(%rip), %rsi      # 0x12053
movb $0x0, %al
callq 0x10d0
movq $0x0, -0x8(%rbp)
jmp 0xc971
jmp 0xc805
leaq -0x1030(%rbp), %rdi
movq -0x20(%rbp), %rcx
movl $0x1, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x1060
movq %rax, -0x1038(%rbp)
movq -0x20(%rbp), %rdi
callq 0x1050
cmpl $0x0, %eax
je 0xc86b
movq 0x87b5(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
leaq 0x5826(%rip), %rsi      # 0x1206b
movb $0x0, %al
callq 0x10d0
movq -0x20(%rbp), %rdi
callq 0x1070
movq -0x30(%rbp), %rdi
callq 0x1030
movq $0x0, -0x8(%rbp)
jmp 0xc971
cmpq $0x0, -0x1038(%rbp)
jne 0xc87a
jmp 0xc94e
movq $-0x1, %rax
subq -0x28(%rbp), %rax
cmpq -0x1038(%rbp), %rax
jae 0xc8c5
movq 0x875b(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
leaq 0x57e3(%rip), %rsi      # 0x12082
movb $0x0, %al
callq 0x10d0
movq -0x20(%rbp), %rdi
callq 0x1070
movq -0x30(%rbp), %rdi
callq 0x1030
movq $0x0, -0x8(%rbp)
jmp 0xc971
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq -0x1038(%rbp), %rsi
callq 0x1140
movq %rax, -0x1040(%rbp)
cmpq $0x0, -0x1040(%rbp)
jne 0xc912
leaq 0x57a5(%rip), %rdi      # 0x12096
callq 0x1170
movq -0x30(%rbp), %rdi
callq 0x1030
movq -0x20(%rbp), %rdi
callq 0x1070
movq $0x0, -0x8(%rbp)
jmp 0xc971
movq -0x1040(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
addq -0x28(%rbp), %rdi
leaq -0x1030(%rbp), %rsi
movq -0x1038(%rbp), %rdx
callq 0x10e0
movq -0x1038(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0xc949
jmp 0xc805
movq -0x20(%rbp), %rdi
callq 0x1070
cmpq $0x0, -0x10(%rbp)
je 0xc969
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x1040, %rsp           # imm = 0x1040
popq %rbp
retq
nop