// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
leaq 0x668(%rdi), %r14
leaq 0x72a4(%rip), %rdx      # 0x14834
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x5e08
leaq 0x71f1(%rip), %rdx      # 0x14795
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x5e08
leaq 0x8(%rbx), %r12
leaq 0x88(%rbx), %r15
movq %r15, %rdi
callq 0x40b0
testb %al, %al
je 0xd5d0
movq %r12, %rdi
callq 0x4050
leaq 0x218(%rbx), %r14
movq 0x218(%rbx), %rsi
pushq $0x14
popq %rdx
movq %r12, %rdi
callq 0x4280
movq %r15, %rdi
callq 0x40b0
testb %al, %al
je 0xd686
leaq 0x24(%rsp), %rsi
movb $0x1, 0x2(%rsi)
movw $0x1b6c, (%rsi)         # imm = 0x1B6C
leaq 0x18(%rbx), %rdi
pushq $0x3
popq %rdx
callq 0x4390
leaq 0x458(%rbx), %rdi
movq 0x48(%rsp), %rsi
pushq $0x10
popq %rdx
callq 0x4280
leaq 0x4d8(%rbx), %rdi
callq 0x40b0
testb %al, %al
je 0xd6bd
leaq 0x248(%rbx), %rdi
movq 0x28(%rsp), %rsi
pushq $0x10
popq %rdx
callq 0x4280
addq $0x2c8, %rbx            # imm = 0x2C8
movq %rbx, %rdi
callq 0x40b0
testb %al, %al
je 0xd6f6
leaq 0x28(%rsp), %rdi
callq 0x4558
leaq 0x48(%rsp), %rdi
callq 0x4558
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0xe963(%rip), %rdi      # 0x1bff0
leaq 0x72e6(%rip), %rsi      # 0x1497a
callq 0x42a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x4270
leaq 0x7037(%rip), %rsi      # 0x146e2
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0xd72d
movq 0xe92c(%rip), %rdi      # 0x1bff0
leaq 0x71ee(%rip), %rsi      # 0x148b9
callq 0x42a0
leaq 0x48(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0x6ffe(%rip), %rsi      # 0x146e2
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
jmp 0xd72d
movq 0xe8f3(%rip), %rdi      # 0x1bff0
leaq 0x7096(%rip), %rsi      # 0x1479a
callq 0x42a0
leaq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0x6fc5(%rip), %rsi      # 0x146e2
movq %rax, %rdi
callq 0x42a0
movq %rax, %rdi
callq 0x4140
pushq $0x2
popq %rdi
callq 0x4310
jmp 0xd737
movq %rax, %rbx
jmp 0xd8fd
movq %rax, %rbx
jmp 0xd907
movq %rax, %rbx
cmpl $0x1, %edx
jne 0xd8fd
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xe88b(%rip), %rdi      # 0x1bff0
leaq 0x704f(%rip), %rsi      # 0x147bb
callq 0x42a0
leaq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0x6f69(%rip), %rsi      # 0x146ee
movq %rax, %rdi
callq 0x42a0
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
movq %rsp, %rdi
callq *0x20(%rax)
movq %rsp, %rsi
movq %r14, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
jmp 0xd8cb
movq %rax, %rbx
movq %rsp, %rdi
callq 0x4558
jmp 0xd7ca
jmp 0xd7c7
movq %rax, %rbx
callq 0x4470
jmp 0xd8fd
movq %rax, %rbx
cmpl $0x1, %edx
jne 0xd8fd
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xe7fe(%rip), %rdi      # 0x1bff0
leaq 0x70e1(%rip), %rsi      # 0x148da
callq 0x42a0
leaq 0x48(%rsp), %rsi
movq %rax, %rdi
callq 0x4270
leaq 0x6edc(%rip), %rsi      # 0x146ee
movq %rax, %rdi
callq 0x42a0
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
movq %rsp, %rdi
callq *0x20(%rax)
movq %rsp, %rsi
movq %r14, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
jmp 0xd8cb
movq %rax, %rbx
movq %rsp, %rdi
callq 0x4558
jmp 0xd857
jmp 0xd854
movq %rax, %rbx
callq 0x4470
jmp 0xd8fd
movq %rax, %rbx
cmpl $0x1, %edx
jne 0xd8fd
movq %rbx, %rdi
callq 0x4110
movq %rax, %rbx
movq 0xe771(%rip), %rdi      # 0x1bff0
leaq 0x6fb3(%rip), %rsi      # 0x14839
callq 0x42a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x4270
leaq 0x6e51(%rip), %rsi      # 0x146ee
movq %rax, %rdi
callq 0x42a0
movq %rax, %r14
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movq (%rsi), %rax
movq %rsp, %rdi
callq *0x20(%rax)
movq %rsp, %rsi
movq %r14, %rdi
callq 0x4270
movq %rax, %rdi
callq 0x41c0
movq %rsp, %rdi
callq 0x4558
leaq 0x6f38(%rip), %rdi      # 0x14812
callq 0x4250
pushq $0x1
jmp 0xd72f
movq %rax, %rbx
movq %rsp, %rdi
callq 0x4558
jmp 0xd8f8
jmp 0xd8f5
movq %rax, %rbx
callq 0x4470
leaq 0x28(%rsp), %rdi
callq 0x4558
leaq 0x48(%rsp), %rdi
callq 0x4558
movq %rbx, %rdi
callq 0x44d0
movq %rax, %rdi
callq 0x6194
nop