// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movq %rdi, %r15
movl $0x1, %edi
movl $0x20, %esi
callq 0x3530
movq %rax, %rbx
movl $0x1, %edi
movl $0x28, %esi
callq 0x3530
movq %rbx, 0x10(%rsp)
movq %rax, 0x18(%rbx)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %ebp, %ebp
movq $0x0, 0x20(%rsp)
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
xorl %eax, %eax
movq $0x0, 0x18(%rsp)
movl %eax, %r13d
movq 0x20(%rsp), %r12
movl %ecx, 0xc(%rsp)
testl %ecx, %ecx
sets %al
testl %r13d, %r13d
sete %cl
andb %al, %cl
cmpl $0x2, %r13d
sete %bl
orb %cl, %bl
movq %r15, %rdi
leaq 0x3(%rsp), %rsi
movl $0x1, %edx
callq 0x2292b
testl %eax, %eax
je 0x1a73a
movzbl 0x3(%rsp), %eax
cmpl $0xa, %eax
jne 0x1a54c
cmpl $0x1, %r13d
je 0x1a537
testb %bl, %bl
jne 0x1a504
jmp 0x1a632
movq 0x28(%r15), %rax
movq %rax, 0x18(%rsp)
movl $0x1, %r13d
movl 0xc(%rsp), %ecx
jmp 0x1a4ee
cmpl $0x3e, %eax
jne 0x1a63a
movl 0xc(%rsp), %edx
testl %edx, %edx
js 0x1a578
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movl 0x8(%rsp), %ecx
movl 0x4(%rsp), %r8d
movq 0x18(%rsp), %r9
callq 0x1a7c3
movq %r15, %rdi
leaq 0x3(%rsp), %rsi
movl $0x1, %edx
callq 0x2292b
testl %eax, %eax
sete %r14b
je 0x1a7bf
callq 0x3310
movq %rax, %r13
movq (%rax), %rax
movsbq 0x3(%rsp), %rcx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x1a6f7
movl $0x1, %ebx
leal 0x1(%rbx), %eax
cmpl %eax, %ebp
jge 0x1a5f0
movl %ebx, %eax
shrl %eax
orl %ebx, %eax
movl %eax, %ecx
shrl $0x2, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x8, %ecx
orl %eax, %ecx
movl %ecx, %ebp
shrl $0x10, %ebp
orl %ecx, %ebp
incl %ebp
movslq %ebp, %rsi
movq %r12, %rdi
callq 0x3610
movq %rax, %r12
movb 0x3(%rsp), %al
movb %al, -0x1(%r12,%rbx)
movq %r15, %rdi
leaq 0x3(%rsp), %rsi
movl $0x1, %edx
callq 0x2292b
testl %eax, %eax
sete %r14b
je 0x1a776
movq (%r13), %rax
movsbq 0x3(%rsp), %rcx
incq %rbx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x1a5b7
decl %ebx
jmp 0x1a6f9
cmpb $0x3e, %al
je 0x1a555
cmpl $0x3, %r13d
je 0x1a78e
xorl %r12d, %r12d
movl $0x1, %r14d
callq 0x3310
movq %rax, %rbx
movl %r12d, %eax
movq (%rbx), %rcx
movsbq 0x3(%rsp), %rdx
movzwl (%rcx,%rdx,2), %r12d
shrl $0xf, %r12d
addl %eax, %r12d
movq %r15, %rdi
leaq 0x3(%rsp), %rsi
movl $0x1, %edx
callq 0x2292b
incl %r14d
testl %eax, %eax
je 0x1a68d
cmpb $0xa, 0x3(%rsp)
jne 0x1a655
cmpl $0x2, %r13d
movl %r13d, %eax
movl $0x3, %ecx
cmovel %ecx, %eax
cmpl $0x3, %eax
movl 0xc(%rsp), %ecx
jne 0x1a6ae
testl %r12d, %r12d
jne 0x1a79d
cmpl $0x10000, %r12d         # imm = 0x10000
jae 0x1a7ae
addl %r12d, %ecx
testl %r13d, %r13d
je 0x1a6de
cmpl $0x1, %r13d
jne 0x1a4e2
xorl %eax, %eax
movl %r14d, 0x8(%rsp)
movl %r12d, 0x4(%rsp)
jmp 0x1a4e2
xorl 0x8(%rsp), %r14d
xorl 0x4(%rsp), %r12d
xorl %eax, %eax
orl %r14d, %r12d
setne %al
addl %eax, %eax
jmp 0x1a4e2
xorl %ebx, %ebx
movb $0x0, (%r12,%rbx)
testb %r14b, %r14b
jne 0x1a77d
movq %r12, 0x20(%rsp)
cmpb $0xa, 0x3(%rsp)
je 0x1a725
movq %r15, %rdi
leaq 0x3(%rsp), %rsi
movl $0x1, %edx
callq 0x2292b
testl %eax, %eax
jne 0x1a708
movq 0x28(%r15), %rax
movq %rax, 0x18(%rsp)
movl $0x1, %eax
xorl %ecx, %ecx
jmp 0x1a4e2
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %ecx
movl 0x4(%rsp), %r8d
movq 0x18(%rsp), %r9
callq 0x1a7c3
movq %r12, %rdi
callq 0x32c0
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebx, %eax
movb $0x0, (%r12,%rax)
movq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x487a
xorl %ebx, %ebx
jmp 0x1a764
movq %r12, %rdi
movq 0x10(%rsp), %rsi
callq 0x4932
jmp 0x1a78a
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x48f5
jmp 0x1a78a
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x48b8
jmp 0x1a78a
xorl %eax, %eax
jmp 0x1a778