// File: /workspace/github_cpp_makefile_star2_O1/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 0x7720
leaq 0x7fbf(%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 0x7720
leaq 0x7eed(%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 0x108d1
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 0x109a4
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 0x109fa
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 0x10a49
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x1097f
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42d0
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x10996
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42d0
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0xf645(%rip), %rdi      # 0x1fff0
leaq 0x7fc8(%rip), %rsi      # 0x1897a
movl $0x20, %edx
callq 0x42f0
movq 0x218(%r14), %rsi
movq 0x220(%r14), %rdx
movq 0xf61f(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0x7d02(%rip), %rsi      # 0x186e2
movl $0xb, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
jmp 0x10a96
movq 0xf5ef(%rip), %rdi      # 0x1fff0
leaq 0x7eb1(%rip), %rsi      # 0x188b9
movl $0x20, %edx
callq 0x42f0
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0xf5cd(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0x7cb0(%rip), %rsi      # 0x186e2
movl $0xb, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
jmp 0x10a96
movq 0xf5a0(%rip), %rdi      # 0x1fff0
leaq 0x7d43(%rip), %rsi      # 0x1879a
movl $0x20, %edx
callq 0x42f0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0xf57e(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %rbx
leaq 0x7c61(%rip), %rsi      # 0x186e2
movl $0xb, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4130
movl $0x2, %edi
callq 0x4320
jmp 0x10aa4
jmp 0x10aa4
movq %rax, %rbx
jmp 0x10cf8
jmp 0x10aae
movq %rax, %rbx
jmp 0x10d0f
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x10cf8
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xf51c(%rip), %rdi      # 0x1fff0
leaq 0x7ce0(%rip), %rsi      # 0x187bb
movl $0x1d, %edx
callq 0x42f0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0xf4fa(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0x7be9(%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 0x10b6d
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0x10b6d
jmp 0x10b6a
movq %rax, %rbx
callq 0x4480
jmp 0x10cf8
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x10cf8
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xf45b(%rip), %rdi      # 0x1fff0
leaq 0x7d3e(%rip), %rsi      # 0x188da
movl $0x1d, %edx
callq 0x42f0
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0xf439(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0x7b28(%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 0x10c2e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0x10c2e
jmp 0x10c2b
movq %rax, %rbx
callq 0x4480
jmp 0x10cf8
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x10cf8
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xf39a(%rip), %rdi      # 0x1fff0
leaq 0x7bdc(%rip), %rsi      # 0x18839
movl $0x1c, %edx
callq 0x42f0
movq 0x218(%r14), %rsi
movq 0x220(%r14), %rdx
movq 0xf374(%rip), %rdi      # 0x1fff0
callq 0x42f0
movq %rax, %r14
leaq 0x7a63(%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 0x10cf3
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0x10cf3
jmp 0x10cf0
movq %rax, %rbx
callq 0x4480
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x10d0f
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42d0
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x10d26
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %rbx, %rdi
callq 0x44e0
movq %rax, %rdi
callq 0x7714