// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/htslib/faidx.c
// Function: fai_build_core
faidx_t *fai_build_core(BGZF *bgzf)
{
    kstring_t name = { 0, 0, NULL };
    int c;
    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);
    len = line_len = line_blen = -1; state = 0; l1 = l2 = -1; offset = 0;
    while ( (c=bgzf_getc(bgzf))>=0 ) {
        if (c == '\n') { // an empty line
            if (state == 1) {
                offset = bgzf_utell(bgzf);
                continue;
            } else if ((state == 0 && len < 0) || state == 2) continue;
            else if (state == 0) { state = 2; continue; }
        }
        if (c == '>') { // fasta header
            if (len >= 0)
                fai_insert_index(idx, name.s, len, line_len, line_blen, offset);

            name.l = 0;
            while ((c = bgzf_getc(bgzf)) >= 0)
                if (! isspace(c)) kputc_(c, &name);
                else if (name.l > 0 || c == '\n') break;
            kputsn("", 0, &name);

            if ( c<0 ) {
                fprintf(stderr, "[fai_build_core] the last entry has no sequence\n");
                goto fail;
            }
            if (c != '\n') while ( (c=bgzf_getc(bgzf))>=0 && c != '\n');
            state = 1; len = 0;
            offset = bgzf_utell(bgzf);
        } else {
            if (state == 3) {
                fprintf(stderr, "[fai_build_core] inlined empty line is not allowed in sequence '%s'.\n", name.s);
                goto fail;
            }
            if (state == 2) state = 3;
            l1 = l2 = 0;
            do {
                ++l1;
                if (isgraph(c)) ++l2;
            } while ( (c=bgzf_getc(bgzf))>=0 && c != '\n');
            if (state == 3 && l2) {
                fprintf(stderr, "[fai_build_core] different line length in sequence '%s'.\n", name.s);
                goto fail;
            }
            ++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;
            }
        }
    }

    if (len >= 0)
        fai_insert_index(idx, name.s, len, line_len, line_blen, offset);
    else
        goto fail;

    free(name.s);
    return idx;

fail:
    free(name.s);
    fai_destroy(idx);
    return NULL;
}

