// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x63a0
movl $0x1, %edi
movl $0x20, %esi
callq 0x6460
movq %rax, -0x48(%rbp)
callq 0x9fa10
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x18(%rax)
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
movq $-0x1, -0x58(%rbp)
movl $0x0, -0x38(%rbp)
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
movq $0x0, -0x50(%rbp)
movq -0x10(%rbp), %rdi
callq 0x9da40
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
jl 0x9f9aa
cmpl $0xa, -0x2c(%rbp)
jne 0x9f77c
cmpl $0x1, -0x38(%rbp)
jne 0x9f752
movq -0x10(%rbp), %rdi
callq 0x9e890
movq %rax, -0x50(%rbp)
jmp 0x9f722
cmpl $0x0, -0x38(%rbp)
jne 0x9f75f
cmpq $0x0, -0x58(%rbp)
jl 0x9f765
cmpl $0x2, -0x38(%rbp)
jne 0x9f767
jmp 0x9f722
cmpl $0x0, -0x38(%rbp)
jne 0x9f776
movl $0x2, -0x38(%rbp)
jmp 0x9f722
jmp 0x9f778
jmp 0x9f77a
jmp 0x9f77c
cmpl $0x3e, -0x2c(%rbp)
jne 0x9f88c
cmpq $0x0, -0x58(%rbp)
jl 0x9f7ab
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x58(%rbp), %rax
movl %eax, %edx
movl -0x30(%rbp), %ecx
movl -0x34(%rbp), %r8d
movq -0x50(%rbp), %r9
callq 0x9fa30
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x9da40
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
jl 0x9f7ff
callq 0x6780
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
jne 0x9f7ec
movl -0x2c(%rbp), %edi
leaq -0x28(%rbp), %rsi
callq 0x9fb80
jmp 0x9f7fd
cmpq $0x0, -0x28(%rbp)
ja 0x9f7f9
cmpl $0xa, -0x2c(%rbp)
jne 0x9f7fb
jmp 0x9f7ff
jmp 0x9f7fd
jmp 0x9f7b3
leaq 0x45c00(%rip), %rdi     # 0xe5406
xorl %esi, %esi
leaq -0x28(%rbp), %rdx
callq 0x9fcc0
cmpl $0x0, -0x2c(%rbp)
jge 0x9f834
movq 0x657b2(%rip), %rax     # 0x104fd0
movq (%rax), %rdi
leaq 0x444ed(%rip), %rsi     # 0xe3d15
movb $0x0, %al
callq 0x6a80
jmp 0x9f9e6
cmpl $0xa, -0x2c(%rbp)
je 0x9f86b
jmp 0x9f83c
movq -0x10(%rbp), %rdi
callq 0x9da40
movl %eax, %ecx
movl %ecx, -0x2c(%rbp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x59(%rbp)
jl 0x9f85e
cmpl $0xa, -0x2c(%rbp)
setne %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x9f867
jmp 0x9f869
jmp 0x9f83c
jmp 0x9f86b
movl $0x1, -0x38(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x10(%rbp), %rdi
callq 0x9e890
movq %rax, -0x50(%rbp)
jmp 0x9f9a5
cmpl $0x3, -0x38(%rbp)
jne 0x9f8b3
movq 0x65737(%rip), %rax     # 0x104fd0
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x4449f(%rip), %rsi     # 0xe3d46
movb $0x0, %al
callq 0x6a80
jmp 0x9f9e6
cmpl $0x2, -0x38(%rbp)
jne 0x9f8c0
movl $0x3, -0x38(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
callq 0x6780
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x9f8fa
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x9f8fc
movq -0x10(%rbp), %rdi
callq 0x9da40
movl %eax, %ecx
movl %ecx, -0x2c(%rbp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x5a(%rbp)
jl 0x9f91e
cmpl $0xa, -0x2c(%rbp)
setne %al
movb %al, -0x5a(%rbp)
movb -0x5a(%rbp), %al
testb $0x1, %al
jne 0x9f8ce
cmpl $0x3, -0x38(%rbp)
jne 0x9f952
cmpl $0x0, -0x40(%rbp)
je 0x9f952
movq 0x65698(%rip), %rax     # 0x104fd0
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x44446(%rip), %rsi     # 0xe3d8c
movb $0x0, %al
callq 0x6a80
jmp 0x9f9e6
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movslq -0x40(%rbp), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpl $0x1, -0x38(%rbp)
jne 0x9f982
movl -0x3c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
jmp 0x9f9a3
cmpl $0x0, -0x38(%rbp)
jne 0x9f9a1
movl -0x3c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jne 0x9f998
movl -0x40(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x9f99f
movl $0x2, -0x38(%rbp)
jmp 0x9f9a1
jmp 0x9f9a3
jmp 0x9f9a5
jmp 0x9f722
cmpq $0x0, -0x58(%rbp)
jl 0x9f9d1
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x58(%rbp), %rax
movl %eax, %edx
movl -0x30(%rbp), %ecx
movl -0x34(%rbp), %r8d
movq -0x50(%rbp), %r9
callq 0x9fa30
jmp 0x9f9d3
jmp 0x9f9e6
movq -0x18(%rbp), %rdi
callq 0x6880
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x9fa00
movq -0x18(%rbp), %rdi
callq 0x6880
movq -0x48(%rbp), %rdi
callq 0x9fe30
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)