// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, %rbp
movl %r8d, 0x44(%rsp)
movl %ecx, %r15d
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, 0x68(%rsp)
movq 0xb0(%rsp), %rbx
movq 0xace91(%rip), %rax     # 0xb2fb0
movq (%rax), %r14
testq %rbx, %rbx
je 0x619a
leaq 0x8bf7b(%rip), %rsi     # 0x920a9
movq %rbx, %rdi
callq 0x46d0
movb $0x1, 0xb(%rsp)
testl %eax, %eax
je 0x61af
leaq 0x8bf6d(%rip), %rsi     # 0x920b3
movq %rbx, %rdi
callq 0x46d0
testl %eax, %eax
je 0x61c9
leaq 0x8bf6a(%rip), %rsi     # 0x920c3
movq %rbx, %rdi
callq 0x46d0
testl %eax, %eax
je 0x61b7
leaq 0x8bf69(%rip), %rsi     # 0x920d5
movq %rbx, %rdi
callq 0x46d0
testl %eax, %eax
je 0x61b7
leaq 0x8bf67(%rip), %rsi     # 0x920e6
movq %rbx, %rdi
callq 0x46d0
testl %eax, %eax
setne %al
movl $0x0, 0xc(%rsp)
movb %al, 0xb(%rsp)
jmp 0x61a9
movb $0x1, 0xb(%rsp)
movl $0x0, 0xc(%rsp)
movb $0x1, %al
movl %eax, 0x14(%rsp)
jmp 0x61d7
movb $0x1, %al
movl %eax, 0x14(%rsp)
jmp 0x61d1
movl $0x0, 0x14(%rsp)
movl $0x0, 0xc(%rsp)
jmp 0x61d7
movl $0x0, 0x14(%rsp)
movb $0x1, %al
movl %eax, 0xc(%rsp)
testq %rbp, %rbp
je 0x61f7
leaq 0x8bf15(%rip), %rsi     # 0x920f8
movq %rbp, %rdi
callq 0x45c0
movq %rax, %r14
testq %rax, %rax
je 0x6753
movq 0x68(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
movl %r15d, %ecx
movl 0x44(%rsp), %r8d
callq 0x6073
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x673d
movq %rbp, 0x60(%rsp)
movl 0xb8(%rsp), %eax
testl %eax, %eax
jle 0x66fa
leaq 0x8d6a5(%rip), %rcx     # 0x938dd
leaq 0x926f0(%rip), %rdx     # 0x9892f
cmpb $0x0, 0xc(%rsp)
cmovneq %rcx, %rdx
movq %rdx, 0x58(%rsp)
xorl %ecx, %ecx
cmpl $0x2, 0x44(%rsp)
sete %cl
leal 0x3e(,%rcx,2), %ecx
movl %ecx, 0x54(%rsp)
movl %eax, %eax
movq %rax, 0x70(%rsp)
leaq 0x8bf82(%rip), %r15     # 0x921f2
xorl %ebp, %ebp
xorl %eax, %eax
movq %rax, 0x48(%rsp)
movq %rax, 0x38(%rsp)
movq %rax, 0x30(%rsp)
movl $0x0, 0x10(%rsp)
cmpb $0x0, 0x14(%rsp)
je 0x62d2
cmpb $0x0, 0xc(%rsp)
je 0x63bc
movl $0x0, 0x20(%rsp)
movq 0xc0(%rsp), %rax
movq (%rax,%rbp,8), %rsi
movq 0x18(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x898d
movq %rax, %rbx
movslq 0x20(%rsp), %rax
movq %rax, 0x48(%rsp)
jmp 0x63da
movq 0xc0(%rsp), %rax
movq (%rax,%rbp,8), %rsi
movq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rdx
leaq 0x38(%rsp), %rcx
leaq 0x30(%rsp), %r8
xorl %r9d, %r9d
callq 0x904c
testq %rax, %rax
je 0x64cd
cmpb $0x0, 0xb(%rsp)
jne 0x636c
movq 0x38(%rsp), %rbx
movq 0x30(%rsp), %r13
movl 0x10(%rsp), %esi
movq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %rdx
leaq 0x30(%rsp), %rcx
callq 0x8b70
testl %eax, %eax
js 0x648f
movl %eax, %ecx
andb $0x1, %cl
cmpq %rbx, 0x38(%rsp)
sete %dl
cmpb %cl, %dl
je 0x648f
cmpq %r13, 0x30(%rsp)
setne %cl
testb $0x2, %al
sete %dl
xorb %cl, %dl
je 0x648f
xorl %eax, %eax
movb $0x1, %r12b
testb %r12b, %r12b
je 0x64e3
cmpb $0x0, 0xc(%rsp)
je 0x6416
movl $0x0, 0x20(%rsp)
movl 0x10(%rsp), %esi
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x8a37
movl 0x38(%rsp), %edx
movl 0x30(%rsp), %ecx
decl %ecx
movq %rbx, %rdi
movq %rax, %rsi
leaq 0x20(%rsp), %r8
callq 0x8e81
movq %rax, %rbx
movslq 0x20(%rsp), %rax
movq %rax, 0x48(%rsp)
jmp 0x6447
movq 0xc0(%rsp), %rax
movq (%rax,%rbp,8), %rsi
movq 0x18(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x8669
movq %rax, %rbx
testq %rbx, %rbx
jne 0x64ed
movq 0xacbee(%rip), %rax     # 0xb2fd8
movq (%rax), %rdi
movq 0xc0(%rsp), %rax
movq (%rax,%rbp,8), %rcx
leaq 0x8bdbc(%rip), %rsi     # 0x921bc
movq 0x58(%rsp), %rdx
xorl %eax, %eax
callq 0x4710
movl $0x2, %eax
jmp 0x66b5
movl 0x10(%rsp), %esi
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x8a37
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
decq %rcx
movq %rbx, %rdi
movq %rax, %rsi
leaq 0x48(%rsp), %r8
callq 0x8e1a
movq %rax, %rbx
xorl %eax, %eax
testq %rbx, %rbx
jne 0x64e5
movq 0xacb7f(%rip), %rax     # 0xb2fd8
movq (%rax), %rbx
movl 0x10(%rsp), %esi
movq 0x18(%rsp), %rdi
callq 0x8a37
movq 0x38(%rsp), %r8
movq 0x30(%rsp), %r9
movq %rbx, %rdi
leaq 0x8bd0a(%rip), %rsi     # 0x92188
movq 0x58(%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x4710
jmp 0x64de
movq 0xacb42(%rip), %rcx     # 0xb2fd8
movq (%rcx), %rdi
movl 0x10(%rsp), %edx
xorl %r12d, %r12d
leaq 0x8bc8c(%rip), %rsi     # 0x92133
movq %rbx, %rcx
movq %r13, %r8
movl %eax, %r9d
xorl %eax, %eax
pushq 0x30(%rsp)
pushq 0x40(%rsp)
callq 0x4710
addq $0x10, %rsp
movl $0x2, %eax
jmp 0x6363
movq 0xc0(%rsp), %rax
leaq (%rax,%rbp,8), %rdi
callq 0x4a00
movl $0x2, %eax
xorl %ebx, %ebx
testl %eax, %eax
jne 0x66b5
movq %rbx, %rdi
callq 0x41e0
movq %rax, %r13
movq 0xc0(%rsp), %rax
movq (%rax,%rbp,8), %rcx
movq 0x48(%rsp), %r8
movq %r14, %rdi
leaq 0x8bccd(%rip), %rsi     # 0x921e0
movl 0x54(%rsp), %edx
xorl %eax, %eax
callq 0x4710
testq %r13, %r13
je 0x6545
xorl %r12d, %r12d
leaq (%rbx,%r12), %rcx
movq %r14, %rdi
movq %r15, %rsi
movl $0x32, %edx
xorl %eax, %eax
callq 0x4710
addq $0x32, %r12
cmpq %r13, %r12
jb 0x6526
movq %rbx, %rdi
callq 0x45d0
cmpl $0x2, 0x44(%rsp)
jne 0x66b3
movq 0xc0(%rsp), %rax
leaq (%rax,%rbp,8), %rbx
movq $0x0, 0x20(%rsp)
cmpb $0x0, 0x14(%rsp)
je 0x65a4
cmpb $0x0, 0xc(%rsp)
je 0x65ed
movl $0x0, 0x2c(%rsp)
movq (%rbx), %rsi
movq 0x18(%rsp), %rdi
leaq 0x2c(%rsp), %rdx
callq 0x8a04
movq %rax, %r13
movslq 0x2c(%rsp), %rax
movq %rax, 0x20(%rsp)
jmp 0x6602
cmpb $0x0, 0xc(%rsp)
je 0x661b
movl $0x0, 0x2c(%rsp)
movl 0x10(%rsp), %esi
movq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0x8a37
movl 0x38(%rsp), %edx
movl 0x30(%rsp), %ecx
decl %ecx
movq %r12, %rdi
movq %rax, %rsi
leaq 0x2c(%rsp), %r8
callq 0x8f19
movq %rax, %r13
movslq 0x2c(%rsp), %rax
movq %rax, 0x20(%rsp)
jmp 0x664c
movq (%rbx), %rsi
movq 0x18(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x89b8
movq %rax, %r13
testq %r13, %r13
jne 0x664c
movq %rbx, %rdi
callq 0x4a24
movl $0x2, %eax
xorl %ebx, %ebx
jmp 0x66af
movl 0x10(%rsp), %esi
movq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0x8a37
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
decq %rcx
movq %r12, %rdi
movq %rax, %rsi
leaq 0x20(%rsp), %r8
callq 0x8eb2
movq %rax, %r13
movq 0x20(%rsp), %rax
cmpq 0x48(%rsp), %rax
jne 0x66c9
movl $0x2, %esi
movl $0x1, %edx
leaq 0x8f163(%rip), %rdi     # 0x957cc
movq %r14, %rcx
callq 0x49c0
movq %r13, %rdi
callq 0x41e0
testq %rax, %rax
je 0x66a3
movq %rax, %rbx
xorl %r12d, %r12d
leaq (%r12,%r13), %rcx
movq %r14, %rdi
movq %r15, %rsi
movl $0x32, %edx
xorl %eax, %eax
callq 0x4710
addq $0x32, %r12
cmpq %rbx, %r12
jb 0x6684
movq %r13, %rdi
callq 0x45d0
xorl %eax, %eax
movb $0x1, %bl
testb %bl, %bl
je 0x66b5
xorl %eax, %eax
testl %eax, %eax
jne 0x6721
incq %rbp
cmpq 0x70(%rsp), %rbp
jne 0x6272
jmp 0x66fa
movq 0xac908(%rip), %rax     # 0xb2fd8
movq (%rax), %rdi
movq (%rbx), %rcx
xorl %ebx, %ebx
leaq 0x8bb41(%rip), %rsi     # 0x92220
movq 0x68(%rsp), %rdx
xorl %eax, %eax
callq 0x4710
movq %r13, %rdi
callq 0x45d0
movl $0x2, %eax
jmp 0x66af
movq 0x18(%rsp), %rdi
callq 0x6ef4
xorl %ebx, %ebx
movq 0x60(%rsp), %r15
testq %r15, %r15
je 0x6760
movq %r14, %rdi
callq 0x44c0
testl %eax, %eax
je 0x6760
movq %r15, %rdi
jmp 0x6756
cmpl $0x2, %eax
jne 0x6751
cmpq $0x0, 0x18(%rsp)
movq 0x60(%rsp), %rbp
je 0x673d
movq 0x18(%rsp), %rdi
callq 0x6ef4
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rbp, %rbp
je 0x6760
movq %r14, %rdi
callq 0x44c0
jmp 0x6760
jmp 0x6760
movq %rbp, %rdi
callq 0x43e0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq