// File: /workspace/github_cpp_makefile_star2_O1/BleuLlama[P]msf-tools/VoiceFile.cpp
// Function: VoiceFile::VoiceFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
VoiceFile::VoiceFile( std::string _path )
	: valid( false )
	, buffer( NULL )
	, vrDir( "." )
	, vrVoiceDir( "." )
	, vrMSFFile( "x" )
{
	if( DiskUtils::IsValidDir( _path )) {
		this->ConfigurePath( _path );
	} else {
		return;
	}


	/* load in the buffer */
	FILE * fp = NULL;

	size_t bufsize = 0;
	size_t readbytes = 0;

	/* attempt to open the file */
	fp = fopen( this->vrMSFFile.c_str(), "r" );

	if( !fp ) {
		std::cerr << "Unable to open file: " << vrMSFFile << std::endl;
		return;
	}

	/* read it in to a buffer */
	fseek( fp, 0, SEEK_END );
	bufsize = ftell( fp );
	fseek( fp, 0, SEEK_SET );
	//printf( "File is %ld bytes\n", bufsize );
	if( bufsize != 16384 ) {
		std::cerr << "File is the wrong size." << std::endl;
		std::cerr << "Bad things might happen" << std::endl;
		std::cerr << std::endl;
	}

	this->buffer = (unsigned char *) malloc( sizeof( unsigned char ) * bufsize );

	if( !this->buffer ) {
		std::cerr << "Mem Alloc error!" << std::endl;
		fclose( fp );
		return;
	}


	readbytes = fread( this->buffer, sizeof( char ), bufsize, fp );
	fclose( fp );

	if( readbytes == 0 ) {
		std::cerr << "Couldn't read!" << std::endl;
		return;
	}


	/* 1. validate its' the right file */
	if(   this->buffer[0] != 'M'
	   || this->buffer[1] != 'S'
	   || this->buffer[2] != 'G'
	   || this->buffer[3] != 'L' ) {
		std::cerr << "This is not a Message List file!" << std::endl;
		return;
	}


	valid = true;
	return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r13
movq %rdi, %r12
movb $0x0, (%rdi)
movq $0x0, 0x8(%rdi)
addq $0x10, %rdi
leaq 0x20(%r12), %rax
movq %rax, 0x10(%rsp)
movq %rax, 0x10(%r12)
leaq 0x2228(%rip), %rbx      # 0x501d
leaq 0x2222(%rip), %r15      # 0x501e
movq %rdi, 0x20(%rsp)
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2d2a
leaq 0x30(%r12), %r14
leaq 0x40(%r12), %rax
movq %rax, 0x8(%rsp)
movq %rax, 0x30(%r12)
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2d2a
movq %r14, 0x18(%rsp)
leaq 0x50(%r12), %r15
leaq 0x60(%r12), %r14
movq %r14, 0x50(%r12)
leaq 0x223b(%rip), %rsi      # 0x5084
leaq 0x2235(%rip), %rdx      # 0x5085
movq %r15, %rdi
callq 0x2d2a
leaq 0x58(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0x2c9a
leaq 0x48(%rsp), %rdi
callq 0x24c0
movl %eax, %ebx
movq 0x48(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2e99
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2110
testb %bl, %bl
je 0x3147
leaq 0x38(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x2c9a
leaq 0x28(%rsp), %rsi
movq %r12, %rdi
callq 0x31ee
movq 0x28(%rsp), %rdi
cmpq %rbx, %rdi
je 0x2ee3
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2110
movq (%r15), %rdi
leaq 0x2199(%rip), %rsi      # 0x5086
callq 0x2140
testq %rax, %rax
je 0x306a
movq %rax, %r13
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x2120
movq %r13, %rdi
callq 0x2030
movq %rax, %rbp
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2120
cmpq $0x4000, %rbp           # imm = 0x4000
je 0x2feb
movq 0x50b8(%rip), %rbx      # 0x7ff0
leaq 0x215f(%rip), %rsi      # 0x509e
movl $0x17, %edx
movq %rbx, %rdi
callq 0x2130
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x20f0
movsbl %al, %esi
movq 0x5086(%rip), %rdi      # 0x7ff0
callq 0x2040
movq %rax, %rdi
callq 0x20a0
movq 0x5072(%rip), %rbx      # 0x7ff0
leaq 0x2131(%rip), %rsi      # 0x50b6
movl $0x17, %edx
movq %rbx, %rdi
callq 0x2130
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x20f0
movsbl %al, %esi
movq 0x5040(%rip), %rbx      # 0x7ff0
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x20f0
movsbl %al, %esi
movq 0x5012(%rip), %rdi      # 0x7ff0
callq 0x2040
movq %rax, %rdi
callq 0x20a0
movq %rbp, %rdi
callq 0x2170
movq %rax, 0x8(%r12)
testq %rax, %rax
je 0x30b4
movl $0x1, %esi
movq %rax, %rdi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x2180
movq %rax, %rbx
movq %r13, %rdi
callq 0x2100
testq %rbx, %rbx
je 0x3104
movq 0x8(%r12), %rax
movl $0x20, %edx
leaq 0x20b5(%rip), %rsi      # 0x50ee
cmpb $0x4d, (%rax)
jne 0x3110
cmpb $0x53, 0x1(%rax)
jne 0x3110
cmpb $0x47, 0x2(%rax)
jne 0x3110
cmpb $0x4c, 0x3(%rax)
jne 0x3110
movb $0x1, (%r12)
jmp 0x3147
movq 0x4f7f(%rip), %rdi      # 0x7ff0
leaq 0x2010(%rip), %rsi      # 0x5088
movl $0x15, %edx
callq 0x2130
movq 0x50(%r12), %rsi
movq 0x58(%r12), %rdx
movq 0x4f5d(%rip), %rdi      # 0x7ff0
callq 0x2130
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x20f0
jmp 0x3134
movq 0x4f35(%rip), %rbx      # 0x7ff0
leaq 0x200c(%rip), %rsi      # 0x50ce
movl $0x10, %edx
movq %rbx, %rdi
callq 0x2130
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x20f0
movsbl %al, %esi
movq 0x4f03(%rip), %rdi      # 0x7ff0
callq 0x2040
movq %rax, %rdi
callq 0x20a0
movq %r13, %rdi
callq 0x2100
jmp 0x3147
movl $0xe, %edx
leaq 0x1fcf(%rip), %rsi      # 0x50df
movq 0x4ed9(%rip), %r12      # 0x7ff0
movq %r12, %rdi
callq 0x2130
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x20f0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20a0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r12
movq 0x28(%rsp), %rdi
cmpq %rbx, %rdi
je 0x3195
movq 0x38(%rsp), %rsi
jmp 0x317c
movq %rax, %r12
movq 0x48(%rsp), %rdi
cmpq %rbp, %rdi
je 0x3195
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2110
jmp 0x3195
movq %rax, %r12
jmp 0x31a8
movq %rax, %r12
jmp 0x31c7
jmp 0x3192
movq %rax, %r12
movq (%r15), %rdi
cmpq %r14, %rdi
je 0x31a8
movq (%r14), %rsi
incq %rsi
callq 0x2110
movq 0x18(%rsp), %rax
movq (%rax), %rdi
cmpq 0x8(%rsp), %rdi
je 0x31c7
movq 0x8(%rsp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x2110
movq 0x20(%rsp), %rax
movq (%rax), %rdi
cmpq 0x10(%rsp), %rdi
je 0x31e6
movq 0x10(%rsp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x2110
movq %r12, %rdi
callq 0x2230