// File: CMU-SAFARI[P]optimal-seed-solver/RefDB.cc
// Function: RefDB::loadRefFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void RefDB::loadRefFile(string refName) {
	if (refFile.is_open()) {
		refFile.close();
		refPos.clear();
	}

	refFile.open(refName.c_str());

	if (!refFile.is_open()) {
		cerr << "RefFile open failed" << endl;
		exit(1);
	}

	string refMetaName = "." + refName + ".meta";
	fstream refMetaFile(refMetaName.c_str(), ios_base::in);

	if (refMetaFile.is_open()) {
		unsigned long int tempPos;
		while (refMetaFile >> tempPos) {
			refPos.push_back((streampos) tempPos);
		}

		cout << "refPos.size(): " << refPos.size() << endl;

	} else {

		refMetaFile.open(refMetaName.c_str(), ios_base::out | ios_base::trunc);

		string temp;
		streampos tempRefPos;

		while (refFile.good()) {
			tempRefPos = refFile.tellg();
			getline(refFile, temp);
			if (temp[0] == '>') {
				refPos.push_back(tempRefPos);
				refMetaFile << (unsigned long int) tempRefPos << endl;
			}
		}
	}

	refMetaFile.close();
}

// Assembly:
subq $0x358, %rsp            # imm = 0x358
movq %rsi, 0x80(%rsp)
movq %rdi, 0x350(%rsp)
movq %rsi, 0x348(%rsp)
movq 0x350(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0x3410
testb $0x1, %al
jne 0x3e3a
jmp 0x3e5b
movq 0x88(%rsp), %rdi
callq 0x3080
movq 0x88(%rsp), %rdi
addq $0x208, %rdi            # imm = 0x208
callq 0x48e0
movq 0x80(%rsp), %rdi
callq 0x3110
movq 0x88(%rsp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0x3190
movq 0x88(%rsp), %rdi
callq 0x3410
testb $0x1, %al
jne 0x3eba
movq 0x515b(%rip), %rdi      # 0x8ff0
leaq 0x21d3(%rip), %rsi      # 0x606f
callq 0x3240
movq %rax, %rdi
movq 0x5115(%rip), %rsi      # 0x8fc0
callq 0x3280
movl $0x1, %edi
callq 0x3300
movq 0x80(%rsp), %rdx
leaq 0x21ba(%rip), %rsi      # 0x6083
leaq 0x308(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x4950
movq 0x78(%rsp), %rsi
leaq 0x219e(%rip), %rdx      # 0x6085
leaq 0x328(%rsp), %rdi
callq 0x4900
jmp 0x3ef6
leaq 0x308(%rsp), %rdi
callq 0x3180
leaq 0x328(%rsp), %rdi
callq 0x3110
movq %rax, %rsi
leaq 0xe8(%rsp), %rdi
movl $0x8, %edx
callq 0x3370
jmp 0x3f27
leaq 0xe8(%rsp), %rdi
callq 0x3460
movb %al, 0x77(%rsp)
jmp 0x3f3a
movb 0x77(%rsp), %al
testb $0x1, %al
jne 0x3f47
jmp 0x4081
jmp 0x3f49
leaq 0xe8(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x3390
movq %rax, 0x68(%rsp)
jmp 0x3f65
movq 0x68(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3330
movb %al, 0x67(%rsp)
jmp 0x3f7f
movb 0x67(%rsp), %al
testb $0x1, %al
jne 0x3f8c
jmp 0x4027
movq 0x88(%rsp), %rax
addq $0x208, %rax            # imm = 0x208
movq %rax, 0x58(%rsp)
movq 0xe0(%rsp), %rsi
leaq 0xd0(%rsp), %rdi
callq 0x4ab0
jmp 0x3fb6
movq 0x58(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x4a80
jmp 0x3fca
jmp 0x3f49
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x300(%rsp)
movl %eax, 0x2fc(%rsp)
leaq 0x308(%rsp), %rdi
callq 0x3180
jmp 0x4273
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x300(%rsp)
movl %eax, 0x2fc(%rsp)
jmp 0x4266
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x300(%rsp)
movl %eax, 0x2fc(%rsp)
jmp 0x4259
movq 0x4fa2(%rip), %rdi      # 0x8fd0
leaq 0x2056(%rip), %rsi      # 0x608b
callq 0x3240
movq %rax, 0x50(%rsp)
jmp 0x4041
movq 0x88(%rsp), %rdi
addq $0x208, %rdi            # imm = 0x208
callq 0x4ae0
movq 0x50(%rsp), %rdi
movq %rax, %rsi
callq 0x30a0
movq %rax, 0x48(%rsp)
jmp 0x4069
movq 0x48(%rsp), %rdi
movq 0x4f4b(%rip), %rsi      # 0x8fc0
callq 0x3280
jmp 0x407c
jmp 0x4228
leaq 0x328(%rsp), %rdi
callq 0x3110
movq %rax, 0x38(%rsp)
movl $0x10, %edi
movl $0x20, %esi
callq 0x4b00
movl %eax, 0x44(%rsp)
jmp 0x40a8
movl 0x44(%rsp), %edx
movq 0x38(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
callq 0x3220
jmp 0x40c0
leaq 0xb0(%rsp), %rdi
callq 0x3380
leaq 0xa0(%rsp), %rdi
callq 0x4b20
jmp 0x40dc
jmp 0x40de
movq 0x88(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3440
movb %al, 0x37(%rsp)
jmp 0x40fb
movb 0x37(%rsp), %al
testb $0x1, %al
jne 0x4108
jmp 0x421b
movq 0x88(%rsp), %rdi
callq 0x3480
movq %rdx, 0x20(%rsp)
movq %rax, 0x28(%rsp)
jmp 0x4121
movq 0x88(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, 0x90(%rsp)
movq %rax, 0x98(%rsp)
movups 0x90(%rsp), %xmm0
movaps %xmm0, 0xa0(%rsp)
leaq 0xb0(%rsp), %rsi
callq 0x3070
jmp 0x4162
xorl %eax, %eax
movl %eax, %esi
leaq 0xb0(%rsp), %rdi
callq 0x34f0
movq %rax, 0x18(%rsp)
jmp 0x417a
movq 0x18(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x3e, %eax
jne 0x4216
movq 0x88(%rsp), %rdi
addq $0x208, %rdi            # imm = 0x208
leaq 0xa0(%rsp), %rsi
callq 0x4b50
jmp 0x41a9
leaq 0xf8(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x4bc0
movq %rax, 0x10(%rsp)
jmp 0x41ca
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x30a0
movq %rax, (%rsp)
jmp 0x41df
movq (%rsp), %rdi
movq 0x4dd6(%rip), %rsi      # 0x8fc0
callq 0x3280
jmp 0x41f1
jmp 0x4216
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x300(%rsp)
movl %eax, 0x2fc(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x3180
jmp 0x4259
jmp 0x40de
leaq 0xb0(%rsp), %rdi
callq 0x3180
leaq 0xe8(%rsp), %rdi
callq 0x3040
jmp 0x4237
leaq 0xe8(%rsp), %rdi
callq 0x3090
leaq 0x328(%rsp), %rdi
callq 0x3180
addq $0x358, %rsp            # imm = 0x358
retq
leaq 0xe8(%rsp), %rdi
callq 0x3090
leaq 0x328(%rsp), %rdi
callq 0x3180
movq 0x300(%rsp), %rdi
callq 0x3490