// File: /workspace/github_c_makefile_star2_O3/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 $0x68, %rsp
movq %r9, 0x48(%rsp)
movl %r8d, 0x3c(%rsp)
movl %ecx, %ebx
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, 0x58(%rsp)
movq 0xa0(%rsp), %r13
movq 0xa9e90(%rip), %rax     # 0xaffb0
movq (%rax), %r14
testq %r13, %r13
je 0x619b
leaq 0x88f7a(%rip), %rsi     # 0x8f0a9
movq %r13, %rdi
callq 0x46d0
movb $0x1, 0x3(%rsp)
testl %eax, %eax
je 0x61b0
leaq 0x88f6c(%rip), %rsi     # 0x8f0b3
movq %r13, %rdi
callq 0x46d0
testl %eax, %eax
je 0x61ca
leaq 0x88f69(%rip), %rsi     # 0x8f0c3
movq %r13, %rdi
callq 0x46d0
testl %eax, %eax
je 0x61b8
leaq 0x88f68(%rip), %rsi     # 0x8f0d5
movq %r13, %rdi
callq 0x46d0
testl %eax, %eax
je 0x61b8
leaq 0x88f66(%rip), %rsi     # 0x8f0e6
movq %r13, %rdi
callq 0x46d0
testl %eax, %eax
setne %al
movl $0x0, 0x4(%rsp)
movb %al, 0x3(%rsp)
jmp 0x61aa
movb $0x1, 0x3(%rsp)
movl $0x0, 0x4(%rsp)
movb $0x1, %al
movl %eax, 0xc(%rsp)
jmp 0x61d8
movb $0x1, %al
movl %eax, 0xc(%rsp)
jmp 0x61d2
movl $0x0, 0xc(%rsp)
movl $0x0, 0x4(%rsp)
jmp 0x61d8
movl $0x0, 0xc(%rsp)
movb $0x1, %al
movl %eax, 0x4(%rsp)
movq 0x48(%rsp), %r13
testq %r13, %r13
je 0x61fd
leaq 0x88f0f(%rip), %rsi     # 0x8f0f8
movq %r13, %rdi
callq 0x45c0
movq %rax, %r14
testq %rax, %rax
je 0x65e1
movq 0x58(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
movl %ebx, %ecx
movl 0x3c(%rsp), %r8d
callq 0x6076
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x6726
movl 0xa8(%rsp), %eax
testl %eax, %eax
jle 0x65b2
xorl %ecx, %ecx
cmpl $0x2, 0x3c(%rsp)
sete %cl
leal 0x3e(%rcx,%rcx), %ecx
movl %ecx, 0x54(%rsp)
movl %eax, %eax
movq %rax, 0x60(%rsp)
leaq 0x88fa1(%rip), %r15     # 0x8f1f2
xorl %r13d, %r13d
xorl %eax, %eax
movq %rax, 0x40(%rsp)
movq %rax, 0x30(%rsp)
movq %rax, 0x28(%rsp)
movl $0x0, 0x8(%rsp)
cmpb $0x0, 0xc(%rsp)
je 0x62b4
cmpb $0x0, 0x4(%rsp)
je 0x638f
movl $0x0, 0x18(%rsp)
movq 0xb0(%rsp), %rax
movq (%rax,%r13,8), %rsi
movq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0x88e1
movq %rax, %rbx
movslq 0x18(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x63ad
movq 0xb0(%rsp), %rax
movq (%rax,%r13,8), %rsi
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
leaq 0x30(%rsp), %rcx
leaq 0x28(%rsp), %r8
xorl %r9d, %r9d
callq 0x8fb4
testq %rax, %rax
je 0x65f3
cmpb $0x0, 0x3(%rsp)
jne 0x6346
movq 0x30(%rsp), %rbx
movq 0x28(%rsp), %rbp
movl 0x8(%rsp), %esi
movq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0x8ac3
movq 0x30(%rsp), %r10
testl %eax, %eax
js 0x66db
movl %eax, %ecx
andb $0x1, %cl
cmpq %rbx, %r10
sete %dl
movq 0x28(%rsp), %r11
cmpb %cl, %dl
je 0x66e0
cmpq %rbp, %r11
setne %cl
testb $0x2, %al
sete %dl
xorb %cl, %dl
je 0x66e0
cmpb $0x0, 0x4(%rsp)
je 0x63b7
movl $0x0, 0x18(%rsp)
movl 0x8(%rsp), %esi
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x898b
movl 0x30(%rsp), %edx
movl 0x28(%rsp), %ecx
decl %ecx
movq %rbx, %rdi
movq %rax, %rsi
leaq 0x18(%rsp), %r8
callq 0x8de5
movq %rax, %rbx
movslq 0x18(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x63e8
movq 0xb0(%rsp), %rax
movq (%rax,%r13,8), %rsi
movq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x8593
movq %rax, %rbx
testq %rbx, %rbx
jne 0x63f1
jmp 0x661c
movl 0x8(%rsp), %esi
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x898b
movq 0x30(%rsp), %rdx
movq 0x28(%rsp), %rcx
decq %rcx
movq %rbx, %rdi
movq %rax, %rsi
leaq 0x40(%rsp), %r8
callq 0x8d7a
movq %rax, %rbx
testq %rbx, %rbx
je 0x665f
movq %rbx, %rdi
callq 0x41e0
movq %rax, %rbp
movq 0xb0(%rsp), %rax
movq (%rax,%r13,8), %rcx
movq 0x40(%rsp), %r8
movq %r14, %rdi
leaq 0x88dc9(%rip), %rsi     # 0x8f1e0
movl 0x54(%rsp), %edx
xorl %eax, %eax
callq 0x4710
testq %rbp, %rbp
je 0x6449
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 %rbp, %r12
jb 0x642a
movq %rbx, %rdi
callq 0x45d0
cmpl $0x2, 0x3c(%rsp)
jne 0x65a4
movq 0xb0(%rsp), %rax
leaq (%rax,%r13,8), %rbx
movq $0x0, 0x18(%rsp)
cmpb $0x0, 0xc(%rsp)
je 0x64a8
cmpb $0x0, 0x4(%rsp)
je 0x64f1
movl $0x0, 0x24(%rsp)
movq (%rbx), %rsi
movq 0x10(%rsp), %rdi
leaq 0x24(%rsp), %rdx
callq 0x8958
movq %rax, %rbp
movslq 0x24(%rsp), %rax
movq %rax, 0x18(%rsp)
jmp 0x6506
cmpb $0x0, 0x4(%rsp)
je 0x6510
movl $0x0, 0x24(%rsp)
movl 0x8(%rsp), %esi
movq 0x10(%rsp), %r12
movq %r12, %rdi
callq 0x898b
movl 0x30(%rsp), %edx
movl 0x28(%rsp), %ecx
decl %ecx
movq %r12, %rdi
movq %rax, %rsi
leaq 0x24(%rsp), %r8
callq 0x8e81
movq %rax, %rbp
movslq 0x24(%rsp), %rax
movq %rax, 0x18(%rsp)
jmp 0x6541
movq (%rbx), %rsi
movq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0x890c
movq %rax, %rbp
testq %rbp, %rbp
jne 0x6541
jmp 0x670f
movl 0x8(%rsp), %esi
movq 0x10(%rsp), %r12
movq %r12, %rdi
callq 0x898b
movq 0x30(%rsp), %rdx
movq 0x28(%rsp), %rcx
decq %rcx
movq %r12, %rdi
movq %rax, %rsi
leaq 0x18(%rsp), %r8
callq 0x8e16
movq %rax, %rbp
movq 0x18(%rsp), %rax
cmpq 0x40(%rsp), %rax
jne 0x66b1
movl $0x2, %esi
movl $0x1, %edx
leaq 0x8c21d(%rip), %rdi     # 0x9277f
movq %r14, %rcx
callq 0x49c0
movq %rbp, %rdi
callq 0x41e0
testq %rax, %rax
je 0x659c
movq %rax, %rbx
xorl %r12d, %r12d
leaq (%r12,%rbp), %rcx
movq %r14, %rdi
movq %r15, %rsi
movl $0x32, %edx
xorl %eax, %eax
callq 0x4710
addq $0x32, %r12
cmpq %rbx, %r12
jb 0x657d
movq %rbp, %rdi
callq 0x45d0
incq %r13
cmpq 0x60(%rsp), %r13
jne 0x6254
movq 0x10(%rsp), %rdi
callq 0x6e88
xorl %ebx, %ebx
movq 0x48(%rsp), %r15
testq %r15, %r15
je 0x6738
movq %r14, %rdi
callq 0x44c0
testl %eax, %eax
je 0x6738
movq %r15, %rdi
jmp 0x65e4
movq %r13, %rdi
callq 0x43e0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x6738
movq 0xa99de(%rip), %rax     # 0xaffd8
movq (%rax), %rdi
movq 0xb0(%rsp), %rax
movq (%rax,%r13,8), %rdx
leaq 0x88aeb(%rip), %rsi     # 0x8f0fb
xorl %eax, %eax
callq 0x4710
jmp 0x6717
movq 0xa99b5(%rip), %rax     # 0xaffd8
movq (%rax), %rdi
leaq 0x8a310(%rip), %rax     # 0x9093d
leaq 0x8f4d3(%rip), %rdx     # 0x95b07
cmpb $0x0, 0x4(%rsp)
cmovneq %rax, %rdx
movl %r13d, %eax
movq 0xb0(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
leaq 0x88b69(%rip), %rsi     # 0x8f1bc
xorl %eax, %eax
callq 0x4710
jmp 0x6717
movq 0xa9972(%rip), %rax     # 0xaffd8
movq (%rax), %rbx
leaq 0x8a2cd(%rip), %rax     # 0x9093d
leaq 0x8f490(%rip), %r15     # 0x95b07
cmpb $0x0, 0x4(%rsp)
cmovneq %rax, %r15
movl 0x8(%rsp), %esi
movq 0x10(%rsp), %rdi
callq 0x898b
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %r9
leaq 0x88ae9(%rip), %rsi     # 0x8f188
movq %rbx, %rdi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x4710
jmp 0x6717
movq 0xa9920(%rip), %rax     # 0xaffd8
movq (%rax), %rdi
movq (%rbx), %rcx
leaq 0x88b5b(%rip), %rsi     # 0x8f220
movq 0x58(%rsp), %rdx
xorl %eax, %eax
callq 0x4710
movq %rbp, %rdi
callq 0x45d0
jmp 0x6717
movq 0x28(%rsp), %r11
movq 0xa98f1(%rip), %rcx     # 0xaffd8
movq (%rcx), %rdi
movl 0x8(%rsp), %edx
leaq 0x88a3e(%rip), %rsi     # 0x8f133
movq %rbx, %rcx
movq %rbp, %r8
movl %eax, %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x4710
addq $0x10, %rsp
jmp 0x6717
movq %rbx, %rdi
callq 0x4a00
movq 0x10(%rsp), %rdi
callq 0x6e88
movq 0x48(%rsp), %r13
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %r13, %r13
je 0x6738
movq %r14, %rdi
callq 0x44c0
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq