// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/samtools-0.1.18/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)
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0x174c0
movq %rax, %rbx
callq 0x1fa22c
movq %rbx, 0x10(%rsp)
movq %rax, 0x18(%rbx)
pushq $-0x1
popq %rcx
pushq $-0x1
popq %rax
xorl %ebp, %ebp
movq $0x0, 0x18(%rsp)
movl %eax, 0xc(%rsp)
movl %eax, 0x8(%rsp)
xorl %eax, %eax
movq $0x0, 0x20(%rsp)
movl %eax, %r13d
movq 0x30(%rsp), %r12
movq %rcx, 0x28(%rsp)
testq %rcx, %rcx
sets %al
testl %r13d, %r13d
sete %cl
andb %al, %cl
cmpl $0x2, %r13d
sete %bl
orb %cl, %bl
movq %r12, %rdi
leaq 0x7(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x2d8a3a
testl %eax, %eax
je 0x1f9273
movzbl 0x7(%rsp), %r15d
cmpl $0xa, %r15d
jne 0x1f90d3
cmpl $0x1, %r13d
je 0x1f90be
testb %bl, %bl
jne 0x1f908b
jmp 0x1f9183
movq 0x28(%r12), %rax
movq %rax, 0x20(%rsp)
pushq $0x1
popq %r13
movq 0x28(%rsp), %rcx
jmp 0x1f9074
cmpl $0x3e, %r15d
jne 0x1f9183
movq 0x28(%rsp), %rdx
testq %rdx, %rdx
movq 0x18(%rsp), %r14
js 0x1f9107
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %r8d
movq 0x20(%rsp), %r9
callq 0x1f9326
xorl %ebx, %ebx
movq %r12, %rdi
leaq 0x7(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x2d8a3a
testl %eax, %eax
je 0x1f92b5
callq 0x17820
movq (%rax), %rcx
movsbq 0x7(%rsp), %rax
testb $0x20, 0x1(%rcx,%rax,2)
jne 0x1f9238
leal 0x2(%rbx), %ecx
cmpl %ecx, %ebp
jge 0x1f917a
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 %r14, %rdi
callq 0x17f58
movq %rax, %r14
movb 0x7(%rsp), %al
movb %al, (%r14,%rbx)
incq %rbx
jmp 0x1f9109
cmpl $0x3, %r13d
je 0x1f92ee
xorl %r12d, %r12d
callq 0x17820
movq %rax, %rbx
pushq $0x1
popq %r14
movl %r12d, %eax
movq (%rbx), %rcx
movsbq %r15b, %rdx
movzwl (%rcx,%rdx,2), %r12d
shrl $0xf, %r12d
addl %eax, %r12d
movq 0x30(%rsp), %rdi
leaq 0x7(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x2d8a3a
incl %r14d
testl %eax, %eax
je 0x1f91d6
movb 0x7(%rsp), %r15b
cmpb $0xa, %r15b
jne 0x1f919c
cmpl $0x2, %r13d
movl %r13d, %eax
pushq $0x3
popq %rcx
cmovel %ecx, %eax
cmpl $0x3, %eax
jne 0x1f91f1
testl %r12d, %r12d
jne 0x1f9301
movl %r12d, %ecx
movq 0x28(%rsp), %rdx
addq %rcx, %rdx
movq %rdx, %rcx
testl %r13d, %r13d
je 0x1f921f
cmpl $0x1, %r13d
jne 0x1f9067
xorl %eax, %eax
movl %r14d, 0xc(%rsp)
movl %r12d, 0x8(%rsp)
jmp 0x1f9067
xorl 0xc(%rsp), %r14d
xorl 0x8(%rsp), %r12d
xorl %eax, %eax
orl %r14d, %r12d
setne %al
addl %eax, %eax
jmp 0x1f9067
movl %ebx, %eax
movq %r14, 0x18(%rsp)
movb $0x0, (%r14,%rax)
cmpb $0xa, 0x7(%rsp)
je 0x1f925f
movq %r12, %rdi
leaq 0x7(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x2d8a3a
testl %eax, %eax
jne 0x1f9244
movq 0x28(%r12), %rax
movq %rax, 0x20(%rsp)
pushq $0x1
popq %rax
xorl %ecx, %ecx
jmp 0x1f9067
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 0x1f9326
movq %r14, %rdi
callq 0x17f48
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebx, %eax
movb $0x0, (%r14,%rax)
movq 0x23eca5(%rip), %rax    # 0x437f68
movq (%rax), %rcx
leaq 0x1719e9(%rip), %rdi    # 0x36acb6
pushq $0x30
popq %rsi
pushq $0x1
popq %rdx
callq 0x17f00
movq %r14, %rdi
callq 0x17f48
movq 0x10(%rsp), %rdi
callq 0x1f97ed
xorl %ebx, %ebx
jmp 0x1f92a3
movq 0x23ec73(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1719e8(%rip), %rsi    # 0x36ace7
jmp 0x1f9312
movq 0x23ec60(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x171a1b(%rip), %rsi    # 0x36ad2d
movq 0x18(%rsp), %rbx
movq %rbx, %rdx
xorl %eax, %eax
callq 0x17a50
movq %rbx, %rdi
jmp 0x1f92db