// File: /workspace/github_c_makefile_star2_O3/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, 0x30(%rsp)
movl $0x1, %edi
movl $0x20, %esi
callq 0x32e0
movq %rax, %rbx
movl $0x1, %edi
movl $0x28, %esi
callq 0x32e0
movq %rbx, 0x10(%rsp)
movq %rax, 0x18(%rbx)
movq $-0x1, %rcx
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
xorl %ebp, %ebp
xorl %r15d, %r15d
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
xorl %eax, %eax
movq $0x0, 0x20(%rsp)
movq %r15, 0x18(%rsp)
movl %eax, %r12d
movq 0x30(%rsp), %r14
leaq 0x7(%rsp), %r13
movq %rcx, 0x28(%rsp)
testq %rcx, %rcx
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 0x131e9
testl %eax, %eax
je 0x13d87
movzbl 0x7(%rsp), %r15d
cmpl $0xa, %r15d
jne 0x13bc4
cmpl $0x1, %r12d
je 0x13bae
testb %bl, %bl
jne 0x13b7e
jmp 0x13bce
movq 0x28(%r14), %rax
movq %rax, 0x20(%rsp)
movl $0x1, %r12d
movq 0x28(%rsp), %rcx
jmp 0x13b67
cmpl $0x3e, %r15d
je 0x13c82
cmpl $0x3, %r12d
je 0x13ddc
xorl %r13d, %r13d
movl $0x1, %r14d
callq 0x35f0
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 0x7(%rsp), %rsi
movl $0x1, %edx
callq 0x131e9
incl %r14d
testl %eax, %eax
je 0x13c25
movb 0x7(%rsp), %r15b
cmpb $0xa, %r15b
jne 0x13be9
cmpl $0x2, %r12d
movl %r12d, %eax
movl $0x3, %ecx
cmovel %ecx, %eax
cmpl $0x3, %eax
jne 0x13c42
testl %r13d, %r13d
jne 0x13ded
movl %r13d, %ecx
movq 0x28(%rsp), %rdx
addq %rcx, %rdx
movq %rdx, %rcx
testl %r12d, %r12d
movq 0x18(%rsp), %r15
je 0x13c69
cmpl $0x1, %r12d
jne 0x13b55
jmp 0x13d76
xorl 0xc(%rsp), %r14d
xorl 0x8(%rsp), %r13d
xorl %eax, %eax
orl %r14d, %r13d
setne %al
addl %eax, %eax
jmp 0x13b55
movq 0x28(%rsp), %rdx
testq %rdx, %rdx
movq 0x18(%rsp), %r15
js 0x13cac
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %r8d
movq 0x20(%rsp), %r9
callq 0x13e02
movq %r14, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x131e9
testl %eax, %eax
je 0x13dfe
callq 0x35f0
movq %rax, %r12
xorl %ebx, %ebx
movq (%r12), %rcx
movsbq 0x7(%rsp), %rax
testb $0x20, 0x1(%rcx,%rax,2)
jne 0x13d3f
leal 0x2(%rbx), %ecx
cmpl %ecx, %ebp
jge 0x13d1f
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 0x3430
movq %rax, %r15
movb 0x7(%rsp), %al
movb %al, (%r15,%rbx)
movq %r14, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x131e9
incq %rbx
testl %eax, %eax
jne 0x13cce
jmp 0x13dc9
movl %ebx, %eax
movb $0x0, (%r15,%rax)
cmpb $0xa, 0x7(%rsp)
je 0x13d61
movq %r14, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x131e9
testl %eax, %eax
jne 0x13d46
movq 0x28(%r14), %rax
movq %rax, 0x20(%rsp)
movl $0x1, %eax
xorl %ecx, %ecx
jmp 0x13b50
xorl %eax, %eax
movl %r14d, 0xc(%rsp)
movl %r13d, 0x8(%rsp)
jmp 0x13b50
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq 0x18(%rsp), %r14
movq %r14, %rsi
movq 0x28(%rsp), %rdx
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %r8d
movq 0x20(%rsp), %r9
callq 0x13e02
movq %r14, %rdi
callq 0x3060
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 0x10(%rsp), %rdx
callq 0x42d3
xorl %ebx, %ebx
jmp 0x13db7
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x4352
jmp 0x13dd8
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x4315
jmp 0x13dd8
xorl %esi, %esi
jmp 0x13dcb