// File: gersteinlab[P]MUSIC/src/ms_utils.cpp
// Function: load_file(char*)
t_file_buffer* load_file(char* fp)
{
	FILE* f = NULL;

	// If the file is "stdin", load the standard input.
	if(strcmp(fp, "stdin") == 0)
	{
		fprintf(stderr, "Cannot buffer stdin.\n");
		return(NULL);
	}
	else
	{
		// Open the file if it is not the stdin.
		f = fopen(fp, "rb");
		if (f == NULL) 
		{ 
			fprintf(stderr, "Could not open %s\n", fp);
			return(NULL);
		} 
	}

	fseek(f, 0, SEEK_END);
	long int file_size = ftell(f);
if(__DUMP_UTIL_MESSAGES__)
{
	fprintf(stderr, "Loading %s of %ld bytes.\n", fp, file_size);
}

	fseek(f, 0, SEEK_SET);
	char* file_buff = new char[file_size + 1];

if(__DUMP_UTIL_MESSAGES__)
{
	fprintf(stderr, "Allocated buffer memory.\n");
}

	if (file_size != (long int)fread(file_buff, sizeof(char), file_size, f)) 
	{ 
		delete [] file_buff;
		return NULL;
	}

if(__DUMP_UTIL_MESSAGES__)
{
	fprintf(stderr, "Read successfully.\n");
}

	fclose(f);
	file_buff[file_size] = 0;

	t_file_buffer* file_buffer = new t_file_buffer();
	file_buffer->file_buffer = file_buff;
	file_buffer->f_ptr = 0;
	file_buffer->l_file = file_size;

	return file_buffer;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x38(%rsp), %rdi
leaq 0x1070f(%rip), %rsi     # 0x556bd
callq 0x2240
cmpl $0x0, %eax
jne 0x44fde
movq 0x20021(%rip), %rax     # 0x64fe0
movq (%rax), %rdi
leaq 0x11b46(%rip), %rsi     # 0x56b0f
movb $0x0, %al
callq 0x2250
movq $0x0, 0x40(%rsp)
jmp 0x451a3
movq 0x38(%rsp), %rdi
leaq 0x11316(%rip), %rsi     # 0x56300
callq 0x21d0
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x45027
movq 0x1ffdd(%rip), %rax     # 0x64fe0
movq (%rax), %rdi
movq 0x38(%rsp), %rdx
leaq 0x1072f(%rip), %rsi     # 0x55741
movb $0x0, %al
callq 0x2250
movq $0x0, 0x40(%rsp)
jmp 0x451a3
jmp 0x45029
movq 0x30(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x21b0
movq 0x30(%rsp), %rdi
callq 0x2030
movq %rax, 0x28(%rsp)
testb $0x1, 0x20192(%rip)     # 0x651e4
je 0x45076
movq 0x1ff85(%rip), %rax     # 0x64fe0
movq (%rax), %rdi
movq 0x38(%rsp), %rdx
movq 0x28(%rsp), %rcx
leaq 0x11ab6(%rip), %rsi     # 0x56b25
movb $0x0, %al
callq 0x2250
movq 0x30(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x21b0
movq 0x28(%rsp), %rdi
addq $0x1, %rdi
callq 0x2040
movq %rax, 0x20(%rsp)
testb $0x1, 0x20144(%rip)     # 0x651e4
je 0x450ba
movq 0x1ff37(%rip), %rax     # 0x64fe0
movq (%rax), %rdi
leaq 0x11a8c(%rip), %rsi     # 0x56b3f
movb $0x0, %al
callq 0x2250
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rcx
movl $0x1, %esi
callq 0x2270
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
je 0x45112
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x45104
movq 0x8(%rsp), %rdi
callq 0x2220
movq $0x0, 0x40(%rsp)
jmp 0x451a3
testb $0x1, 0x200cb(%rip)     # 0x651e4
je 0x45133
movq 0x1febe(%rip), %rax     # 0x64fe0
movq (%rax), %rdi
leaq 0x11a2d(%rip), %rsi     # 0x56b59
movb $0x0, %al
callq 0x2250
movq 0x30(%rsp), %rdi
callq 0x2180
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movl $0x18, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, (%rsp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x2110
movq (%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, (%rax)
movq 0x18(%rsp), %rax
movq $0x0, 0x8(%rax)
movq 0x28(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x18(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
addq $0x48, %rsp
retq
nopl (%rax)