// 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 0x6470
movq %rax, %rbx
movl $0x1, %edi
movl $0x28, %esi
callq 0x6470
movq %rbx, 0x10(%rsp)
movq %rax, 0x18(%rbx)
movq $-0x1, %r12
movq $0x0, 0x28(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movq $0x0, 0x20(%rsp)
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
xorl %eax, %eax
movq $0x0, 0x18(%rsp)
movq 0x28(%rsp), %r13
movl %eax, %r14d
testq %r12, %r12
sets %al
testl %r14d, %r14d
sete %cl
andb %al, %cl
cmpl $0x2, %r14d
sete %bpl
orb %cl, %bpl
movq %r15, %rdi
callq 0x68744
testl %eax, %eax
js 0x696bc
movl %eax, %ebx
cmpl $0xa, %eax
jne 0x6948d
cmpl $0x1, %r14d
je 0x69479
testb %bpl, %bpl
jne 0x69448
movl $0x2, %eax
testl %r14d, %r14d
je 0x6942c
jmp 0x69573
movq %r15, %rdi
callq 0x68ffc
movq %rax, 0x18(%rsp)
movl $0x1, %eax
jmp 0x6942c
cmpl $0x3e, %ebx
jne 0x69573
testq %r12, %r12
js 0x694b9
movq 0x10(%rsp), %rdi
movq %r13, %rsi
movl %r12d, %edx
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %r8d
movq 0x18(%rsp), %r9
callq 0x6974f
movq %r15, %rdi
callq 0x68744
movl %eax, %ebp
testl %eax, %eax
js 0x6961b
callq 0x6790
movq %rax, %r12
xorl %r14d, %r14d
movq (%r12), %rax
movl %ebp, %ecx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x69539
leaq 0x1(%r14), %rbx
cmpq 0x20(%rsp), %rbx
jbe 0x6954f
movq %r14, %rax
shrq %rax
orq %r14, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %r13, %rdi
movq %rsi, 0x20(%rsp)
callq 0x6c80
testq %rax, %rax
jne 0x69552
movq %r14, %rbx
jmp 0x69559
testq %r14, %r14
jne 0x6961f
cmpl $0xa, %ebp
je 0x6961f
xorl %ebx, %ebx
jmp 0x69559
movq %r13, %rax
movb %bpl, (%rax,%r14)
movq %rax, %r13
movq %r15, %rdi
callq 0x68744
movl %eax, %ebp
movq %rbx, %r14
testl %eax, %eax
jns 0x694d6
jmp 0x69622
cmpl $0x3, %r14d
je 0x696ec
movq %r12, 0x30(%rsp)
xorl %r13d, %r13d
movl $0x1, %ebp
callq 0x6790
movq %rax, %r12
movl %r13d, %eax
movq (%r12), %rcx
movl %ebx, %edx
movzwl (%rcx,%rdx,2), %r13d
shrl $0xf, %r13d
addl %eax, %r13d
movq %r15, %rdi
callq 0x68744
incl %ebp
testl %eax, %eax
js 0x695bc
movl %eax, %ebx
cmpl $0xa, %eax
jne 0x69592
cmpl $0x2, %r14d
movl %r14d, %eax
movl $0x3, %ecx
cmovel %ecx, %eax
cmpl $0x3, %eax
jne 0x695d9
testl %r13d, %r13d
jne 0x696ff
movl %r13d, %ecx
movq 0x30(%rsp), %r12
addq %rcx, %r12
testl %r14d, %r14d
je 0x69603
cmpl $0x1, %r14d
jne 0x69427
xorl %eax, %eax
movl %ebp, 0xc(%rsp)
movl %r13d, 0x8(%rsp)
jmp 0x69427
xorl 0xc(%rsp), %ebp
xorl 0x8(%rsp), %r13d
xorl %eax, %eax
orl %ebp, %r13d
setne %al
addl %eax, %eax
jmp 0x69427
xorl %ebx, %ebx
jmp 0x69622
movq %r14, %rbx
leaq 0x1(%rbx), %rax
cmpq 0x20(%rsp), %rax
jae 0x69632
movq %r13, %rax
jmp 0x69678
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %r13, %rdi
movq %rsi, 0x20(%rsp)
callq 0x6c80
testq %rax, %rax
je 0x6967f
movb $0x0, (%rax,%rbx)
movq %rax, %r13
testl %ebp, %ebp
js 0x69721
movq %r13, 0x28(%rsp)
cmpl $0xa, %ebp
je 0x696a2
movq %r15, %rdi
callq 0x68744
testl %eax, %eax
js 0x696a2
cmpl $0xa, %eax
jne 0x69691
movq %r15, %rdi
callq 0x68ffc
movq %rax, 0x18(%rsp)
movl $0x1, %eax
xorl %r12d, %r12d
jmp 0x69427
testq %r12, %r12
js 0x69726
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movl %r12d, %edx
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %r8d
movq 0x18(%rsp), %r9
callq 0x6974f
movq %r13, %rdi
callq 0x68a0
jmp 0x6973d
movq 0x558e5(%rip), %rax     # 0xbefd8
movq (%rax), %rdi
leaq 0x307d4(%rip), %rsi     # 0x99ed1
jmp 0x69715
movq 0x558d2(%rip), %rax     # 0xbefd8
movq (%rax), %rdi
leaq 0x30807(%rip), %rsi     # 0x99f17
movq 0x28(%rsp), %r13
movq %r13, %rdx
xorl %eax, %eax
callq 0x6a90
jmp 0x69726
callq 0x7b7e
movq 0x10(%rsp), %rbx
movq %r13, %rdi
callq 0x68a0
movq %rbx, %rdi
callq 0x69a2d
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq