// File: /workspace/github_cpp_makefile_star2_O3/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 0x76e4
leaq 0xd59e(%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 0x76e4
leaq 0xd4cb(%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 0xb3c4
leaq 0x5(%rsp), %rsi
movl $0x3, %edx
movq %r14, %rdi
callq 0x4350
cmpb $0x6c, 0x5(%rsp)
jne 0xb41a
cmpb $0x1b, 0x6(%rsp)
jne 0xb41a
cmpb $0x1, 0x7(%rsp)
jne 0xb470
leaq 0x458(%rbx), %rdi
movq 0x48(%rsp), %rsi
movl $0x8, %edx
callq 0x4270
leaq 0x4d8(%rbx), %rdi
callq 0x40a0
testb %al, %al
je 0xb4cb
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 0xb51a
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0xb3a1
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42d0
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0xb3b8
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42d0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x14c25(%rip), %rdi     # 0x1fff0
leaq 0xd17e(%rip), %rsi      # 0x18550
movl $0x1b, %edx
callq 0x42f0
movq 0x218(%rbx), %rsi
movq 0x220(%rbx), %rdx
movq 0x14bff(%rip), %rdi     # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0xd16c(%rip), %rsi      # 0x1856c
movl $0xa, %edx
movq %rax, %rdi
callq 0x42f0
movq %r14, %rdi
callq 0x4130
jmp 0xb567
movq 0x14bcf(%rip), %rdi     # 0x1fff0
leaq 0xd42e(%rip), %rsi      # 0x18856
movl $0x13, %edx
callq 0x42f0
movq 0x218(%rbx), %rsi
movq 0x220(%rbx), %rdx
movq 0x14ba9(%rip), %rdi     # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0xd414(%rip), %rsi      # 0x1886a
movl $0x16, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
jmp 0xb567
movq 0x14b79(%rip), %rdi     # 0x1fff0
leaq 0xd3d8(%rip), %rsi      # 0x18856
movl $0x13, %edx
callq 0x42f0
movq 0x218(%rbx), %rsi
movq 0x220(%rbx), %rdx
movq 0x14b53(%rip), %rdi     # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0xd3d5(%rip), %rsi      # 0x18881
movl $0x37, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
movl $0x3, %edi
callq 0x4320
movq 0x14b1e(%rip), %rdi     # 0x1fff0
leaq 0xd3e0(%rip), %rsi      # 0x188b9
movl $0x20, %edx
callq 0x42f0
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0x14afc(%rip), %rdi     # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0xd069(%rip), %rsi      # 0x1856c
movl $0xa, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
jmp 0xb567
movq 0x14acf(%rip), %rdi     # 0x1fff0
leaq 0xd272(%rip), %rsi      # 0x1879a
movl $0x20, %edx
callq 0x42f0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x14aad(%rip), %rdi     # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0xd01a(%rip), %rsi      # 0x1856c
movl $0xa, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
movl $0x2, %edi
callq 0x4320
jmp 0xb7cd
jmp 0xb578
movq %rax, %r14
jmp 0xb7e7
movq %rax, %r14
cmpl $0x1, %edx
jne 0xb7d0
movq %r14, %rdi
callq 0x4110
movq %rax, %rbx
movq 0x14a52(%rip), %rdi     # 0x1fff0
leaq 0xd216(%rip), %rsi      # 0x187bb
movl $0x1d, %edx
callq 0x42f0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x14a30(%rip), %rdi     # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0xd42e(%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 0xb637
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0xb637
jmp 0xb634
movq %rax, %r14
callq 0x4480
jmp 0xb7d0
movq %rax, %r14
cmpl $0x1, %edx
jne 0xb7d0
movq %r14, %rdi
callq 0x4110
movq %rax, %rbx
movq 0x14991(%rip), %rdi     # 0x1fff0
leaq 0xd274(%rip), %rsi      # 0x188da
movl $0x1d, %edx
callq 0x42f0
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0x1496f(%rip), %rdi     # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0xd36d(%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 0xb6f8
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0xb6f8
jmp 0xb6f5
movq %rax, %r14
callq 0x4480
jmp 0xb7d0
movq %rax, %r14
cmpl $0x1, %edx
jne 0xb7d0
movq %r14, %rdi
callq 0x4110
movq %rax, %r14
movq 0x148d0(%rip), %rdi     # 0x1fff0
leaq 0xd112(%rip), %rsi      # 0x18839
movl $0x1c, %edx
callq 0x42f0
movq 0x218(%rbx), %rsi
movq 0x220(%rbx), %rdx
movq 0x148aa(%rip), %rdi     # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0xd2a8(%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 0xb7be
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0xb7be
jmp 0xb7bb
movq %rax, %r14
callq 0x4480
jmp 0xb7d0
movq %rax, %rdi
callq 0x76d8
movq %rax, %r14
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0xb7e7
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42d0
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0xb7fe
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %r14, %rdi
callq 0x44e0