// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/faidx.c
// Function: fai_build_core
faidx_t *fai_build_core(RAZF *rz)
{
	char c, *name;
	int l_name, m_name, ret;
	int line_len, line_blen, state;
	int l1, l2;
	faidx_t *idx;
	uint64_t offset;
	int64_t len;

	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 (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, %r15
movl $0x1, %edi
movl $0x20, %esi
callq 0x32e0
movq %rax, %rbx
movl $0x1, %edi
movl $0x28, %esi
callq 0x32e0
movq %rbx, 0x18(%rsp)
movq %rax, 0x18(%rbx)
movq $-0x1, %rdx
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
xorl %ebp, %ebp
movq $0x0, 0x30(%rsp)
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
xorl %eax, %eax
movq $0x0, 0x20(%rsp)
movl %eax, %r13d
movq 0x30(%rsp), %r12
movq %rdx, 0x28(%rsp)
testq %rdx, %rdx
sets %al
testl %r13d, %r13d
sete %cl
andb %al, %cl
cmpl $0x2, %r13d
sete %bl
orb %cl, %bl
movq %r15, %rdi
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
callq 0x12b53
testl %eax, %eax
je 0x13734
movzbl 0xf(%rsp), %eax
cmpl $0xa, %eax
jne 0x1354d
cmpl $0x1, %r13d
je 0x13537
testb %bl, %bl
jne 0x13504
jmp 0x13635
movq 0x28(%r15), %rax
movq %rax, 0x20(%rsp)
movl $0x1, %r13d
movq 0x28(%rsp), %rdx
jmp 0x134ed
cmpl $0x3e, %eax
jne 0x1363d
movq 0x28(%rsp), %rdx
testq %rdx, %rdx
js 0x1357b
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movl 0x14(%rsp), %ecx
movl 0x10(%rsp), %r8d
movq 0x20(%rsp), %r9
callq 0x137ad
movq %r15, %rdi
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
callq 0x12b53
testl %eax, %eax
sete %r14b
je 0x137a9
callq 0x35f0
movq %rax, %r13
movq (%rax), %rax
movsbq 0xf(%rsp), %rcx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x136f1
movl $0x1, %ebx
leal 0x1(%rbx), %eax
cmpl %eax, %ebp
jge 0x135f3
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 0x3430
movq %rax, %r12
movb 0xf(%rsp), %al
movb %al, -0x1(%r12,%rbx)
movq %r15, %rdi
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
callq 0x12b53
testl %eax, %eax
sete %r14b
je 0x13771
movq (%r13), %rax
movsbq 0xf(%rsp), %rcx
incq %rbx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x135ba
decl %ebx
jmp 0x136f3
cmpb $0x3e, %al
je 0x13556
cmpl $0x3, %r13d
je 0x13789
xorl %r12d, %r12d
movl $0x1, %r14d
callq 0x35f0
movq %rax, %rbx
movl %r12d, %eax
movq (%rbx), %rcx
movsbq 0xf(%rsp), %rdx
movzwl (%rcx,%rdx,2), %r12d
shrl $0xf, %r12d
addl %eax, %r12d
movq %r15, %rdi
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
callq 0x12b53
incl %r14d
testl %eax, %eax
je 0x13690
cmpb $0xa, 0xf(%rsp)
jne 0x13658
cmpl $0x2, %r13d
movl %r13d, %eax
movl $0x3, %ecx
cmovel %ecx, %eax
cmpl $0x3, %eax
jne 0x136ad
testl %r12d, %r12d
jne 0x13798
movl %r12d, %ecx
movq 0x28(%rsp), %rdx
addq %rcx, %rdx
testl %r13d, %r13d
je 0x136d8
cmpl $0x1, %r13d
jne 0x134e0
xorl %eax, %eax
movl %r14d, 0x14(%rsp)
movl %r12d, 0x10(%rsp)
jmp 0x134e0
xorl 0x14(%rsp), %r14d
xorl 0x10(%rsp), %r12d
xorl %eax, %eax
orl %r14d, %r12d
setne %al
addl %eax, %eax
jmp 0x134e0
xorl %ebx, %ebx
movb $0x0, (%r12,%rbx)
testb %r14b, %r14b
jne 0x13778
movq %r12, 0x30(%rsp)
cmpb $0xa, 0xf(%rsp)
je 0x1371f
movq %r15, %rdi
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
callq 0x12b53
testl %eax, %eax
jne 0x13702
movq 0x28(%r15), %rax
movq %rax, 0x20(%rsp)
movl $0x1, %eax
xorl %edx, %edx
jmp 0x134e0
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
movq 0x28(%rsp), %rdx
movl 0x14(%rsp), %ecx
movl 0x10(%rsp), %r8d
movq 0x20(%rsp), %r9
callq 0x137ad
movq %r12, %rdi
callq 0x3060
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebx, %eax
movb $0x0, (%r12,%rax)
movq 0x18(%rsp), %rsi
movq %r12, %rdi
callq 0x3ff8
xorl %ebx, %ebx
jmp 0x1375f
movq %r12, %rdi
movq 0x18(%rsp), %rsi
callq 0x4073
jmp 0x13785
movq 0x30(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x4036
jmp 0x13785
xorl %eax, %eax
jmp 0x13773