// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/faidx.c
// Function: faidx_fetch_seq
char *faidx_fetch_seq(const faidx_t *fai, const char *c_name, int p_beg_i, int p_end_i, int *len)
{
    int l, c;
    khiter_t iter;
    faidx1_t val;
    char *seq=NULL;

    // Adjust position
    iter = kh_get(s, fai->hash, c_name);
    if (iter == kh_end(fai->hash))
    {
        *len = -2;
        fprintf(stderr, "[fai_fetch_seq] The sequence \"%s\" not found\n", c_name);
        return NULL;
    }
    val = kh_value(fai->hash, iter);
    if(p_end_i < p_beg_i) p_beg_i = p_end_i;
    if(p_beg_i < 0) p_beg_i = 0;
    else if(val.len <= p_beg_i) p_beg_i = val.len - 1;
    if(p_end_i < 0) p_end_i = 0;
    else if(val.len <= p_end_i) p_end_i = val.len - 1;

    // Now retrieve the sequence
    int ret = bgzf_useek(fai->bgzf, val.offset + p_beg_i / val.line_blen * val.line_len + p_beg_i % val.line_blen, SEEK_SET);
    if ( ret<0 )
    {
        *len = -1;
        fprintf(stderr, "[fai_fetch_seq] Error: fai_fetch failed. (Seeking in a compressed, .gzi unindexed, file?)\n");
        return NULL;
    }
    l = 0;
    seq = (char*)malloc(p_end_i - p_beg_i + 2);
    while ( (c=bgzf_getc(fai->bgzf))>=0 && l < p_end_i - p_beg_i + 1)
        if (isgraph(c)) seq[l++] = c;
    seq[l] = '\0';
    *len = l;
    return seq;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x9ff70
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpl (%rcx), %eax
jne 0xa0e28
movq -0x28(%rbp), %rax
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
movq 0x641ca(%rip), %rax     # 0x104fd0
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x431d8(%rip), %rsi     # 0xe3fec
movb $0x0, %al
callq 0x6a80
movq $0x0, -0x8(%rbp)
jmp 0xa0fc3
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x50(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x48(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xa0e63
movl -0x20(%rbp), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0xa0e72
movl $0x0, -0x1c(%rbp)
jmp 0xa0e8c
movq -0x48(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
jg 0xa0e8a
movq -0x48(%rbp), %rax
subq $0x1, %rax
movl %eax, -0x1c(%rbp)
jmp 0xa0e8c
cmpl $0x0, -0x20(%rbp)
jge 0xa0e9b
movl $0x0, -0x20(%rbp)
jmp 0xa0eb5
movq -0x48(%rbp), %rax
movslq -0x20(%rbp), %rcx
cmpq %rcx, %rax
jg 0xa0eb3
movq -0x48(%rbp), %rax
subq $0x1, %rax
movl %eax, -0x20(%rbp)
jmp 0xa0eb5
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rsi
movl -0x1c(%rbp), %eax
cltd
idivl -0x4c(%rbp)
imull -0x50(%rbp), %eax
cltq
addq %rax, %rsi
movl -0x1c(%rbp), %eax
cltd
idivl -0x4c(%rbp)
movslq %edx, %rax
addq %rax, %rsi
xorl %edx, %edx
callq 0x9e5b0
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jge 0xa0f1c
movq -0x28(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq 0x640d2(%rip), %rax     # 0x104fd0
movq (%rax), %rdi
leaq 0x43111(%rip), %rsi     # 0xe4019
movb $0x0, %al
callq 0x6a80
movq $0x0, -0x8(%rbp)
jmp 0xa0fc3
movl $0x0, -0x2c(%rbp)
movl -0x20(%rbp), %eax
subl -0x1c(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rdi
callq 0x69c0
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x9da40
movl %eax, %ecx
movl %ecx, -0x30(%rbp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x5d(%rbp)
jl 0xa0f67
movl -0x2c(%rbp), %eax
movl -0x20(%rbp), %ecx
subl -0x1c(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
setl %al
movb %al, -0x5d(%rbp)
movb -0x5d(%rbp), %al
testb $0x1, %al
jne 0xa0f70
jmp 0xa0fa6
callq 0x6780
movq (%rax), %rax
movslq -0x30(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0xa0fa4
movl -0x30(%rbp), %eax
movb %al, %dl
movq -0x58(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0xa0f38
movq -0x58(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x2c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)