// File: /workspace/github_cpp_makefile_star2_O3/tonymugen[P]sampleSNPs/varfiles.cpp
// Function: sampFiles::BedFileO::open()
void BedFileO::open(){
	string bimName = _fileStub + ".bim";
	string famName = _fileStub + ".fam";
    if (_varFile.is_open()) {
        _varFile.close();
    }
	try {
		_varFile.open(_fileName.c_str(), ios::out | ios::binary);
		if (!_varFile.is_open()) {
			cerr << "ERROR: failed to open .bed file " << _fileName << " for output" << endl;
			exit(2);
		}

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

	}
	// write the magic bytes and the SNP-major status byte
	char magic[3] = {static_cast<char>(0x6C), static_cast<char>(0x1B), static_cast<char>(0x01)};
	_varFile.write(magic, 3);

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

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

	}

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

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

	}

}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x70, %rsp
movq %rdi, %r14
leaq 0x58(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x668(%rdi), %rsi
movq 0x670(%rdi), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
callq 0x76e4
leaq 0x8151(%rip), %rsi      # 0x18834
movq %rbx, %rdi
callq 0x4530
leaq 0x38(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x668(%r14), %rsi
movq 0x670(%r14), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x76e4
leaq 0x807f(%rip), %rsi      # 0x18795
leaq 0x28(%rsp), %rdi
callq 0x4530
leaq 0x8(%r14), %r15
leaq 0x88(%r14), %rbx
movq %rbx, %rdi
callq 0x40a0
testb %al, %al
je 0x1073f
movq %r15, %rdi
callq 0x4060
movq 0x218(%r14), %rsi
movq %r15, %rdi
movl $0x14, %edx
callq 0x4270
movq %rbx, %rdi
callq 0x40a0
testb %al, %al
je 0x10812
leaq 0x6c(%rsp), %rsi
movb $0x1, 0x2(%rsi)
movw $0x1b6c, (%rsi)         # imm = 0x1B6C
leaq 0x18(%r14), %rdi
movl $0x3, %edx
callq 0x4390
leaq 0x458(%r14), %rdi
movq 0x48(%rsp), %rsi
movl $0x10, %edx
callq 0x4270
leaq 0x4d8(%r14), %rdi
callq 0x40a0
testb %al, %al
je 0x10868
leaq 0x248(%r14), %rdi
movq 0x28(%rsp), %rsi
movl $0x10, %edx
callq 0x4270
addq $0x2c8, %r14            # imm = 0x2C8
movq %r14, %rdi
callq 0x40a0
testb %al, %al
je 0x108b7
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x107ed
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42d0
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x10804
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42d0
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0xf7d7(%rip), %rdi      # 0x1fff0
leaq 0x815a(%rip), %rsi      # 0x1897a
movl $0x20, %edx
callq 0x42f0
movq 0x218(%r14), %rsi
movq 0x220(%r14), %rdx
movq 0xf7b1(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0x7e94(%rip), %rsi      # 0x186e2
movl $0xb, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
jmp 0x10904
movq 0xf781(%rip), %rdi      # 0x1fff0
leaq 0x8043(%rip), %rsi      # 0x188b9
movl $0x20, %edx
callq 0x42f0
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0xf75f(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0x7e42(%rip), %rsi      # 0x186e2
movl $0xb, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
jmp 0x10904
movq 0xf732(%rip), %rdi      # 0x1fff0
leaq 0x7ed5(%rip), %rsi      # 0x1879a
movl $0x20, %edx
callq 0x42f0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0xf710(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0x7df3(%rip), %rsi      # 0x186e2
movl $0xb, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
movl $0x2, %edi
callq 0x4320
jmp 0x10912
jmp 0x10912
movq %rax, %rbx
jmp 0x10b66
jmp 0x1091c
movq %rax, %rbx
jmp 0x10b7d
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x10b66
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xf6ae(%rip), %rdi      # 0x1fff0
leaq 0x7e72(%rip), %rsi      # 0x187bb
movl $0x1d, %edx
callq 0x42f0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0xf68c(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0x7d7b(%rip), %rsi      # 0x186ee
movl $0xd, %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 0x487d
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x109db
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0x109db
jmp 0x109d8
movq %rax, %rbx
callq 0x4480
jmp 0x10b66
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x10b66
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xf5ed(%rip), %rdi      # 0x1fff0
leaq 0x7ed0(%rip), %rsi      # 0x188da
movl $0x1d, %edx
callq 0x42f0
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0xf5cb(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0x7cba(%rip), %rsi      # 0x186ee
movl $0xd, %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 0x4863
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x10a9c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0x10a9c
jmp 0x10a99
movq %rax, %rbx
callq 0x4480
jmp 0x10b66
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x10b66
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xf52c(%rip), %rdi      # 0x1fff0
leaq 0x7d6e(%rip), %rsi      # 0x18839
movl $0x1c, %edx
callq 0x42f0
movq 0x218(%r14), %rsi
movq 0x220(%r14), %rdx
movq 0xf506(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0x7bf5(%rip), %rsi      # 0x186ee
movl $0xd, %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 0x4849
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x10b61
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0x10b61
jmp 0x10b5e
movq %rax, %rbx
callq 0x4480
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x10b7d
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42d0
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x10b94
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %rbx, %rdi
callq 0x44e0
movq %rax, %rdi
callq 0x76d8