// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movl $0x1, %edi
movl $0x20, %esi
callq 0x194a0
movq %rax, 0x20(%rsp)
callq 0x36f750
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x18(%rax)
movq $0x0, 0x48(%rsp)
movl $0x0, 0x40(%rsp)
movl $0x0, 0x44(%rsp)
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x38(%rsp) # imm = 0xFFFFFFFF
movq $-0x1, 0x10(%rsp)
movl $0x0, 0x30(%rsp)
movl $0xffffffff, 0x28(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x2c(%rsp) # imm = 0xFFFFFFFF
movq $0x0, 0x18(%rsp)
movq 0x58(%rsp), %rdi
leaq 0x57(%rsp), %rsi
movl $0x1, %edx
callq 0x4fc520
cmpl $0x0, %eax
je 0x36e57d
movsbl 0x57(%rsp), %eax
cmpl $0xa, %eax
jne 0x36e1eb
cmpl $0x1, 0x30(%rsp)
jne 0x36e1cf
movq 0x58(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x36e191
cmpl $0x0, 0x30(%rsp)
jne 0x36e1de
cmpq $0x0, 0x10(%rsp)
jl 0x36e1e5
cmpl $0x2, 0x30(%rsp)
jne 0x36e1e7
jmp 0x36e191
jmp 0x36e1e9
jmp 0x36e1eb
movsbl 0x57(%rsp), %eax
cmpl $0x3e, %eax
jne 0x36e3f0
cmpq $0x0, 0x10(%rsp)
jl 0x36e225
movq 0x20(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x10(%rsp), %rax
movl %eax, %edx
movl 0x38(%rsp), %ecx
movl 0x34(%rsp), %r8d
movq 0x18(%rsp), %r9
callq 0x36e5c0
movl $0x0, 0x44(%rsp)
movq 0x58(%rsp), %rdi
leaq 0x57(%rsp), %rsi
movl $0x1, %edx
callq 0x4fc520
movl %eax, %ecx
movl %ecx, 0x3c(%rsp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0xf(%rsp)
je 0x36e277
callq 0x197c0
movq (%rax), %rax
movsbl 0x57(%rsp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x36e284
jmp 0x36e333
movl 0x40(%rsp), %eax
movl 0x44(%rsp), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jge 0x36e312
movl 0x44(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x40(%rsp)
movl 0x40(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x40(%rsp)
movl 0x40(%rsp), %eax
sarl %eax
orl 0x40(%rsp), %eax
movl %eax, 0x40(%rsp)
movl 0x40(%rsp), %eax
sarl $0x2, %eax
orl 0x40(%rsp), %eax
movl %eax, 0x40(%rsp)
movl 0x40(%rsp), %eax
sarl $0x4, %eax
orl 0x40(%rsp), %eax
movl %eax, 0x40(%rsp)
movl 0x40(%rsp), %eax
sarl $0x8, %eax
orl 0x40(%rsp), %eax
movl %eax, 0x40(%rsp)
movl 0x40(%rsp), %eax
sarl $0x10, %eax
orl 0x40(%rsp), %eax
movl %eax, 0x40(%rsp)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
movq 0x48(%rsp), %rdi
movslq 0x40(%rsp), %rsi
callq 0x19f00
movq %rax, 0x48(%rsp)
movb 0x57(%rsp), %dl
movq 0x48(%rsp), %rax
movl 0x44(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x44(%rsp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x36e22d
movq 0x48(%rsp), %rax
movslq 0x44(%rsp), %rcx
movb $0x0, (%rax,%rcx)
cmpl $0x0, 0x3c(%rsp)
jne 0x36e382
movq 0x2cdc51(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x22f991(%rip), %rsi    # 0x59dcea
movb $0x0, %al
callq 0x199f0
movq 0x48(%rsp), %rdi
callq 0x19ef0
movq 0x20(%rsp), %rdi
callq 0x36e710
movq $0x0, 0x60(%rsp)
jmp 0x36e5b5
movsbl 0x57(%rsp), %eax
cmpl $0xa, %eax
je 0x36e3cc
jmp 0x36e38e
movq 0x58(%rsp), %rdi
leaq 0x57(%rsp), %rsi
movl $0x1, %edx
callq 0x4fc520
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0xe(%rsp)
je 0x36e3be
movsbl 0x57(%rsp), %eax
cmpl $0xa, %eax
setne %al
movb %al, 0xe(%rsp)
movb 0xe(%rsp), %al
testb $0x1, %al
jne 0x36e3c8
jmp 0x36e3ca
jmp 0x36e38e
jmp 0x36e3cc
movl $0x1, 0x30(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x58(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x36e578
cmpl $0x3, 0x30(%rsp)
jne 0x36e436
movq 0x2cdba2(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
movq 0x48(%rsp), %rdx
leaq 0x22f90e(%rip), %rsi    # 0x59dd1b
movb $0x0, %al
callq 0x199f0
movq 0x48(%rsp), %rdi
callq 0x19ef0
movq 0x20(%rsp), %rdi
callq 0x36e710
movq $0x0, 0x60(%rsp)
jmp 0x36e5b5
cmpl $0x2, 0x30(%rsp)
jne 0x36e445
movl $0x3, 0x30(%rsp)
movl $0x0, 0x28(%rsp)
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
callq 0x197c0
movq (%rax), %rax
movsbl 0x57(%rsp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x36e489
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x36e48b
movq 0x58(%rsp), %rdi
leaq 0x57(%rsp), %rsi
movl $0x1, %edx
callq 0x4fc520
movl %eax, %ecx
movl %ecx, 0x3c(%rsp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0xd(%rsp)
je 0x36e4bf
movsbl 0x57(%rsp), %eax
cmpl $0xa, %eax
setne %al
movb %al, 0xd(%rsp)
movb 0xd(%rsp), %al
testb $0x1, %al
jne 0x36e455
cmpl $0x3, 0x30(%rsp)
jne 0x36e514
cmpl $0x0, 0x28(%rsp)
je 0x36e514
movq 0x2cdac4(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
movq 0x48(%rsp), %rdx
leaq 0x22f876(%rip), %rsi    # 0x59dd61
movb $0x0, %al
callq 0x199f0
movq 0x48(%rsp), %rdi
callq 0x19ef0
movq 0x20(%rsp), %rdi
callq 0x36e710
movq $0x0, 0x60(%rsp)
jmp 0x36e5b5
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
movslq 0x28(%rsp), %rax
addq 0x10(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpl $0x1, 0x30(%rsp)
jne 0x36e54f
movl 0x2c(%rsp), %eax
movl %eax, 0x38(%rsp)
movl 0x28(%rsp), %eax
movl %eax, 0x34(%rsp)
movl $0x0, 0x30(%rsp)
jmp 0x36e576
cmpl $0x0, 0x30(%rsp)
jne 0x36e574
movl 0x2c(%rsp), %eax
cmpl 0x38(%rsp), %eax
jne 0x36e56a
movl 0x28(%rsp), %eax
cmpl 0x34(%rsp), %eax
je 0x36e572
movl $0x2, 0x30(%rsp)
jmp 0x36e574
jmp 0x36e576
jmp 0x36e578
jmp 0x36e191
movq 0x20(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x10(%rsp), %rax
movl %eax, %edx
movl 0x38(%rsp), %ecx
movl 0x34(%rsp), %r8d
movq 0x18(%rsp), %r9
callq 0x36e5c0
movq 0x48(%rsp), %rdi
callq 0x19ef0
movq 0x20(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
addq $0x68, %rsp
retq
nop