// File: /workspace/github_cpp_makefile_star2_O1/CK7[P]abawaca/src/SCGdb.cpp
// Function: SCGdb::load_scgs()
void SCGdb::load_scgs()
{
	FILE* fin = fopen(scg_list_file.c_str(), "r");
	if(fin == NULL) {
		char	s[2048];
		sprintf(s, "Failed to read file %s", scg_list_file.c_str());
		throw invalid_argument(s);
	}

	char	scg[1024], gene[1024];

	total_num_scgs = 0;
	while(fscanf(fin, "%s", scg) == 1) {
		total_num_scgs++;
	}
	fclose(fin);

	// An empty SCG database
	if(gene2scg_file.size() == 0)
		return;

	fin = fopen(gene2scg_file.c_str(), "r");
	if(fin == NULL) {
		char	s[2048];
		sprintf(s, "Failed to read file %s", gene2scg_file.c_str());
		throw invalid_argument(s);
	}

	while(fscanf(fin, "%s %s", gene, scg) == 2) {
		char* p = strrchr(gene, '_');
		if(p == NULL) {
			char	s[2048];
			sprintf(s, "Unexpected gene name %s, expected prodigal format: <name>_<integer>\nfile: %s", gene, scg_list_file.c_str());
			throw invalid_argument(s);
		}

		*p = 0;
		size_t scaf = scaf_db.scaf_name2id(gene);
		// The following can happen if a sequence is in the file that was used for the SCG analysis but was not in the file that was binned.
		// We are fine with that.
		if(scaf == 0) {
			continue;
		}

		int gene_id = atoi(p+1);

		if(gene_id == 0) {
			string scaf_name = gene;
			*p = '_';
			char	s[2048];
			sprintf(s, "Could not identify gene id in %s (recovered scaf=%s (%lu), gene_id=%s). Expecting prodigal format gene names: <name>_<integer>\nfile: %s",
				gene, scaf_name.c_str(), scaf, p+1, scg_list_file.c_str());
			throw invalid_argument(s);
		}
		auto it = scaf2scgs.find(scaf);
		if(it == scaf2scgs.end()) {
			scaf2scgs.insert(pair<size_t, set<string> >(scaf, set<string>()));
			it = scaf2scgs.find(scaf);
		}
		it->second.insert(scg);
	}
	fclose(fin);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1088, %rsp           # imm = 0x1088
movq %rdi, %rbx
movq 0x20(%rdi), %rdi
leaq 0x4999(%rip), %rsi      # 0x1a131
callq 0x5450
testq %rax, %rax
je 0x15b9c
movq %rax, %r14
movl $0x0, 0x70(%rbx)
leaq 0x59c1(%rip), %rsi      # 0x1b178
leaq -0x10a0(%rbp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0x56f0
cmpl $0x1, %eax
jne 0x157f3
leaq 0x59a4(%rip), %r15      # 0x1b178
leaq -0x10a0(%rbp), %r12
incl 0x70(%rbx)
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x56f0
cmpl $0x1, %eax
je 0x157db
movq %r14, %rdi
callq 0x5390
cmpq $0x0, 0x8(%rbx)
je 0x15aa0
movq %rbx, -0x30(%rbp)
movq (%rbx), %rdi
leaq 0x491d(%rip), %rsi      # 0x1a131
callq 0x5450
testq %rax, %rax
je 0x15bd5
movq %rax, %r14
leaq 0x5c0c(%rip), %rsi      # 0x1b438
leaq -0xca0(%rbp), %rdx
leaq -0x10a0(%rbp), %rcx
movq %rax, %rdi
xorl %eax, %eax
callq 0x56f0
cmpl $0x2, %eax
jne 0x15a98
movq -0x30(%rbp), %rax
leaq 0x40(%rax), %rcx
movq %rcx, -0x78(%rbp)
addq $0x48, %rax
movq %rax, -0x38(%rbp)
leaq -0xca0(%rbp), %r15
leaq -0xa0(%rbp), %r13
movq %r14, -0x80(%rbp)
movq %r15, %rdi
movl $0x5f, %esi
callq 0x53f0
testq %rax, %rax
je 0x15ab2
movq %r15, %rbx
movq %rax, %r15
movb $0x0, (%rax)
movq -0x30(%rbp), %rax
movq 0x78(%rax), %r14
leaq -0x90(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq %rbx, %rdi
callq 0x5180
leaq (%rax,%rbp), %rdx
addq $-0xca0, %rdx           # imm = 0xF360
movq %r13, %rdi
movq %rbx, %rsi
callq 0xb314
movq %r14, %rdi
movq %r13, %rbx
movq %r13, %rsi
callq 0x15c94
movq %rax, %r12
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x158ef
callq 0x5340
testq %r12, %r12
je 0x15a66
movq %r15, %r14
incq %r14
movq %r14, %rdi
callq 0x55c0
testl %eax, %eax
je 0x15b07
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rcx
movq -0x38(%rbp), %rsi
movq %rsi, %rax
testq %rcx, %rcx
je 0x1593c
movq %rsi, %rax
xorl %edx, %edx
cmpq %r12, 0x20(%rcx)
setb %dl
cmovaeq %rcx, %rax
movq 0x10(%rcx,%rdx,8), %rcx
testq %rcx, %rcx
jne 0x15925
movq %rsi, %r14
cmpq %rsi, %rax
leaq -0x890(%rbp), %r15
je 0x15956
cmpq 0x20(%rax), %r12
cmovbq %rsi, %rax
movq %rax, %r14
cmpq %rsi, %r14
jne 0x15a13
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x70(%rbp)
leaq -0x68(%rbp), %rax
movq %rax, -0x58(%rbp)
movq %rax, -0x50(%rbp)
xorl %eax, %eax
movq %rax, -0x48(%rbp)
movq %r12, -0x8a0(%rbp)
movl $0x0, -0x890(%rbp)
movq %rax, -0x888(%rbp)
movq %r15, -0x880(%rbp)
movq %r15, -0x878(%rbp)
movq %rax, -0x870(%rbp)
movq -0x78(%rbp), %rdi
leaq -0x8a0(%rbp), %rsi
callq 0x160d0
leaq -0x898(%rbp), %rdi
callq 0x990a
leaq -0x70(%rbp), %rdi
callq 0x990a
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rcx
movq -0x38(%rbp), %rsi
movq %rsi, %rax
testq %rcx, %rcx
je 0x15a00
movq %rsi, %rax
xorl %edx, %edx
cmpq %r12, 0x20(%rcx)
setb %dl
cmovaeq %rcx, %rax
movq 0x10(%rcx,%rdx,8), %rcx
testq %rcx, %rcx
jne 0x159e9
movq %rsi, %r14
cmpq %rsi, %rax
je 0x15a13
cmpq 0x20(%rax), %r12
cmovbq %rsi, %rax
movq %rax, %r14
movq %r15, -0x8a0(%rbp)
leaq -0x10a0(%rbp), %r12
movq %r12, %rdi
callq 0x5180
leaq (%rax,%rbp), %rdx
addq $-0x10a0, %rdx          # imm = 0xEF60
leaq -0x8a0(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0xb314
addq $0x28, %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x16248
movq -0x8a0(%rbp), %rdi
cmpq %r15, %rdi
je 0x15a66
callq 0x5340
movq -0x80(%rbp), %r14
movq %r14, %rdi
leaq 0x59c4(%rip), %rsi      # 0x1b438
leaq -0xca0(%rbp), %r15
movq %r15, %rdx
leaq -0x10a0(%rbp), %rcx
xorl %eax, %eax
callq 0x56f0
cmpl $0x2, %eax
movq %rbx, %r13
je 0x15873
movq %r14, %rdi
callq 0x5390
addq $0x1088, %rsp           # imm = 0x1088
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rcx
leaq 0x597d(%rip), %rsi      # 0x1b43e
leaq -0x8a0(%rbp), %rbx
leaq -0xca0(%rbp), %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x5090
movl $0x10, %edi
callq 0x51b0
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5730
movq 0xd4d0(%rip), %rsi      # 0x22fc8
movq 0xd4b9(%rip), %rdx      # 0x22fb8
movq %r14, %rdi
callq 0x5660
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
leaq -0xca0(%rbp), %r13
movq %r13, %rdi
callq 0x5180
leaq (%rax,%rbp), %rdx
addq $-0xca0, %rdx           # imm = 0xF360
leaq -0x70(%rbp), %rdi
movq %r13, %rsi
callq 0xb314
movb $0x5f, (%r15)
movq -0x70(%rbp), %rcx
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, (%rsp)
leaq 0x593b(%rip), %rsi      # 0x1b48b
leaq -0x8a0(%rbp), %rbx
leaq -0xca0(%rbp), %rdx
movq %rbx, %rdi
movq %r12, %r8
movq %r14, %r9
xorl %eax, %eax
callq 0x5090
movl $0x10, %edi
callq 0x51b0
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5730
movq 0xd43b(%rip), %rsi      # 0x22fc8
movq 0xd424(%rip), %rdx      # 0x22fb8
movq %r14, %rdi
callq 0x5660
movq 0x20(%rbx), %rdx
leaq 0x587a(%rip), %rsi      # 0x1b421
leaq -0x8a0(%rbp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x5090
movl $0x10, %edi
callq 0x51b0
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5730
jmp 0x15af1
movq -0x30(%rbp), %rax
movq (%rax), %rdx
leaq 0x583e(%rip), %rsi      # 0x1b421
leaq -0x8a0(%rbp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x5090
movl $0x10, %edi
callq 0x51b0
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5730
jmp 0x15af1
jmp 0x15c4b
jmp 0x15c4b
movq %rax, %rbx
jmp 0x15c25
movq %rax, %rbx
movq %r14, %rdi
callq 0x5280
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
jmp 0x15c81
movq %rax, %rbx
leaq -0x898(%rbp), %rdi
callq 0x990a
leaq -0x70(%rbp), %rdi
callq 0x990a
jmp 0x15c8b
jmp 0x15c6b
movq %rax, %rbx
movq %r14, %rdi
callq 0x5280
jmp 0x15c8b
movq %rax, %rbx
movq -0x8a0(%rbp), %rdi
cmpq %r15, %rdi
jne 0x15c86
jmp 0x15c8b
jmp 0x15c6b
movq %rax, %rbx
jmp 0x15c8b
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x15c8b
callq 0x5340
movq %rbx, %rdi
callq 0x56a0
nop