// File: 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 %rbp
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
movq %rsi, -0xe8(%rbp)
addq $0x668, %rsi            # imm = 0x668
movq %rsi, -0xe0(%rbp)
leaq 0x1410d(%rip), %rdx     # 0x2381c
leaq -0x28(%rbp), %rdi
callq 0x7920
movq -0xe0(%rbp), %rsi
leaq 0x14057(%rip), %rdx     # 0x2377d
leaq -0x48(%rbp), %rdi
callq 0x7920
jmp 0xf731
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 $0x8, %edi
movl $0x4, %esi
callq 0x1ee70
movl %eax, -0xec(%rbp)
jmp 0xf770
movl -0xec(%rbp), %edx
movq -0xf8(%rbp), %rsi
movq -0x100(%rbp), %rdi
callq 0x42f0
jmp 0xf78b
movq -0xe8(%rbp), %rdi
addq $0x8, %rdi
callq 0x45e0
movb %al, -0x101(%rbp)
jmp 0xf7a3
movb -0x101(%rbp), %al
testb $0x1, %al
jne 0xf928
jmp 0xf7b3
movq 0x1c836(%rip), %rdi     # 0x2bff0
leaq 0x13d77(%rip), %rsi     # 0x23538
callq 0x4310
movq %rax, -0x110(%rbp)
jmp 0xf7cf
movq -0x110(%rbp), %rdi
movq -0xe8(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0x118(%rbp)
jmp 0xf7f2
movq -0x118(%rbp), %rdi
leaq 0x13d54(%rip), %rsi     # 0x23554
callq 0x4310
movq %rax, -0x120(%rbp)
jmp 0xf80e
movq -0x120(%rbp), %rdi
movq 0x1c794(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0xf823
movl $0x2, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xfea9
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 0xfea0
movq -0x50(%rbp), %rdi
callq 0x4130
movq %rax, -0x60(%rbp)
movq 0x1c782(%rip), %rdi     # 0x2bff0
leaq 0x13fac(%rip), %rsi     # 0x23821
callq 0x4310
movq %rax, -0x128(%rbp)
jmp 0xf883
movq -0x128(%rbp), %rdi
movq -0xe8(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0x130(%rbp)
jmp 0xf8a6
movq -0x130(%rbp), %rdi
leaq 0x14131(%rip), %rsi     # 0x239e5
callq 0x4310
movq %rax, -0x138(%rbp)
jmp 0xf8c2
movq -0x60(%rbp), %rdi
callq 0x1ee90
movq %rax, %rsi
leaq -0x80(%rbp), %rdi
callq 0x1eeb0
jmp 0xf8d9
movq -0x138(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x42e0
movq %rax, -0x140(%rbp)
jmp 0xf8f2
movq -0x140(%rbp), %rdi
movq 0x1c6c8(%rip), %rsi     # 0x2bfc8
callq 0x4350
jmp 0xf907
leaq -0x80(%rbp), %rdi
callq 0x46d8
leaq 0x13ee3(%rip), %rdi     # 0x237fa
callq 0x42a0
jmp 0xf91e
movl $0x1, %edi
callq 0x4400
jmp 0xf959
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xf94d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x46d8
callq 0x4580
jmp 0xf954
jmp 0xfea0
movq -0xe8(%rbp), %rdi
addq $0x8, %rdi
leaq -0x83(%rbp), %rsi
movl $0x3, %edx
callq 0x4450
jmp 0xf977
movsbl -0x83(%rbp), %eax
cmpl $0x6c, %eax
jne 0xf993
movsbl -0x82(%rbp), %eax
cmpl $0x1b, %eax
je 0xfa1e
movq 0x1c656(%rip), %rdi     # 0x2bff0
leaq 0x13e9d(%rip), %rsi     # 0x2383e
callq 0x4310
movq %rax, -0x148(%rbp)
jmp 0xf9af
movq -0x148(%rbp), %rdi
movq -0xe8(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0x150(%rbp)
jmp 0xf9d2
movq -0x150(%rbp), %rdi
leaq 0x13e72(%rip), %rsi     # 0x23852
callq 0x4310
movq %rax, -0x158(%rbp)
jmp 0xf9ee
movq -0x158(%rbp), %rdi
movq 0x1c5b4(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0xfa03
movl $0x2, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xfea0
movsbl -0x81(%rbp), %eax
cmpl $0x1, %eax
je 0xfaa4
movq 0x1c5bf(%rip), %rdi     # 0x2bff0
leaq 0x13e06(%rip), %rsi     # 0x2383e
callq 0x4310
movq %rax, -0x160(%rbp)
jmp 0xfa46
movq -0x160(%rbp), %rdi
movq -0xe8(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0x168(%rbp)
jmp 0xfa69
movq -0x168(%rbp), %rdi
leaq 0x13df2(%rip), %rsi     # 0x23869
callq 0x4310
movq %rax, -0x170(%rbp)
jmp 0xfa85
movq -0x170(%rbp), %rdi
movq 0x1c51d(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0xfa9a
movl $0x3, %edi
callq 0x4400
jmp 0xfaa6
movq -0xe8(%rbp), %rax
addq $0x458, %rax            # imm = 0x458
movq %rax, -0x178(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x4140
movq -0x178(%rbp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0x42f0
jmp 0xfad9
movq -0xe8(%rbp), %rdi
addq $0x458, %rdi            # imm = 0x458
callq 0x45e0
movb %al, -0x179(%rbp)
jmp 0xfaf4
movb -0x179(%rbp), %al
testb $0x1, %al
jne 0xfc63
jmp 0xfb04
movq 0x1c4e5(%rip), %rdi     # 0x2bff0
leaq 0x13d8f(%rip), %rsi     # 0x238a1
callq 0x4310
movq %rax, -0x188(%rbp)
jmp 0xfb20
movq -0x188(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x42e0
movq %rax, -0x190(%rbp)
jmp 0xfb39
movq -0x190(%rbp), %rdi
leaq 0x13a0d(%rip), %rsi     # 0x23554
callq 0x4310
movq %rax, -0x198(%rbp)
jmp 0xfb55
movq -0x198(%rbp), %rdi
movq 0x1c44d(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0xfb6a
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 0xfea0
movq -0x50(%rbp), %rdi
callq 0x4130
movq %rax, -0x90(%rbp)
movq 0x1c449(%rip), %rdi     # 0x2bff0
leaq 0x13d14(%rip), %rsi     # 0x238c2
callq 0x4310
movq %rax, -0x1a0(%rbp)
jmp 0xfbbc
movq -0x1a0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x42e0
movq %rax, -0x1a8(%rbp)
jmp 0xfbd5
movq -0x1a8(%rbp), %rdi
leaq 0x13e02(%rip), %rsi     # 0x239e5
callq 0x4310
movq %rax, -0x1b0(%rbp)
jmp 0xfbf1
movq -0x90(%rbp), %rdi
callq 0x1ee90
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x1eeb0
jmp 0xfc0e
movq -0x1b0(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x42e0
movq %rax, -0x1b8(%rbp)
jmp 0xfc2a
movq -0x1b8(%rbp), %rdi
movq 0x1c390(%rip), %rsi     # 0x2bfc8
callq 0x4350
jmp 0xfc3f
leaq -0xb0(%rbp), %rdi
callq 0x46d8
leaq 0x13ba8(%rip), %rdi     # 0x237fa
callq 0x42a0
jmp 0xfc59
movl $0x1, %edi
callq 0x4400
jmp 0xfc97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xfc8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x46d8
callq 0x4580
jmp 0xfc92
jmp 0xfea0
movq -0xe8(%rbp), %rax
addq $0x248, %rax            # imm = 0x248
movq %rax, -0x1c0(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4140
movq -0x1c0(%rbp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0x42f0
jmp 0xfcca
movq -0xe8(%rbp), %rdi
addq $0x248, %rdi            # imm = 0x248
callq 0x45e0
movb %al, -0x1c1(%rbp)
jmp 0xfce5
movb -0x1c1(%rbp), %al
testb $0x1, %al
jne 0xfe54
jmp 0xfcf5
movq 0x1c2f4(%rip), %rdi     # 0x2bff0
leaq 0x13a7f(%rip), %rsi     # 0x23782
callq 0x4310
movq %rax, -0x1d0(%rbp)
jmp 0xfd11
movq -0x1d0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x42e0
movq %rax, -0x1d8(%rbp)
jmp 0xfd2a
movq -0x1d8(%rbp), %rdi
leaq 0x1381c(%rip), %rsi     # 0x23554
callq 0x4310
movq %rax, -0x1e0(%rbp)
jmp 0xfd46
movq -0x1e0(%rbp), %rdi
movq 0x1c25c(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0xfd5b
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 0xfea0
movq -0x50(%rbp), %rdi
callq 0x4130
movq %rax, -0xb8(%rbp)
movq 0x1c258(%rip), %rdi     # 0x2bff0
leaq 0x13a04(%rip), %rsi     # 0x237a3
callq 0x4310
movq %rax, -0x1e8(%rbp)
jmp 0xfdad
movq -0x1e8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x42e0
movq %rax, -0x1f0(%rbp)
jmp 0xfdc6
movq -0x1f0(%rbp), %rdi
leaq 0x13c11(%rip), %rsi     # 0x239e5
callq 0x4310
movq %rax, -0x1f8(%rbp)
jmp 0xfde2
movq -0xb8(%rbp), %rdi
callq 0x1ee90
movq %rax, %rsi
leaq -0xd8(%rbp), %rdi
callq 0x1eeb0
jmp 0xfdff
movq -0x1f8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x42e0
movq %rax, -0x200(%rbp)
jmp 0xfe1b
movq -0x200(%rbp), %rdi
movq 0x1c19f(%rip), %rsi     # 0x2bfc8
callq 0x4350
jmp 0xfe30
leaq -0xd8(%rbp), %rdi
callq 0x46d8
leaq 0x139b7(%rip), %rdi     # 0x237fa
callq 0x42a0
jmp 0xfe4a
movl $0x1, %edi
callq 0x4400
jmp 0xfe85
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xfe7c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x46d8
callq 0x4580
jmp 0xfe83
jmp 0xfea0
leaq -0x48(%rbp), %rdi
callq 0x46d8
leaq -0x28(%rbp), %rdi
callq 0x46d8
addq $0x200, %rsp            # imm = 0x200
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
nopw %cs:(%rax,%rax)