// File: /workspace/github_cpp_makefile_star2_O2/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, %r14
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0x4370
movq %rax, %rbx
callq 0x38bac
movq %rbx, 0x8(%rsp)
movq %rax, 0x18(%rbx)
pushq $-0x1
popq %rax
movq %rax, 0x30(%rsp)
pushq $-0x1
popq %rax
movq $0x0, 0x28(%rsp)
movl %eax, 0x4(%rsp)
movl %eax, (%rsp)
xorl %eax, %eax
movq 0x30(%rsp), %r15
movl %eax, %r13d
testq %r15, %r15
sets %al
testl %r13d, %r13d
sete %cl
andb %al, %cl
cmpl $0x2, %r13d
sete %bl
orb %cl, %bl
movq %r14, %rdi
callq 0x37c4a
testl %eax, %eax
js 0x38af0
movl %eax, %ebp
cmpl $0xa, %eax
jne 0x38949
cmpl $0x1, %r13d
je 0x38937
testb %bl, %bl
jne 0x38909
pushq $0x2
popq %rax
testl %r13d, %r13d
je 0x388ef
jmp 0x389f2
movq %r14, %rdi
callq 0x384ab
movq %rax, 0x28(%rsp)
pushq $0x1
popq %rax
jmp 0x388ef
cmpl $0x3e, %ebp
jne 0x389f2
testq %r15, %r15
movq 0x8(%rsp), %rbx
js 0x38984
movq 0x20(%rsp), %rbp
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movl 0x4(%rsp), %ecx
movl (%rsp), %r8d
movq 0x28(%rsp), %r9
callq 0x38bb7
testl %eax, %eax
jne 0x38b65
andq $0x0, 0x10(%rsp)
leaq 0x10(%rsp), %r15
movq %r14, %rdi
callq 0x37c4a
movl %eax, %r12d
testl %eax, %eax
js 0x38a69
callq 0x4580
movq (%rax), %rax
movl %r12d, %ecx
testb $0x20, 0x1(%rax,%rcx,2)
movq 0x10(%rsp), %rsi
jne 0x389e1
incq %rsi
movq %r15, %rdi
callq 0x39e70
testl %eax, %eax
js 0x3898f
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x10(%rsp)
movb %r12b, (%rcx,%rax)
jmp 0x3898f
cmpl $0xa, %r12d
je 0x38a6e
testq %rsi, %rsi
je 0x3898f
jmp 0x38a6e
cmpl $0x3, %r13d
je 0x38b28
xorl %r15d, %r15d
callq 0x4580
movq %rax, %rbx
pushq $0x1
popq %r12
movl %r15d, %eax
movq (%rbx), %rcx
movl %ebp, %edx
movzwl (%rcx,%rdx,2), %r15d
shrl $0xf, %r15d
addl %eax, %r15d
movq %r14, %rdi
callq 0x37c4a
incl %r12d
testl %eax, %eax
js 0x38a35
movl %eax, %ebp
cmpl $0xa, %eax
jne 0x38a0b
cmpl $0x2, %r13d
movl %r13d, %eax
pushq $0x3
popq %rcx
cmovel %ecx, %eax
cmpl $0x3, %eax
jne 0x38a50
testl %r15d, %r15d
jne 0x38b40
movl %r15d, %ecx
addq %rcx, 0x30(%rsp)
testl %r13d, %r13d
je 0x38aca
cmpl $0x1, %r13d
jne 0x388ea
jmp 0x38ae2
movq 0x10(%rsp), %rsi
addq $0x2, %rsi
movq %r15, %rdi
callq 0x39e70
testl %eax, %eax
js 0x38a8c
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
movb $0x0, (%rcx,%rax)
testl %r12d, %r12d
js 0x38b89
cmpl $0xa, %r12d
je 0x38aac
movq %r14, %rdi
callq 0x37c4a
testl %eax, %eax
js 0x38aac
cmpl $0xa, %eax
jne 0x38a9b
movq %r14, %rdi
callq 0x384ab
movq %rax, 0x28(%rsp)
pushq $0x1
popq %rax
movq $0x0, 0x30(%rsp)
jmp 0x388ea
xorl 0x4(%rsp), %r12d
xorl (%rsp), %r15d
xorl %eax, %eax
orl %r12d, %r15d
setne %al
addl %eax, %eax
jmp 0x388ea
movl %r12d, 0x4(%rsp)
movl %r15d, (%rsp)
jmp 0x388e8
movq 0x20(%rsp), %rbp
testq %r15, %r15
js 0x38b60
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movl 0x4(%rsp), %ecx
movl (%rsp), %r8d
movq 0x28(%rsp), %r9
callq 0x38bb7
testl %eax, %eax
jne 0x38b65
movq %rbp, %rdi
callq 0x4600
jmp 0x38b77
movq 0x1e4a1(%rip), %rax     # 0x56fd0
movq (%rax), %rdi
movq 0x20(%rsp), %rbp
leaq 0xe427(%rip), %rsi      # 0x46f65
jmp 0x38b56
movq 0x1e489(%rip), %rax     # 0x56fd0
movq (%rax), %rdi
movq 0x20(%rsp), %rbp
leaq 0xe455(%rip), %rsi      # 0x46fab
movq %rbp, %rdx
xorl %eax, %eax
callq 0x4770
movq 0x8(%rsp), %rbx
movq %rbp, %rdi
callq 0x4600
movq %rbx, %rdi
callq 0x38ea6
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1e440(%rip), %rax     # 0x56fd0
movq (%rax), %rcx
leaq 0xe39a(%rip), %rdi      # 0x46f34
pushq $0x30
popq %rsi
pushq $0x1
popq %rdx
callq 0x4a20
movq 0x20(%rsp), %rbp
jmp 0x38b65