// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/test/test_faidx.c
// Function: do_retrieval
int do_retrieval(const char *fn, const char *fnfai, const char *fngzi,
                 int flags, enum fai_format_options format, const char *fnout,
                 const char *interface, int nreg, char **regions) {
    int i, use_64bit = 1, use_parse_reg = 0, use_adjust_reg = 0;
    faidx_t *fai = NULL;
    FILE *out = stdout;

    if (interface) {
        if (strcmp(interface, "fai_fetch") == 0) {
            use_64bit = 0;
        } else if (strcmp(interface, "faidx_fetch_seq") == 0) {
            use_64bit = 0;
            use_parse_reg = 1;
        } else if (strcmp(interface, "faidx_fetch_seq64") == 0
                   || strcmp(interface, "fai_parse_region") == 0) {
            use_parse_reg = 1;
        } else if (strcmp(interface, "fai_adjust_region") == 0) {
            use_parse_reg = 1;
            use_adjust_reg = 1;
        }
    }

    if (fnout) {
        out = fopen(fnout, "wb");
        if (!out) {
            perror(fnout);
            return -1;
        }
    }

    fai = load_index(fn, fnfai, fngzi, flags, format);
    if (!fai)
        goto fail;

    for (i = 0; i < nreg; i++) {
        hts_pos_t len = 0, pos, beg = 0, end = 0;
        int tid = 0;
        char *seq = NULL;
        size_t l;

        if (use_parse_reg) {
            const char *e = fai_parse_region(fai, regions[i],
                                             &tid, &beg, &end, 0);
            if (e == NULL) {
                fprintf(stderr, "Failed: "
                        "fai_parse_region(fai, %s, &tid, &beg, &end, 0)\n",
                        regions[i]);
                goto fail;
            }
            if (use_adjust_reg) {
                hts_pos_t orig_beg = beg, orig_end = end;
                int r = fai_adjust_region(fai, tid, &beg, &end);
                if (r < 0
                    || (((r & 1) != 0) ^ (beg != orig_beg))
                    || (((r & 2) != 0) ^ (end != orig_end))) {
                    fprintf(stderr, "Failed: fai_adjust_region(fai, %d, "
                            "%"PRIhts_pos", %"PRIhts_pos") returned %d\n"
                            "After: beg = %"PRIhts_pos" end = %"PRIhts_pos"\n",
                            tid, orig_beg, orig_end, r, beg, end);
                    goto fail;
                }
            }
            if (use_64bit) {
                seq = faidx_fetch_seq64(fai, faidx_iseq(fai, tid),
                                        beg, end - 1, &len);
            } else {
                int ilen = 0;
                seq = faidx_fetch_seq(fai, faidx_iseq(fai, tid),
                                      beg, end - 1, &ilen);
                len = ilen;
            }
            if (!seq) {
                fprintf(stderr, "Failed: faidx_fetch_seq%s(fai, %s, "
                        "%"PRIhts_pos", %"PRIhts_pos", &len)\n",
                        use_64bit ? "64" : "", faidx_iseq(fai, tid), beg, end);
                goto fail;
            }
        } else {
            if (use_64bit) {
                seq = fai_fetch64(fai, regions[i], &len);
            } else {
                int ilen = 0;
                seq = fai_fetch(fai, regions[i], &ilen);
                len = ilen;
            }
            if (!seq) {
                fprintf(stderr, "Failed: fai_fetch%s(fai, %s, &len)\n",
                        use_64bit ? "64" : "", regions[i]);
                goto fail;
            }
        }

        l = strlen(seq);
        fprintf(out, "%c%s length: %"PRIhts_pos"\n",
                format == FAI_FASTQ ? '@' : '>', regions[i], len);
        for (pos = 0; pos < l; pos += 50) {
            fprintf(out, "%.*s\n", 50, seq + pos);
        }
        free(seq);
        if (format == FAI_FASTQ) {
            hts_pos_t qual_len = 0;
            char *qual;
            if (use_parse_reg) {
                if (use_64bit) {
                    qual = faidx_fetch_qual64(fai, faidx_iseq(fai, tid),
                                              beg, end - 1, &qual_len);
                } else {
                    int ilen = 0;
                    qual = faidx_fetch_qual(fai, faidx_iseq(fai, tid),
                                            beg, end - 1, &ilen);
                    qual_len = ilen;
                }
            } else {
                if (use_64bit) {
                    qual = fai_fetchqual64(fai, regions[i], &qual_len);
                } else {
                    int ilen = 0;
                    qual = fai_fetchqual(fai, regions[i], &ilen);
                    qual_len = ilen;
                }
                if (!qual) {
                    fprintf(stderr, "Failed: fai_fetchqual64(fai, %s, &len)\n",
                            regions[i]);
                    goto fail;
                }
            }
            if (qual_len != len) {
                fprintf(stderr,
                        "Sequence and quality lengths differ for %s %s\n",
                        fn, regions[i]);
                free(qual);
                goto fail;
            }
            fprintf(out, "+\n");
            l = strlen(qual);
            for (pos = 0; pos < l; pos+=50) {
                fprintf(out, "%.*s\n", 50, qual + pos);
            }
            free(qual);
        }
    }

    fai_destroy(fai);

    if (fnout) {
        if (fclose(out) != 0) {
            perror(fnout);
            return -1;
        }
    }
    return 0;

 fail:
    if (fai)
        fai_destroy(fai);
    if (fnout)
        fclose(out);

    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0x1, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq 0xff12f(%rip), %rax     # 0x104fb0
movq (%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x5f37
movq 0x10(%rbp), %rdi
leaq 0xe1253(%rip), %rsi     # 0xe70f1
callq 0x46a0
cmpl $0x0, %eax
jne 0x5eb4
movl $0x0, -0x38(%rbp)
jmp 0x5f35
movq 0x10(%rbp), %rdi
leaq 0xe123c(%rip), %rsi     # 0xe70fb
callq 0x46a0
cmpl $0x0, %eax
jne 0x5ed9
movl $0x0, -0x38(%rbp)
movl $0x1, -0x3c(%rbp)
jmp 0x5f33
movq 0x10(%rbp), %rdi
leaq 0xe1227(%rip), %rsi     # 0xe710b
callq 0x46a0
cmpl $0x0, %eax
je 0x5f03
movq 0x10(%rbp), %rdi
leaq 0xe1224(%rip), %rsi     # 0xe711d
callq 0x46a0
cmpl $0x0, %eax
jne 0x5f0c
movl $0x1, -0x3c(%rbp)
jmp 0x5f31
movq 0x10(%rbp), %rdi
leaq 0xe1217(%rip), %rsi     # 0xe712e
callq 0x46a0
cmpl $0x0, %eax
jne 0x5f2f
movl $0x1, -0x3c(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x5f31
jmp 0x5f33
jmp 0x5f35
jmp 0x5f37
cmpq $0x0, -0x30(%rbp)
je 0x5f70
movq -0x30(%rbp), %rdi
leaq 0xe11f7(%rip), %rsi     # 0xe7140
callq 0x45a0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x5f6e
movq -0x30(%rbp), %rdi
callq 0x43d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x65f4
jmp 0x5f70
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
movl -0x28(%rbp), %r8d
callq 0x5d50
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x5f98
jmp 0x65cd
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0x18(%rbp), %eax
jge 0x6592
movq $0x0, -0x58(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movq $0x0, -0x80(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x622f
movq -0x48(%rbp), %rdi
movq 0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x74(%rbp), %rdx
leaq -0x68(%rbp), %rcx
leaq -0x70(%rbp), %r8
xorl %r9d, %r9d
callq 0x89b0
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
jne 0x603a
movq 0xfefc0(%rip), %rax     # 0x104fd8
movq (%rax), %rdi
movq 0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0xe1115(%rip), %rsi     # 0xe7143
movb $0x0, %al
callq 0x46e0
jmp 0x65cd
cmpl $0x0, -0x40(%rbp)
je 0x6123
movq -0x68(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x48(%rbp), %rdi
movl -0x74(%rbp), %esi
leaq -0x68(%rbp), %rdx
leaq -0x70(%rbp), %rcx
callq 0x84f0
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
jl 0x60db
movl -0xa4(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movq -0x68(%rbp), %rcx
cmpq -0x98(%rbp), %rcx
setne %cl
andb $0x1, %cl
movzbl %cl, %ecx
xorl %ecx, %eax
cmpl $0x0, %eax
jne 0x60db
movl -0xa4(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movq -0x70(%rbp), %rcx
cmpq -0xa0(%rbp), %rcx
setne %cl
andb $0x1, %cl
movzbl %cl, %ecx
xorl %ecx, %eax
cmpl $0x0, %eax
je 0x6121
movq 0xfeef6(%rip), %rax     # 0x104fd8
movq (%rax), %rdi
movl -0x74(%rbp), %edx
movq -0x98(%rbp), %rcx
movq -0xa0(%rbp), %r8
movl -0xa4(%rbp), %r9d
movq -0x68(%rbp), %r10
movq -0x70(%rbp), %rax
leaq 0xe106f(%rip), %rsi     # 0xe717b
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x46e0
jmp 0x65cd
jmp 0x6123
cmpl $0x0, -0x38(%rbp)
je 0x6165
movq -0x48(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x48(%rbp), %rdi
movl -0x74(%rbp), %esi
callq 0x82c0
movq -0xd0(%rbp), %rdi
movq %rax, %rsi
movq -0x68(%rbp), %rdx
movq -0x70(%rbp), %rcx
subq $0x1, %rcx
leaq -0x58(%rbp), %r8
callq 0x8780
movq %rax, -0x80(%rbp)
jmp 0x61bb
movl $0x0, -0xa8(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x48(%rbp), %rdi
movl -0x74(%rbp), %esi
callq 0x82c0
movq -0xd8(%rbp), %rdi
movq %rax, %rsi
movq -0x68(%rbp), %rax
movl %eax, %edx
movq -0x70(%rbp), %rax
subq $0x1, %rax
movl %eax, %ecx
leaq -0xa8(%rbp), %r8
callq 0x8800
movq %rax, -0x80(%rbp)
movslq -0xa8(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x622a
movq 0xfee0f(%rip), %rax     # 0x104fd8
movq (%rax), %rax
movq %rax, -0xe8(%rbp)
movl -0x38(%rbp), %edx
leaq 0xe27dd(%rip), %rax     # 0xe89ba
leaq 0xe7e6b(%rip), %rcx     # 0xee04f
cmpl $0x0, %edx
cmovneq %rcx, %rax
movq %rax, -0xe0(%rbp)
movq -0x48(%rbp), %rdi
movl -0x74(%rbp), %esi
callq 0x82c0
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rdx
movq %rax, %rcx
movq -0x68(%rbp), %r8
movq -0x70(%rbp), %r9
leaq 0xe0fb2(%rip), %rsi     # 0xe71d0
movb $0x0, %al
callq 0x46e0
jmp 0x65cd
jmp 0x62d3
cmpl $0x0, -0x38(%rbp)
je 0x6254
movq -0x48(%rbp), %rdi
movq 0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x58(%rbp), %rdx
callq 0x7d60
movq %rax, -0x80(%rbp)
jmp 0x6289
movl $0x0, -0xac(%rbp)
movq -0x48(%rbp), %rdi
movq 0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq -0xac(%rbp), %rdx
callq 0x8150
movq %rax, -0x80(%rbp)
movslq -0xac(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x62d1
movq 0xfed41(%rip), %rax     # 0x104fd8
movq (%rax), %rdi
movl -0x38(%rbp), %ecx
leaq 0xe2716(%rip), %rdx     # 0xe89ba
leaq 0xe7da4(%rip), %rax     # 0xee04f
cmpl $0x0, %ecx
cmovneq %rax, %rdx
movq 0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0xe0f3f(%rip), %rsi     # 0xe7204
movb $0x0, %al
callq 0x46e0
jmp 0x65cd
jmp 0x62d3
movq -0x80(%rbp), %rdi
callq 0x41c0
movq %rax, -0x88(%rbp)
movq -0x50(%rbp), %rdi
movl -0x28(%rbp), %ecx
movl $0x3e, %edx
movl $0x40, %eax
cmpl $0x2, %ecx
cmovel %eax, %edx
movq 0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x58(%rbp), %r8
leaq 0xe0f17(%rip), %rsi     # 0xe7228
movb $0x0, %al
callq 0x46e0
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x88(%rbp), %rax
jae 0x635a
movq -0x50(%rbp), %rdi
movq -0x80(%rbp), %rcx
addq -0x60(%rbp), %rcx
leaq 0xe0efa(%rip), %rsi     # 0xe723a
movl $0x32, %edx
movb $0x0, %al
callq 0x46e0
movq -0x60(%rbp), %rax
addq $0x32, %rax
movq %rax, -0x60(%rbp)
jmp 0x6320
movq -0x80(%rbp), %rdi
callq 0x45b0
cmpl $0x2, -0x28(%rbp)
jne 0x6582
movq $0x0, -0xb8(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x642b
cmpl $0x0, -0x38(%rbp)
je 0x63ca
movq -0x48(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x48(%rbp), %rdi
movl -0x74(%rbp), %esi
callq 0x82c0
movq -0xf0(%rbp), %rdi
movq %rax, %rsi
movq -0x68(%rbp), %rdx
movq -0x70(%rbp), %rcx
subq $0x1, %rcx
leaq -0xb8(%rbp), %r8
callq 0x8870
movq %rax, -0xc0(%rbp)
jmp 0x6426
movl $0x0, -0xc4(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x48(%rbp), %rdi
movl -0x74(%rbp), %esi
callq 0x82c0
movq -0xf8(%rbp), %rdi
movq %rax, %rsi
movq -0x68(%rbp), %rax
movl %eax, %edx
movq -0x70(%rbp), %rax
subq $0x1, %rax
movl %eax, %ecx
leaq -0xc4(%rbp), %r8
callq 0x88f0
movq %rax, -0xc0(%rbp)
movslq -0xc4(%rbp), %rax
movq %rax, -0xb8(%rbp)
jmp 0x64c6
cmpl $0x0, -0x38(%rbp)
je 0x6456
movq -0x48(%rbp), %rdi
movq 0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq -0xb8(%rbp), %rdx
callq 0x81b0
movq %rax, -0xc0(%rbp)
jmp 0x6491
movl $0x0, -0xc8(%rbp)
movq -0x48(%rbp), %rdi
movq 0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq -0xc8(%rbp), %rdx
callq 0x8220
movq %rax, -0xc0(%rbp)
movslq -0xc8(%rbp), %rax
movq %rax, -0xb8(%rbp)
cmpq $0x0, -0xc0(%rbp)
jne 0x64c4
movq 0xfeb36(%rip), %rax     # 0x104fd8
movq (%rax), %rdi
movq 0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0xe0d88(%rip), %rsi     # 0xe7240
movb $0x0, %al
callq 0x46e0
jmp 0x65cd
jmp 0x64c6
movq -0xb8(%rbp), %rax
cmpq -0x58(%rbp), %rax
je 0x650c
movq 0xfeafe(%rip), %rax     # 0x104fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
movq 0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0xe0d74(%rip), %rsi     # 0xe7268
movb $0x0, %al
callq 0x46e0
movq -0xc0(%rbp), %rdi
callq 0x45b0
jmp 0x65cd
movq -0x50(%rbp), %rdi
leaq 0xe4536(%rip), %rsi     # 0xeaa4d
movb $0x0, %al
callq 0x46e0
movq -0xc0(%rbp), %rdi
callq 0x41c0
movq %rax, -0x88(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x88(%rbp), %rax
jae 0x6576
movq -0x50(%rbp), %rdi
movq -0xc0(%rbp), %rcx
addq -0x60(%rbp), %rcx
leaq 0xe0cde(%rip), %rsi     # 0xe723a
movl $0x32, %edx
movb $0x0, %al
callq 0x46e0
movq -0x60(%rbp), %rax
addq $0x32, %rax
movq %rax, -0x60(%rbp)
jmp 0x6539
movq -0xc0(%rbp), %rdi
callq 0x45b0
jmp 0x6584
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x5f9f
movq -0x48(%rbp), %rdi
callq 0x6fe0
cmpq $0x0, -0x30(%rbp)
je 0x65c4
movq -0x50(%rbp), %rdi
callq 0x44b0
cmpl $0x0, %eax
je 0x65c2
movq -0x30(%rbp), %rdi
callq 0x43d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x65f4
jmp 0x65c4
movl $0x0, -0x4(%rbp)
jmp 0x65f4
cmpq $0x0, -0x48(%rbp)
je 0x65dd
movq -0x48(%rbp), %rdi
callq 0x6fe0
cmpq $0x0, -0x30(%rbp)
je 0x65ed
movq -0x50(%rbp), %rdi
callq 0x44b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq