// File: 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 %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
movq %rsi, -0xe8(%rbp)
addq $0x668, %rsi            # imm = 0x668
movq %rsi, -0xe0(%rbp)
leaq 0xd1fd(%rip), %rdx      # 0x2381c
leaq -0x28(%rbp), %rdi
callq 0x7920
movq -0xe0(%rbp), %rsi
leaq 0xd147(%rip), %rdx      # 0x2377d
leaq -0x48(%rbp), %rdi
callq 0x7920
jmp 0x16641
movq -0xe8(%rbp), %rdi
addq $0x8, %rdi
callq 0x45e0
movb %al, -0xe9(%rbp)
jmp 0x16659
movb -0xe9(%rbp), %al
testb $0x1, %al
jne 0x16665
jmp 0x1669b
movq -0xe8(%rbp), %rdi
addq $0x8, %rdi
callq 0x4060
jmp 0x16677
jmp 0x1669b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x16ce3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x16cda
movq -0xe8(%rbp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0x100(%rbp)
addq $0x218, %rdi            # imm = 0x218
callq 0x4140
movq %rax, -0xf8(%rbp)
movl $0x10, %edi
movl $0x4, %esi
callq 0x1ee70
movl %eax, -0xf0(%rbp)
jmp 0x166da
movl -0xf0(%rbp), %edx
movq -0xf8(%rbp), %rsi
movq -0x100(%rbp), %rdi
callq 0x42f0
jmp 0x166f5
movq -0xe8(%rbp), %rdi
addq $0x8, %rdi
callq 0x45e0
movb %al, -0x101(%rbp)
jmp 0x1670d
movb -0x101(%rbp), %al
testb $0x1, %al
jne 0x16881
jmp 0x1671d
movq 0x158cc(%rip), %rdi     # 0x2bff0
leaq 0xd237(%rip), %rsi      # 0x23962
callq 0x4310
movq %rax, -0x110(%rbp)
jmp 0x16739
movq -0x110(%rbp), %rdi
movq -0xe8(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0x118(%rbp)
jmp 0x1675c
movq -0x118(%rbp), %rdi
leaq 0xcf60(%rip), %rsi      # 0x236ca
callq 0x4310
movq %rax, -0x120(%rbp)
jmp 0x16778
movq -0x120(%rbp), %rdi
movq 0x1582a(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0x1678d
movl $0x2, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x16cda
movq -0x50(%rbp), %rdi
callq 0x4130
movq %rax, -0x60(%rbp)
movq 0x15829(%rip), %rdi     # 0x2bff0
leaq 0xd053(%rip), %rsi      # 0x23821
callq 0x4310
movq %rax, -0x128(%rbp)
jmp 0x167dc
movq -0x128(%rbp), %rdi
movq -0xe8(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0x130(%rbp)
jmp 0x167ff
movq -0x130(%rbp), %rdi
leaq 0xcec9(%rip), %rsi      # 0x236d6
callq 0x4310
movq %rax, -0x138(%rbp)
jmp 0x1681b
movq -0x60(%rbp), %rdi
callq 0x1ee90
movq %rax, %rsi
leaq -0x80(%rbp), %rdi
callq 0x1eeb0
jmp 0x16832
movq -0x138(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x42e0
movq %rax, -0x140(%rbp)
jmp 0x1684b
movq -0x140(%rbp), %rdi
movq 0x1576f(%rip), %rsi     # 0x2bfc8
callq 0x4350
jmp 0x16860
leaq -0x80(%rbp), %rdi
callq 0x46d8
leaq 0xcf8a(%rip), %rdi      # 0x237fa
callq 0x42a0
jmp 0x16877
movl $0x1, %edi
callq 0x4400
jmp 0x168b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x168a6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x46d8
callq 0x4580
jmp 0x168ad
jmp 0x16cda
movq -0xe8(%rbp), %rdi
movb $0x1, -0x82(%rbp)
movw $0x1b6c, -0x84(%rbp)    # imm = 0x1B6C
addq $0x18, %rdi
leaq -0x84(%rbp), %rsi
movl $0x3, %edx
callq 0x44a0
jmp 0x168e0
movq -0xe8(%rbp), %rax
addq $0x458, %rax            # imm = 0x458
movq %rax, -0x148(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x4140
movq -0x148(%rbp), %rdi
movq %rax, %rsi
movl $0x10, %edx
callq 0x42f0
jmp 0x16913
movq -0xe8(%rbp), %rdi
addq $0x458, %rdi            # imm = 0x458
callq 0x45e0
movb %al, -0x149(%rbp)
jmp 0x1692e
movb -0x149(%rbp), %al
testb $0x1, %al
jne 0x16a9d
jmp 0x1693e
movq 0x156ab(%rip), %rdi     # 0x2bff0
leaq 0xcf55(%rip), %rsi      # 0x238a1
callq 0x4310
movq %rax, -0x158(%rbp)
jmp 0x1695a
movq -0x158(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x42e0
movq %rax, -0x160(%rbp)
jmp 0x16973
movq -0x160(%rbp), %rdi
leaq 0xcd49(%rip), %rsi      # 0x236ca
callq 0x4310
movq %rax, -0x168(%rbp)
jmp 0x1698f
movq -0x168(%rbp), %rdi
movq 0x15613(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0x169a4
movl $0x2, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x16cda
movq -0x50(%rbp), %rdi
callq 0x4130
movq %rax, -0x90(%rbp)
movq 0x1560f(%rip), %rdi     # 0x2bff0
leaq 0xceda(%rip), %rsi      # 0x238c2
callq 0x4310
movq %rax, -0x170(%rbp)
jmp 0x169f6
movq -0x170(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x42e0
movq %rax, -0x178(%rbp)
jmp 0x16a0f
movq -0x178(%rbp), %rdi
leaq 0xccb9(%rip), %rsi      # 0x236d6
callq 0x4310
movq %rax, -0x180(%rbp)
jmp 0x16a2b
movq -0x90(%rbp), %rdi
callq 0x1ee90
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x1eeb0
jmp 0x16a48
movq -0x180(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x42e0
movq %rax, -0x188(%rbp)
jmp 0x16a64
movq -0x188(%rbp), %rdi
movq 0x15556(%rip), %rsi     # 0x2bfc8
callq 0x4350
jmp 0x16a79
leaq -0xb0(%rbp), %rdi
callq 0x46d8
leaq 0xcd6e(%rip), %rdi      # 0x237fa
callq 0x42a0
jmp 0x16a93
movl $0x1, %edi
callq 0x4400
jmp 0x16ad1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x16ac5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x46d8
callq 0x4580
jmp 0x16acc
jmp 0x16cda
movq -0xe8(%rbp), %rax
addq $0x248, %rax            # imm = 0x248
movq %rax, -0x190(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4140
movq -0x190(%rbp), %rdi
movq %rax, %rsi
movl $0x10, %edx
callq 0x42f0
jmp 0x16b04
movq -0xe8(%rbp), %rdi
addq $0x248, %rdi            # imm = 0x248
callq 0x45e0
movb %al, -0x191(%rbp)
jmp 0x16b1f
movb -0x191(%rbp), %al
testb $0x1, %al
jne 0x16c8e
jmp 0x16b2f
movq 0x154ba(%rip), %rdi     # 0x2bff0
leaq 0xcc45(%rip), %rsi      # 0x23782
callq 0x4310
movq %rax, -0x1a0(%rbp)
jmp 0x16b4b
movq -0x1a0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x42e0
movq %rax, -0x1a8(%rbp)
jmp 0x16b64
movq -0x1a8(%rbp), %rdi
leaq 0xcb58(%rip), %rsi      # 0x236ca
callq 0x4310
movq %rax, -0x1b0(%rbp)
jmp 0x16b80
movq -0x1b0(%rbp), %rdi
movq 0x15422(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0x16b95
movl $0x2, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x16cda
movq -0x50(%rbp), %rdi
callq 0x4130
movq %rax, -0xb8(%rbp)
movq 0x1541e(%rip), %rdi     # 0x2bff0
leaq 0xcbca(%rip), %rsi      # 0x237a3
callq 0x4310
movq %rax, -0x1b8(%rbp)
jmp 0x16be7
movq -0x1b8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x42e0
movq %rax, -0x1c0(%rbp)
jmp 0x16c00
movq -0x1c0(%rbp), %rdi
leaq 0xcac8(%rip), %rsi      # 0x236d6
callq 0x4310
movq %rax, -0x1c8(%rbp)
jmp 0x16c1c
movq -0xb8(%rbp), %rdi
callq 0x1ee90
movq %rax, %rsi
leaq -0xd8(%rbp), %rdi
callq 0x1eeb0
jmp 0x16c39
movq -0x1c8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x42e0
movq %rax, -0x1d0(%rbp)
jmp 0x16c55
movq -0x1d0(%rbp), %rdi
movq 0x15365(%rip), %rsi     # 0x2bfc8
callq 0x4350
jmp 0x16c6a
leaq -0xd8(%rbp), %rdi
callq 0x46d8
leaq 0xcb7d(%rip), %rdi      # 0x237fa
callq 0x42a0
jmp 0x16c84
movl $0x1, %edi
callq 0x4400
jmp 0x16cbf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x16cb6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x46d8
callq 0x4580
jmp 0x16cbd
jmp 0x16cda
leaq -0x48(%rbp), %rdi
callq 0x46d8
leaq -0x28(%rbp), %rdi
callq 0x46d8
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0x46d8
leaq -0x28(%rbp), %rdi
callq 0x46d8
movq -0x50(%rbp), %rdi
callq 0x4610
movq %rax, %rdi
callq 0x82c0
nopl (%rax)