// File: /workspace/github_cpp_makefile_star2_O1/karel-brinda[P]ococo/ext/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) {
                if (fai_insert_index(idx, name.s, len, line_len, line_blen, offset) != 0)
                    goto fail;
            }

            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) {
        if (fai_insert_index(idx, name.s, len, line_len, line_blen, offset) != 0)
            goto fail;
    } 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 0x4360
movq %rax, %rbx
movl $0x1, %edi
movl $0x28, %esi
callq 0x4360
movq %rbx, 0x18(%rsp)
movq %rax, 0x18(%rbx)
movq $-0x1, 0x30(%rsp)
movq $0x0, 0x8(%rsp)
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
movq $0x0, 0x20(%rsp)
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
xorl %eax, %eax
movq $0x0, 0x28(%rsp)
movq 0x30(%rsp), %r13
movl %eax, %ebp
testq %r13, %r13
sets %al
testl %ebp, %ebp
sete %cl
andb %al, %cl
cmpl $0x2, %ebp
sete %bl
orb %cl, %bl
movq %r15, %rdi
callq 0x456b0
testl %eax, %eax
js 0x4665c
movl %eax, %r12d
cmpl $0xa, %eax
jne 0x463fd
cmpl $0x1, %ebp
je 0x463e9
testb %bl, %bl
jne 0x463bd
movl $0x2, %eax
testl %ebp, %ebp
je 0x463a6
jmp 0x463fd
movq %r15, %rdi
callq 0x45ee6
movq %rax, 0x28(%rsp)
movl $0x1, %eax
jmp 0x463a6
cmpl $0x3e, %r12d
movq 0x20(%rsp), %rbx
je 0x46497
cmpl $0x3, %ebp
je 0x46695
xorl %r13d, %r13d
movl $0x1, %r14d
callq 0x4580
movq %rax, %rbx
movl %r13d, %eax
movq (%rbx), %rcx
movslq %r12d, %rdx
movzwl (%rcx,%rdx,2), %r13d
shrl $0xf, %r13d
addl %eax, %r13d
movq %r15, %rdi
callq 0x456b0
incl %r14d
testl %eax, %eax
js 0x46452
movl %eax, %r12d
cmpl $0xa, %eax
jne 0x46426
cmpl $0x2, %ebp
movl %ebp, %eax
movl $0x3, %ecx
cmovel %ecx, %eax
cmpl $0x3, %eax
jne 0x4646d
testl %r13d, %r13d
jne 0x466a8
movl %r13d, %ecx
addq %rcx, 0x30(%rsp)
testl %ebp, %ebp
je 0x4658a
cmpl $0x1, %ebp
jne 0x463a1
xorl %eax, %eax
movl %r14d, 0x14(%rsp)
movl %r13d, 0x10(%rsp)
jmp 0x463a1
testq %r13, %r13
js 0x464c4
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rdx
movl 0x14(%rsp), %ecx
movl 0x10(%rsp), %r8d
movq 0x28(%rsp), %r9
callq 0x46702
testl %eax, %eax
jne 0x466d4
movq %r15, %rdi
callq 0x456b0
movl %eax, %ebp
testl %eax, %eax
js 0x465a3
callq 0x4580
movq %rax, %r13
xorl %r14d, %r14d
movq (%r13), %rax
movl %ebp, %ecx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x46556
leaq 0x1(%r14), %r12
cmpq %r12, %rbx
jae 0x46565
movq %rbx, 0x20(%rsp)
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, %rax
shrq $0x10, %rax
orq %rcx, %rax
movq %rax, %rbx
shrq $0x20, %rbx
orq %rax, %rbx
incq %rbx
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x48d0
testq %rax, %rax
jne 0x4656a
movq %r14, %r12
movq 0x20(%rsp), %rbx
jmp 0x46573
testq %r14, %r14
jne 0x465a6
movq %r14, %r12
cmpl $0xa, %ebp
jne 0x46573
jmp 0x465a6
movq 0x8(%rsp), %rax
movb %bpl, (%rax,%r14)
movq %rax, 0x8(%rsp)
movq %r15, %rdi
callq 0x456b0
movl %eax, %ebp
movq %r12, %r14
testl %eax, %eax
jns 0x464e1
jmp 0x465a6
xorl 0x14(%rsp), %r14d
xorl 0x10(%rsp), %r13d
xorl %eax, %eax
orl %r14d, %r13d
setne %al
addl %eax, %eax
jmp 0x463a1
xorl %r14d, %r14d
leaq 0x2(%r14), %rax
cmpq %rax, %rbx
jae 0x4660a
movq %rbx, 0x20(%rsp)
leaq 0x1(%r14), %rax
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, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %rbx
shrq $0x20, %rbx
orq %rcx, %rbx
incq %rbx
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x48d0
testq %rax, %rax
jne 0x4660f
jmp 0x4661e
movq 0x8(%rsp), %rax
movb $0x0, (%rax,%r14)
movq %rbx, 0x20(%rsp)
movq %rax, 0x8(%rsp)
testl %ebp, %ebp
js 0x466cf
cmpl $0xa, %ebp
je 0x4663c
movq %r15, %rdi
callq 0x456b0
testl %eax, %eax
js 0x4663c
cmpl $0xa, %eax
jne 0x4662b
movq %r15, %rdi
callq 0x45ee6
movq %rax, 0x28(%rsp)
movl $0x1, %eax
movq $0x0, 0x30(%rsp)
jmp 0x463a1
testq %r13, %r13
js 0x466d4
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
movq %r13, %rdx
movl 0x14(%rsp), %ecx
movl 0x10(%rsp), %r8d
movq 0x28(%rsp), %r9
callq 0x46702
testl %eax, %eax
jne 0x466de
movq %r14, %rdi
callq 0x4610
jmp 0x466f0
movq 0x1d92c(%rip), %rax     # 0x63fc8
movq (%rax), %rdi
leaq 0xf8af(%rip), %rsi      # 0x55f55
jmp 0x466b9
movq 0x1d919(%rip), %rax     # 0x63fc8
movq (%rax), %rdi
leaq 0xf8e2(%rip), %rsi      # 0x55f9b
movq 0x8(%rsp), %r14
movq %r14, %rdx
xorl %eax, %eax
callq 0x4770
movq 0x18(%rsp), %rbx
jmp 0x466de
callq 0x5f21
movq 0x18(%rsp), %rbx
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x4610
movq %rbx, %rdi
callq 0x46a1e
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq