// File: /workspace/github_c_makefile_star2_O2/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, 0x18(%rsp)
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0x6470
movq %rax, %rbx
callq 0x5e39c
movq %rbx, 0x10(%rsp)
movq %rax, 0x18(%rbx)
pushq $-0x1
popq %rax
movq %rax, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
pushq $-0x1
popq %rax
xorl %r13d, %r13d
movl %eax, 0xc(%rsp)
movl %eax, 0x8(%rsp)
xorl %eax, %eax
movq $0x0, 0x20(%rsp)
movq 0x28(%rsp), %r15
movq 0x30(%rsp), %r14
movl %eax, %r12d
testq %r14, %r14
sets %al
testl %r12d, %r12d
sete %cl
andb %al, %cl
cmpl $0x2, %r12d
sete %bpl
orb %cl, %bpl
movq 0x18(%rsp), %rdi
callq 0x5d480
testl %eax, %eax
js 0x5e2f2
movl %eax, %ebx
cmpl $0xa, %eax
jne 0x5e0e8
cmpl $0x1, %r12d
je 0x5e0d4
testb %bpl, %bpl
jne 0x5e0a3
pushq $0x2
popq %rax
testl %r12d, %r12d
je 0x5e087
jmp 0x5e1bf
movq 0x18(%rsp), %rdi
callq 0x5dc88
movq %rax, 0x20(%rsp)
pushq $0x1
popq %rax
jmp 0x5e087
cmpl $0x3e, %ebx
jne 0x5e1bf
testq %r14, %r14
js 0x5e114
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movl %r14d, %edx
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %r8d
movq 0x20(%rsp), %r9
callq 0x5e3a7
xorl %r12d, %r12d
movq %r12, %r14
incq %r12
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, %rbx
shrq $0x10, %rbx
orq %rcx, %rbx
incq %rbx
movq 0x18(%rsp), %rdi
callq 0x5d480
movl %eax, %ebp
testl %eax, %eax
js 0x5e1aa
callq 0x6790
movq (%rax), %rax
movl %ebp, %ecx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x5e196
cmpq %r13, %r12
jbe 0x5e190
movq %r15, %rdi
movq %rbx, %rsi
callq 0x6c80
movq %rbx, %r13
testq %rax, %rax
je 0x5e151
movq %rax, %r15
movq %rbx, %r13
movb %bpl, (%r15,%r14)
jmp 0x5e117
testq %r14, %r14
jne 0x5e1aa
movl $0x0, %r12d
cmpl $0xa, %ebp
jne 0x5e117
leaq 0x1(%r14), %rax
cmpq %r13, %rax
jae 0x5e261
movq %r15, %rax
jmp 0x5e2a5
cmpl $0x3, %r12d
je 0x5e322
xorl %r14d, %r14d
callq 0x6790
movq %rax, %rbp
pushq $0x1
popq %r15
movl %r14d, %eax
movq (%rbp), %rcx
movl %ebx, %edx
movzwl (%rcx,%rdx,2), %r14d
shrl $0xf, %r14d
addl %eax, %r14d
movq 0x18(%rsp), %rdi
callq 0x5d480
incl %r15d
testl %eax, %eax
js 0x5e205
movl %eax, %ebx
cmpl $0xa, %eax
jne 0x5e1d8
cmpl $0x2, %r12d
movl %r12d, %eax
pushq $0x3
popq %rcx
cmovel %ecx, %eax
cmpl $0x3, %eax
jne 0x5e220
testl %r14d, %r14d
jne 0x5e335
movl %r14d, %ecx
addq %rcx, 0x30(%rsp)
testl %r12d, %r12d
je 0x5e248
cmpl $0x1, %r12d
jne 0x5e07d
xorl %eax, %eax
movl %r15d, 0xc(%rsp)
movl %r14d, 0x8(%rsp)
jmp 0x5e07d
xorl 0xc(%rsp), %r15d
xorl 0x8(%rsp), %r14d
xorl %eax, %eax
orl %r15d, %r14d
setne %al
addl %eax, %eax
jmp 0x5e07d
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, %r13
shrq $0x10, %r13
orq %rax, %r13
incq %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x6c80
testq %rax, %rax
je 0x5e2ad
movb $0x0, (%rax,%r14)
movq %rax, %r15
testl %ebp, %ebp
js 0x5e357
movq %r15, 0x28(%rsp)
cmpl $0xa, %ebp
je 0x5e2d2
movq 0x18(%rsp), %rdi
callq 0x5d480
testl %eax, %eax
js 0x5e2d2
cmpl $0xa, %eax
jne 0x5e2bf
movq 0x18(%rsp), %rdi
callq 0x5dc88
movq %rax, 0x20(%rsp)
pushq $0x1
popq %rax
movq $0x0, 0x30(%rsp)
jmp 0x5e07d
testq %r14, %r14
js 0x5e373
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %r8d
movq 0x20(%rsp), %r9
callq 0x5e3a7
movq %r15, %rdi
callq 0x68a0
jmp 0x5e38a
movq 0x54caf(%rip), %rax     # 0xb2fd8
movq (%rax), %rdi
leaq 0x2a91e(%rip), %rsi     # 0x88c51
jmp 0x5e34b
movq 0x54c9c(%rip), %rax     # 0xb2fd8
movq (%rax), %rdi
leaq 0x2a951(%rip), %rsi     # 0x88c97
movq 0x28(%rsp), %r15
movq %r15, %rdx
xorl %eax, %eax
callq 0x6a90
jmp 0x5e373
movq 0x54c7a(%rip), %rax     # 0xb2fd8
movq (%rax), %rcx
leaq 0x2a8b8(%rip), %rdi     # 0x88c20
pushq $0x30
popq %rsi
pushq $0x1
popq %rdx
callq 0x6e70
movq 0x10(%rsp), %rbx
movq %r15, %rdi
callq 0x68a0
movq %rbx, %rdi
callq 0x5e65b
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq