// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/faidx.c
// Function: fai_build_core
faidx_t *fai_build_core(RAZF *rz)
{
	char c, *name;
	int l_name, m_name, ret;
	int len, line_len, line_blen, state;
	int l1, l2;
	faidx_t *idx;
	uint64_t offset;

	idx = (faidx_t*)calloc(1, sizeof(faidx_t));
	idx->hash = kh_init(s);
	name = 0; l_name = m_name = 0;
	len = line_len = line_blen = -1; state = 0; l1 = l2 = -1; offset = 0;
	while (razf_read(rz, &c, 1)) {
		if (c == '\n') { // an empty line
			if (state == 1) {
				offset = razf_tell(rz);
				continue;
			} else if ((state == 0 && len < 0) || state == 2) continue;
		}
		if (c == '>') { // fasta header
			if (len >= 0)
				fai_insert_index(idx, name, len, line_len, line_blen, offset);
			l_name = 0;
			while ((ret = razf_read(rz, &c, 1)) != 0 && !isspace(c)) {
				if (m_name < l_name + 2) {
					m_name = l_name + 2;
					kroundup32(m_name);
					name = (char*)realloc(name, m_name);
				}
				name[l_name++] = c;
			}
			name[l_name] = '\0';
			if (ret == 0) {
				fprintf(stderr, "[fai_build_core] the last entry has no sequence\n");
				free(name); fai_destroy(idx);
				return 0;
			}
			if (c != '\n') while (razf_read(rz, &c, 1) && c != '\n');
			state = 1; len = 0;
			offset = razf_tell(rz);
		} else {
			if (state == 3) {
				fprintf(stderr, "[fai_build_core] inlined empty line is not allowed in sequence '%s'.\n", name);
				free(name); fai_destroy(idx);
				return 0;
			}
			if (state == 2) state = 3;
			l1 = l2 = 0;
			do {
				++l1;
				if (isgraph(c)) ++l2;
			} while ((ret = razf_read(rz, &c, 1)) && c != '\n');
			if (state == 3 && l2) {
				fprintf(stderr, "[fai_build_core] different line length in sequence '%s'.\n", name);
				free(name); fai_destroy(idx);
				return 0;
			}
			++l1; len += l2;
			if (l2 >= 0x10000) {
				fprintf(stderr, "[fai_build_core] line length exceeds 65535 in sequence '%s'.\n", name);
				free(name); fai_destroy(idx);
				return 0;
			}
			if (state == 1) line_len = l1, line_blen = l2, state = 0;
			else if (state == 0) {
				if (l1 != line_len || l2 != line_blen) state = 2;
			}
		}
	}
	fai_insert_index(idx, name, len, line_len, line_blen, offset);
	free(name);
	return idx;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movl $0x1, %edi
movl $0x20, %esi
callq 0x3530
movq %rax, %rbx
movl $0x1, %edi
movl $0x28, %esi
callq 0x3530
movq %rbx, 0x18(%rsp)
movq %rax, 0x18(%rbx)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %ebp, %ebp
xorl %r15d, %r15d
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
xorl %eax, %eax
movq $0x0, 0x28(%rsp)
movq %r15, 0x20(%rsp)
movl %eax, %r12d
movq 0x30(%rsp), %r14
leaq 0xb(%rsp), %r13
movl %ecx, 0x14(%rsp)
testl %ecx, %ecx
sets %al
testl %r12d, %r12d
sete %cl
andb %al, %cl
cmpl $0x2, %r12d
sete %bl
orb %cl, %bl
movq %r14, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x22445
testl %eax, %eax
je 0x1ad7e
movzbl 0xb(%rsp), %r15d
cmpl $0xa, %r15d
jne 0x1abb7
cmpl $0x1, %r12d
je 0x1aba2
testb %bl, %bl
jne 0x1ab72
jmp 0x1abc1
movq 0x28(%r14), %rax
movq %rax, 0x28(%rsp)
movl $0x1, %r12d
movl 0x14(%rsp), %ecx
jmp 0x1ab5c
cmpl $0x3e, %r15d
je 0x1ac7b
cmpl $0x3, %r12d
je 0x1add2
xorl %r13d, %r13d
movl $0x1, %r14d
callq 0x3310
movq %rax, %rbx
movl %r13d, %eax
movq (%rbx), %rcx
movsbq %r15b, %rdx
movzwl (%rcx,%rdx,2), %r13d
shrl $0xf, %r13d
addl %eax, %r13d
movq 0x30(%rsp), %rdi
leaq 0xb(%rsp), %rsi
movl $0x1, %edx
callq 0x22445
incl %r14d
testl %eax, %eax
je 0x1ac18
movb 0xb(%rsp), %r15b
cmpb $0xa, %r15b
jne 0x1abdc
cmpl $0x2, %r12d
movl %r12d, %eax
movl $0x3, %ecx
cmovel %ecx, %eax
cmpl $0x3, %eax
jne 0x1ac35
testl %r13d, %r13d
jne 0x1ade3
cmpl $0x10000, %r13d         # imm = 0x10000
movq 0x20(%rsp), %r15
jae 0x1adf4
movl 0x14(%rsp), %ecx
addl %r13d, %ecx
testl %r12d, %r12d
je 0x1ac62
cmpl $0x1, %r12d
jne 0x1ab4b
jmp 0x1ad6d
xorl 0x10(%rsp), %r14d
xorl 0xc(%rsp), %r13d
xorl %eax, %eax
orl %r14d, %r13d
setne %al
addl %eax, %eax
jmp 0x1ab4b
movl 0x14(%rsp), %edx
testl %edx, %edx
movq 0x20(%rsp), %r15
js 0x1aca3
movq 0x18(%rsp), %rdi
movq %r15, %rsi
movl 0x10(%rsp), %ecx
movl 0xc(%rsp), %r8d
movq 0x28(%rsp), %r9
callq 0x1ae07
movq %r14, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x22445
testl %eax, %eax
je 0x1ae03
callq 0x3310
movq %rax, %r12
xorl %ebx, %ebx
movq (%r12), %rcx
movsbq 0xb(%rsp), %rax
testb $0x20, 0x1(%rcx,%rax,2)
jne 0x1ad36
leal 0x2(%rbx), %ecx
cmpl %ecx, %ebp
jge 0x1ad16
leal 0x1(%rbx), %eax
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %ebp
shrl $0x10, %ebp
orl %eax, %ebp
incl %ebp
movslq %ebp, %rsi
movq %r15, %rdi
callq 0x3610
movq %rax, %r15
movb 0xb(%rsp), %al
movb %al, (%r15,%rbx)
movq %r14, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x22445
incq %rbx
testl %eax, %eax
jne 0x1acc5
jmp 0x1adbf
movl %ebx, %eax
movb $0x0, (%r15,%rax)
cmpb $0xa, 0xb(%rsp)
je 0x1ad58
movq %r14, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x22445
testl %eax, %eax
jne 0x1ad3d
movq 0x28(%r14), %rax
movq %rax, 0x28(%rsp)
movl $0x1, %eax
xorl %ecx, %ecx
jmp 0x1ab46
xorl %eax, %eax
movl %r14d, 0x10(%rsp)
movl %r13d, 0xc(%rsp)
jmp 0x1ab46
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq 0x20(%rsp), %r14
movq %r14, %rsi
movl 0x14(%rsp), %edx
movl 0x10(%rsp), %ecx
movl 0xc(%rsp), %r8d
movq 0x28(%rsp), %r9
callq 0x1ae07
movq %r14, %rdi
callq 0x32c0
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebx, %esi
movq %r15, %rdi
movq 0x18(%rsp), %rdx
callq 0x4b1d
xorl %ebx, %ebx
jmp 0x1adad
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x4bd9
jmp 0x1adce
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x4b9c
jmp 0x1adce
movq %r15, %rdi
movq 0x18(%rsp), %rsi
callq 0x4b5f
jmp 0x1adce
xorl %esi, %esi
jmp 0x1adc1