// File: /workspace/github_cpp_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
leaq 0x58(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x668(%rdi), %rsi
movq 0x670(%rdi), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %r14
movq %r14, %rdi
callq 0x7720
leaq 0xd550(%rip), %rsi      # 0x18834
movq %r14, %rdi
callq 0x4530
leaq 0x38(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x668(%rbx), %rsi
movq 0x670(%rbx), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x7720
leaq 0xd47d(%rip), %rsi      # 0x18795
leaq 0x28(%rsp), %rdi
callq 0x4530
leaq 0x8(%rbx), %r14
movq 0x218(%rbx), %rsi
movq %r14, %rdi
movl $0xc, %edx
callq 0x4270
leaq 0x88(%rbx), %rdi
callq 0x40a0
testb %al, %al
je 0xb412
leaq 0x5(%rsp), %rsi
movl $0x3, %edx
movq %r14, %rdi
callq 0x4350
cmpb $0x6c, 0x5(%rsp)
jne 0xb468
cmpb $0x1b, 0x6(%rsp)
jne 0xb468
cmpb $0x1, 0x7(%rsp)
jne 0xb4be
leaq 0x458(%rbx), %rdi
movq 0x48(%rsp), %rsi
movl $0x8, %edx
callq 0x4270
leaq 0x4d8(%rbx), %rdi
callq 0x40a0
testb %al, %al
je 0xb519
leaq 0x248(%rbx), %rdi
movq 0x28(%rsp), %rsi
movl $0x8, %edx
callq 0x4270
addq $0x2c8, %rbx            # imm = 0x2C8
movq %rbx, %rdi
callq 0x40a0
testb %al, %al
je 0xb568
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0xb3ef
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42d0
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0xb406
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42d0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x14bd7(%rip), %rdi     # 0x1fff0
leaq 0xd130(%rip), %rsi      # 0x18550
movl $0x1b, %edx
callq 0x42f0
movq 0x218(%rbx), %rsi
movq 0x220(%rbx), %rdx
movq 0x14bb1(%rip), %rdi     # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0xd11e(%rip), %rsi      # 0x1856c
movl $0xa, %edx
movq %rax, %rdi
callq 0x42f0
movq %r14, %rdi
callq 0x4130
jmp 0xb5b5
movq 0x14b81(%rip), %rdi     # 0x1fff0
leaq 0xd3e0(%rip), %rsi      # 0x18856
movl $0x13, %edx
callq 0x42f0
movq 0x218(%rbx), %rsi
movq 0x220(%rbx), %rdx
movq 0x14b5b(%rip), %rdi     # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0xd3c6(%rip), %rsi      # 0x1886a
movl $0x16, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
jmp 0xb5b5
movq 0x14b2b(%rip), %rdi     # 0x1fff0
leaq 0xd38a(%rip), %rsi      # 0x18856
movl $0x13, %edx
callq 0x42f0
movq 0x218(%rbx), %rsi
movq 0x220(%rbx), %rdx
movq 0x14b05(%rip), %rdi     # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0xd387(%rip), %rsi      # 0x18881
movl $0x37, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
movl $0x3, %edi
callq 0x4320
movq 0x14ad0(%rip), %rdi     # 0x1fff0
leaq 0xd392(%rip), %rsi      # 0x188b9
movl $0x20, %edx
callq 0x42f0
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0x14aae(%rip), %rdi     # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0xd01b(%rip), %rsi      # 0x1856c
movl $0xa, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
jmp 0xb5b5
movq 0x14a81(%rip), %rdi     # 0x1fff0
leaq 0xd224(%rip), %rsi      # 0x1879a
movl $0x20, %edx
callq 0x42f0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x14a5f(%rip), %rdi     # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0xcfcc(%rip), %rsi      # 0x1856c
movl $0xa, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
movl $0x2, %edi
callq 0x4320
jmp 0xb81b
jmp 0xb5c6
movq %rax, %r14
jmp 0xb835
movq %rax, %r14
cmpl $0x1, %edx
jne 0xb81e
movq %r14, %rdi
callq 0x4110
movq %rax, %rbx
movq 0x14a04(%rip), %rdi     # 0x1fff0
leaq 0xd1c8(%rip), %rsi      # 0x187bb
movl $0x1d, %edx
callq 0x42f0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x149e2(%rip), %rdi     # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0xd3e0(%rip), %rsi      # 0x189fd
movl $0xc, %edx
movq %rax, %rdi
callq 0x42f0
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x8(%rsp), %rdi
callq *0x20(%rax)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %r14, %rdi
callq 0x42f0
movq %rax, %rdi
callq 0x41b0
leaq 0x8(%rsp), %rdi
callq 0x46a9
movq %rax, %r14
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb685
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0xb685
jmp 0xb682
movq %rax, %r14
callq 0x4480
jmp 0xb81e
movq %rax, %r14
cmpl $0x1, %edx
jne 0xb81e
movq %r14, %rdi
callq 0x4110
movq %rax, %rbx
movq 0x14943(%rip), %rdi     # 0x1fff0
leaq 0xd226(%rip), %rsi      # 0x188da
movl $0x1d, %edx
callq 0x42f0
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0x14921(%rip), %rdi     # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0xd31f(%rip), %rsi      # 0x189fd
movl $0xc, %edx
movq %rax, %rdi
callq 0x42f0
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
leaq 0x8(%rsp), %rdi
callq *0x20(%rax)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %r14, %rdi
callq 0x42f0
movq %rax, %rdi
callq 0x41b0
leaq 0x8(%rsp), %rdi
callq 0x468f
movq %rax, %r14
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb746
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0xb746
jmp 0xb743
movq %rax, %r14
callq 0x4480
jmp 0xb81e
movq %rax, %r14
cmpl $0x1, %edx
jne 0xb81e
movq %r14, %rdi
callq 0x4110
movq %rax, %r14
movq 0x14882(%rip), %rdi     # 0x1fff0
leaq 0xd0c4(%rip), %rsi      # 0x18839
movl $0x1c, %edx
callq 0x42f0
movq 0x218(%rbx), %rsi
movq 0x220(%rbx), %rdx
movq 0x1485c(%rip), %rdi     # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0xd25a(%rip), %rsi      # 0x189fd
movl $0xc, %edx
movq %rax, %rdi
callq 0x42f0
movq 0x18(%r14), %rsi
movl 0x10(%r14), %edx
movq (%rsi), %rax
leaq 0x8(%rsp), %rdi
callq *0x20(%rax)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x42f0
movq %rax, %rdi
callq 0x41b0
leaq 0x8(%rsp), %rdi
callq 0x4675
movq %rax, %r14
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb80c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0xb80c
jmp 0xb809
movq %rax, %r14
callq 0x4480
jmp 0xb81e
movq %rax, %rdi
callq 0x7714
movq %rax, %r14
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0xb835
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42d0
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0xb84c
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %r14, %rdi
callq 0x44e0