// File: /workspace/github_c_makefile_star2_O1/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 0x6865b
testl %eax, %eax
js 0x695f6
movl %eax, %ebx
cmpl $0xa, %eax
jne 0x693d2
cmpl $0x1, %r14d
je 0x693be
testb %bpl, %bpl
jne 0x69390
movl $0x2, %eax
testl %r14d, %r14d
je 0x69374
jmp 0x693d2
movq %r15, %rdi
callq 0x68efe
movq %rax, 0x18(%rsp)
movl $0x1, %eax
jmp 0x69374
cmpl $0x3e, %ebx
je 0x69470
cmpl $0x3, %r14d
je 0x69626
movq %r12, 0x30(%rsp)
xorl %r13d, %r13d
movl $0x1, %ebp
callq 0x6790
movq %rax, %r12
movl %r13d, %eax
movq (%r12), %rcx
movslq %ebx, %rdx
movzwl (%rcx,%rdx,2), %r13d
shrl $0xf, %r13d
addl %eax, %r13d
movq %r15, %rdi
callq 0x6865b
incl %ebp
testl %eax, %eax
js 0x69425
movl %eax, %ebx
cmpl $0xa, %eax
jne 0x693fa
cmpl $0x2, %r14d
movl %r14d, %eax
movl $0x3, %ecx
cmovel %ecx, %eax
cmpl $0x3, %eax
jne 0x69442
testl %r13d, %r13d
jne 0x69639
movl %r13d, %ecx
movq 0x30(%rsp), %r12
addq %rcx, %r12
testl %r14d, %r14d
je 0x69542
cmpl $0x1, %r14d
jne 0x6936f
xorl %eax, %eax
movl %ebp, 0xc(%rsp)
movl %r13d, 0x8(%rsp)
jmp 0x6936f
testq %r12, %r12
js 0x69493
movq 0x10(%rsp), %rdi
movq %r13, %rsi
movl %r12d, %edx
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %r8d
movq 0x18(%rsp), %r9
callq 0x69689
movq %r15, %rdi
callq 0x6865b
movl %eax, %ebp
testl %eax, %eax
js 0x6955a
callq 0x6790
movq %rax, %r12
xorl %ebx, %ebx
movq (%r12), %rax
movl %ebp, %ecx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x69512
leaq 0x1(%rbx), %r14
cmpq 0x20(%rsp), %r14
jbe 0x69521
movq %rbx, %rax
shrq %rax
orq %rbx, %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 0x69524
movq %rbx, %r14
jmp 0x6952b
testq %rbx, %rbx
jne 0x6955c
movq %rbx, %r14
cmpl $0xa, %ebp
jne 0x6952b
jmp 0x6955c
movq %r13, %rax
movb %bpl, (%rax,%rbx)
movq %rax, %r13
movq %r15, %rdi
callq 0x6865b
movl %eax, %ebp
movq %r14, %rbx
testl %eax, %eax
jns 0x694af
jmp 0x6955c
xorl 0xc(%rsp), %ebp
xorl 0x8(%rsp), %r13d
xorl %eax, %eax
orl %ebp, %r13d
setne %al
addl %eax, %eax
jmp 0x6936f
xorl %ebx, %ebx
leaq 0x1(%rbx), %rax
cmpq 0x20(%rsp), %rax
jae 0x6956c
movq %r13, %rax
jmp 0x695b2
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 0x695b9
movb $0x0, (%rax,%rbx)
movq %rax, %r13
testl %ebp, %ebp
js 0x6965b
movq %r13, 0x28(%rsp)
cmpl $0xa, %ebp
je 0x695dc
movq %r15, %rdi
callq 0x6865b
testl %eax, %eax
js 0x695dc
cmpl $0xa, %eax
jne 0x695cb
movq %r15, %rdi
callq 0x68efe
movq %rax, 0x18(%rsp)
movl $0x1, %eax
xorl %r12d, %r12d
jmp 0x6936f
testq %r12, %r12
js 0x69660
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 0x69689
movq %r13, %rdi
callq 0x68a0
jmp 0x69677
movq 0x559ab(%rip), %rax     # 0xbefd8
movq (%rax), %rdi
leaq 0x3066a(%rip), %rsi     # 0x99ca1
jmp 0x6964f
movq 0x55998(%rip), %rax     # 0xbefd8
movq (%rax), %rdi
leaq 0x3069d(%rip), %rsi     # 0x99ce7
movq 0x28(%rsp), %r13
movq %r13, %rdx
xorl %eax, %eax
callq 0x6a90
jmp 0x69660
callq 0x7bd2
movq 0x10(%rsp), %rbx
movq %r13, %rdi
callq 0x68a0
movq %rbx, %rdi
callq 0x69954
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq