// File: /workspace/github_cpp_makefile_star2_O2/tonymugen[P]sampleSNPs/varfiles.cpp
// Function: sampFiles::BedFileI::open()
void BedFileI::open(){
	string bimName = _fileStub + ".bim";
	string famName = _fileStub + ".fam";


	try {
		_varFile.open(_fileName.c_str(), ios::in | ios::binary);
		if (!_varFile.is_open()) {
			cerr << "ERROR: failed to open file " << _fileName << " for input" << endl;
			exit(2);
		}

	} catch (system_error &error) {
		cerr << "ERROR: cannot open BED file " << _fileName << " for input: " << error.code().message() << flush;
		perror(" ");
		exit(1);

	}
	// check the magic bytes and SNP-major status
	char magic[3];
	_varFile.read(magic, 3);
	if ( (magic[0] != static_cast<char>(0x6C)) || (magic[1] != static_cast<char>(0x1B)) ) {
		cerr << "ERROR: binary file " << _fileName << " not recognized as BED" << endl;
		exit(2);
	} else if (magic[2] != static_cast<char>(0x01)){
		cerr << "ERROR: binary file " << _fileName << " not SNP-major. Run a newer version of plink to fix it." << endl;
		exit(3);
	}

	try {
		_bimFile.open(bimName.c_str(), ios::in);
		if (!_bimFile.is_open()) {
			cerr << "ERROR: failed to open .bim file " << bimName << " for input" << endl;
			exit(2);
		}

	} catch (system_error &error) {
		cerr << "ERROR: cannot open .bim file " << bimName << " for input: " << error.code().message() << flush;
		perror(" ");
		exit(1);

	}

	try {
		_famFile.open(famName.c_str(), ios::in);
		if (!_famFile.is_open()) {
			cerr << "ERROR: failed to open .fam file " << famName << " for input" << endl;
			exit(2);
		}

	} catch (system_error &error) {
		cerr << "ERROR: cannot open .fam file " << famName << " for input: " << error.code().message() << flush;
		perror(" ");
		exit(1);

	}

}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x70, %rsp
movq %rdi, %r14
leaq 0x668(%rdi), %rbx
leaq 0xb0dc(%rip), %rdx      # 0x14834
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x5e08
leaq 0xb029(%rip), %rdx      # 0x14795
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x5e08
leaq 0x8(%r14), %r15
leaq 0x218(%r14), %rbx
movq 0x218(%r14), %rsi
pushq $0xc
popq %rdx
movq %r15, %rdi
callq 0x4280
leaq 0x88(%r14), %rdi
callq 0x40b0
testb %al, %al
je 0x984c
leaq 0xd(%rsp), %rsi
pushq $0x3
popq %rdx
movq %r15, %rdi
callq 0x4340
cmpb $0x6c, 0xd(%rsp)
jne 0x9886
cmpb $0x1b, 0xe(%rsp)
jne 0x9886
cmpb $0x1, 0xf(%rsp)
jne 0x98c0
leaq 0x458(%r14), %rdi
movq 0x50(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x4280
leaq 0x4d8(%r14), %rdi
callq 0x40b0
testb %al, %al
je 0x98f9
leaq 0x248(%r14), %rdi
movq 0x30(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x4280
addq $0x2c8, %r14            # imm = 0x2C8
movq %r14, %rdi
callq 0x40b0
testb %al, %al
je 0x9932
leaq 0x30(%rsp), %rdi
callq 0x4558
leaq 0x50(%rsp), %rdi
callq 0x4558
addq $0x70, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq 0x1279d(%rip), %rdi     # 0x1bff0
leaq 0xacf6(%rip), %rsi      # 0x14550
callq 0x42a0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4270
leaq 0xacfb(%rip), %rsi      # 0x1456c
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0x9969
movq 0x12763(%rip), %rdi     # 0x1bff0
leaq 0xafc2(%rip), %rsi      # 0x14856
callq 0x42a0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4270
leaq 0xafbf(%rip), %rsi      # 0x1486a
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0x9969
movq 0x12729(%rip), %rdi     # 0x1bff0
leaq 0xaf88(%rip), %rsi      # 0x14856
callq 0x42a0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4270
leaq 0xaf9c(%rip), %rsi      # 0x14881
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
pushq $0x3
jmp 0x996b
movq 0x126f0(%rip), %rdi     # 0x1bff0
leaq 0xafb2(%rip), %rsi      # 0x148b9
callq 0x42a0
leaq 0x50(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0xac4c(%rip), %rsi      # 0x1456c
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0x9969
movq 0x126b7(%rip), %rdi     # 0x1bff0
leaq 0xae5a(%rip), %rsi      # 0x1479a
callq 0x42a0
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0xac13(%rip), %rsi      # 0x1456c
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
pushq $0x2
popq %rdi
callq 0x4310
movq %rax, %r14
jmp 0x9b5b
movq %rax, %r14
cmpl $0x1, %edx
jne 0x9b51
movq %r14, %rdi
callq 0x4110
movq %rax, %rbx
movq 0x12659(%rip), %rdi     # 0x1bff0
leaq 0xae1d(%rip), %rsi      # 0x147bb
callq 0x42a0
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0xb046(%rip), %rsi      # 0x149fd
movq %rax, %rdi
callq 0x42a0
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x10(%rsp), %rdi
callq *0x20(%rax)
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
jmp 0x9b0e
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x4558
jmp 0x9a02
jmp 0x99ff
movq %rax, %r14
callq 0x4470
jmp 0x9b51
movq %rax, %r14
cmpl $0x1, %edx
jne 0x9b51
movq %r14, %rdi
callq 0x4110
movq %rax, %rbx
movq 0x125c6(%rip), %rdi     # 0x1bff0
leaq 0xaea9(%rip), %rsi      # 0x148da
callq 0x42a0
leaq 0x50(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0xafb3(%rip), %rsi      # 0x149fd
movq %rax, %rdi
callq 0x42a0
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x10(%rsp), %rdi
callq *0x20(%rax)
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
jmp 0x9b0e
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x4558
jmp 0x9a95
jmp 0x9a92
movq %rax, %r14
callq 0x4470
jmp 0x9b51
movq %rax, %r14
cmpl $0x1, %edx
jne 0x9b51
movq %r14, %rdi
callq 0x4110
movq %rax, %r14
movq 0x12533(%rip), %rdi     # 0x1bff0
leaq 0xad75(%rip), %rsi      # 0x14839
callq 0x42a0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4270
leaq 0xaf22(%rip), %rsi      # 0x149fd
movq %rax, %rdi
callq 0x42a0
movq %rax, %rbx
movq 0x18(%r14), %rsi
movl 0x10(%r14), %edx
movq (%rsi), %rax
leaq 0x10(%rsp), %rdi
callq *0x20(%rax)
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
leaq 0x10(%rsp), %rdi
callq 0x4558
leaq 0xacf3(%rip), %rdi      # 0x14812
callq 0x4250
pushq $0x1
jmp 0x996b
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x4558
jmp 0x9b3f
jmp 0x9b3c
movq %rax, %r14
callq 0x4470
jmp 0x9b51
movq %rax, %rdi
callq 0x6194
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x4558
leaq 0x50(%rsp), %rdi
callq 0x4558
movq %r14, %rdi
callq 0x44d0
nop