// File: /workspace/github_c_makefile_star2_O2/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
movl %r8d, 0x50(%rsp)
movl %ecx, %ebx
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, 0x58(%rsp)
movq 0xa0(%rsp), %r13
movq 0x932ab(%rip), %rax     # 0x98fb0
movq (%rax), %r14
testq %r13, %r13
movq %r9, 0x30(%rsp)
je 0x5d89
leaq 0x6c390(%rip), %rsi     # 0x720a9
movq %r13, %rdi
callq 0x46d0
movb $0x1, 0x3(%rsp)
testl %eax, %eax
je 0x5d9e
leaq 0x6c382(%rip), %rsi     # 0x720b3
movq %r13, %rdi
callq 0x46d0
testl %eax, %eax
je 0x5db8
leaq 0x6c37f(%rip), %rsi     # 0x720c3
movq %r13, %rdi
callq 0x46d0
testl %eax, %eax
je 0x5da6
leaq 0x6c37e(%rip), %rsi     # 0x720d5
movq %r13, %rdi
callq 0x46d0
testl %eax, %eax
je 0x5da6
leaq 0x6c37c(%rip), %rsi     # 0x720e6
movq %r13, %rdi
callq 0x46d0
testl %eax, %eax
setne %al
movl $0x0, 0x4(%rsp)
movb %al, 0x3(%rsp)
movl %eax, 0xc(%rsp)
jmp 0x5dc6
movb $0x1, 0x3(%rsp)
movl $0x0, 0x4(%rsp)
movb $0x1, %al
movl %eax, 0xc(%rsp)
jmp 0x5dcb
movb $0x1, %al
movl %eax, 0xc(%rsp)
jmp 0x5dc0
movl $0x0, 0xc(%rsp)
movl $0x0, 0x4(%rsp)
jmp 0x5dc6
movl $0x0, 0xc(%rsp)
movb $0x1, %al
movl %eax, 0x4(%rsp)
movq 0x30(%rsp), %r9
testq %r9, %r9
je 0x5df0
leaq 0x6c321(%rip), %rsi     # 0x720f8
movq %r9, %rdi
callq 0x45c0
movq 0x30(%rsp), %rdi
movq %rax, %r14
testq %rax, %rax
je 0x61d8
movq 0x58(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
movl %ebx, %ecx
movl 0x50(%rsp), %ebx
movl %ebx, %r8d
callq 0x5c60
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x6332
movl 0xa8(%rsp), %ecx
xorl %eax, %eax
cmpl $0x2, %ebx
sete %al
leal 0x3e(,%rax,2), %eax
movl %eax, 0x54(%rsp)
xorl %eax, %eax
testl %ecx, %ecx
cmovlel %eax, %ecx
movq %rcx, 0x60(%rsp)
leaq 0x6c3ae(%rip), %r12     # 0x721f2
pushq $0x32
popq %rbx
xorl %r15d, %r15d
cmpq 0x60(%rsp), %r15
je 0x61ab
andq $0x0, 0x40(%rsp)
andq $0x0, 0x38(%rsp)
andq $0x0, 0x28(%rsp)
andl $0x0, 0x8(%rsp)
cmpb $0x0, 0xc(%rsp)
movq %r15, 0x48(%rsp)
je 0x5eb5
cmpb $0x0, 0x4(%rsp)
je 0x5f8d
andl $0x0, 0x18(%rsp)
movq 0xb0(%rsp), %rax
movq (%rax,%r15,8), %rsi
movq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0x7f5c
movq %rax, %rbp
movslq 0x18(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x5fab
movq 0xb0(%rsp), %rax
movq (%rax,%r15,8), %rsi
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
leaq 0x38(%rsp), %rcx
leaq 0x28(%rsp), %r8
xorl %r9d, %r9d
callq 0x840d
testq %rax, %rax
je 0x61e5
cmpb $0x0, 0x3(%rsp)
jne 0x5f47
movq 0x38(%rsp), %rbp
movq 0x28(%rsp), %r13
movl 0x8(%rsp), %esi
movq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0x810e
movq 0x38(%rsp), %r10
testl %eax, %eax
js 0x62d2
movl %eax, %ecx
andb $0x1, %cl
cmpq %rbp, %r10
sete %dl
movq 0x28(%rsp), %r11
cmpb %cl, %dl
je 0x62d7
cmpq %r13, %r11
setne %cl
testb $0x2, %al
sete %dl
xorb %cl, %dl
je 0x62d7
cmpb $0x0, 0x4(%rsp)
je 0x5fb5
andl $0x0, 0x18(%rsp)
movl 0x8(%rsp), %esi
movq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x8006
movl 0x38(%rsp), %edx
movl 0x28(%rsp), %ecx
decl %ecx
movq %r15, %rdi
movq %rax, %rsi
leaq 0x18(%rsp), %r8
callq 0x832e
movq %rax, %rbp
movslq 0x18(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x5fe6
movq 0xb0(%rsp), %rax
movq (%rax,%r15,8), %rsi
movq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x7cf2
movq %rax, %rbp
testq %rbp, %rbp
jne 0x5ff4
jmp 0x6207
movl 0x8(%rsp), %esi
movq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x8006
movq 0x38(%rsp), %rdx
movq 0x28(%rsp), %rcx
decq %rcx
movq %r15, %rdi
movq %rax, %rsi
leaq 0x40(%rsp), %r8
callq 0x82c9
movq %rax, %rbp
testq %rbp, %rbp
movq 0x48(%rsp), %r15
je 0x624a
movq %rbp, %rdi
callq 0x41e0
movq %rax, %r13
movq 0xb0(%rsp), %rax
movq (%rax,%r15,8), %rcx
movq 0x40(%rsp), %r8
movq %r14, %rdi
leaq 0x6c1c6(%rip), %rsi     # 0x721e0
movl 0x54(%rsp), %edx
xorl %eax, %eax
callq 0x4710
xorl %r15d, %r15d
cmpq %r13, %r15
jae 0x6046
leaq (%r15,%rbp), %rcx
movq %r14, %rdi
movq %r12, %rsi
movl %ebx, %edx
xorl %eax, %eax
callq 0x4710
addq $0x32, %r15
jmp 0x6028
movq %rbp, %rdi
callq 0x45d0
cmpl $0x2, 0x50(%rsp)
jne 0x619e
andq $0x0, 0x18(%rsp)
cmpb $0x0, 0xc(%rsp)
movq 0x48(%rsp), %r15
je 0x60a1
cmpb $0x0, 0x4(%rsp)
je 0x60e7
andl $0x0, 0x24(%rsp)
movq 0xb0(%rsp), %rax
movq (%rax,%r15,8), %rsi
movq 0x10(%rsp), %rdi
leaq 0x24(%rsp), %rdx
callq 0x7fd3
movq %rax, %rbp
movslq 0x24(%rsp), %rax
movq %rax, 0x18(%rsp)
jmp 0x6105
cmpb $0x0, 0x4(%rsp)
je 0x610f
andl $0x0, 0x24(%rsp)
movl 0x8(%rsp), %esi
movq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x8006
movl 0x38(%rsp), %edx
movl 0x28(%rsp), %ecx
decl %ecx
movq %r15, %rdi
movq %rax, %rsi
leaq 0x24(%rsp), %r8
callq 0x83c4
movq %rax, %rbp
movslq 0x24(%rsp), %rax
movq %rax, 0x18(%rsp)
jmp 0x6140
movq 0xb0(%rsp), %rax
movq (%rax,%r15,8), %rsi
movq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0x7f87
movq %rax, %rbp
testq %rbp, %rbp
jne 0x6145
jmp 0x6304
movl 0x8(%rsp), %esi
movq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x8006
movq 0x38(%rsp), %rdx
movq 0x28(%rsp), %rcx
decq %rcx
movq %r15, %rdi
movq %rax, %rsi
leaq 0x18(%rsp), %r8
callq 0x835f
movq %rax, %rbp
movq 0x48(%rsp), %r15
movq 0x18(%rsp), %rax
cmpq 0x40(%rsp), %rax
jne 0x629f
leaq 0x6f5ee(%rip), %rdi     # 0x7574a
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x49c0
movq %rbp, %rdi
callq 0x41e0
movq %rax, %r13
xorl %r15d, %r15d
cmpq %r13, %r15
jae 0x6196
leaq (%r15,%rbp), %rcx
movq %r14, %rdi
movq %r12, %rsi
movl %ebx, %edx
xorl %eax, %eax
callq 0x4710
addq $0x32, %r15
jmp 0x6178
movq %rbp, %rdi
callq 0x45d0
movq 0x48(%rsp), %r15
incq %r15
jmp 0x5e4a
movq 0x10(%rsp), %rdi
callq 0x6a50
xorl %ebx, %ebx
cmpq $0x0, 0x30(%rsp)
je 0x6345
movq %r14, %rdi
callq 0x44c0
testl %eax, %eax
je 0x6345
movq 0x30(%rsp), %rdi
callq 0x43e0
pushq $-0x1
popq %rbx
jmp 0x6345
movq 0x92dec(%rip), %rax     # 0x98fd8
movq (%rax), %rdi
movq 0xb0(%rsp), %rax
movq (%rax,%r15,8), %rdx
leaq 0x6bef9(%rip), %rsi     # 0x720fb
jmp 0x6321
movq 0x92dca(%rip), %rax     # 0x98fd8
movq (%rax), %rdi
leaq 0x6d75e(%rip), %rax     # 0x73976
leaq 0x72718(%rip), %rdx     # 0x78937
cmpb $0x0, 0x4(%rsp)
cmovneq %rax, %rdx
movl %r15d, %eax
movq 0xb0(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
leaq 0x6bf7e(%rip), %rsi     # 0x721bc
xorl %eax, %eax
callq 0x4710
jmp 0x6328
movq 0x92d87(%rip), %rax     # 0x98fd8
movq (%rax), %rbx
leaq 0x6d71b(%rip), %rax     # 0x73976
leaq 0x726d5(%rip), %r12     # 0x78937
cmpb $0x0, 0x4(%rsp)
cmovneq %rax, %r12
movl 0x8(%rsp), %esi
movq 0x10(%rsp), %rdi
callq 0x8006
movq 0x38(%rsp), %r8
movq 0x28(%rsp), %r9
leaq 0x6befe(%rip), %rsi     # 0x72188
movq %rbx, %rdi
movq %r12, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x4710
jmp 0x6328
movq 0x92d32(%rip), %rax     # 0x98fd8
movq (%rax), %rdi
movq 0xb0(%rsp), %rax
movq (%rax,%r15,8), %rcx
leaq 0x6bf64(%rip), %rsi     # 0x72220
movq 0x58(%rsp), %rdx
xorl %eax, %eax
callq 0x4710
movq %rbp, %rdi
callq 0x45d0
jmp 0x6328
movq 0x28(%rsp), %r11
movq 0x92cfa(%rip), %rcx     # 0x98fd8
movq (%rcx), %rdi
movl 0x8(%rsp), %edx
leaq 0x6be47(%rip), %rsi     # 0x72133
movq %rbp, %rcx
movq %r13, %r8
movl %eax, %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x4710
popq %rcx
popq %rdx
jmp 0x6328
movq 0x92ccd(%rip), %rax     # 0x98fd8
movq (%rax), %rdi
movq 0xb0(%rsp), %rax
movq (%rax,%r15,8), %rdx
leaq 0x6bed7(%rip), %rsi     # 0x721f8
xorl %eax, %eax
callq 0x4710
movq 0x10(%rsp), %rdi
callq 0x6a50
pushq $-0x1
popq %rbx
cmpq $0x0, 0x30(%rsp)
je 0x6345
movq %r14, %rdi
callq 0x44c0
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq