// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/test/test_view.c
// Function: vcf_loop
int vcf_loop(int argc, char **argv, int optind, struct opts *opts, htsFile *in, htsFile *out) {
    bcf_hdr_t *h = bcf_hdr_read(in);
    bcf1_t *b = bcf_init1();
    hts_idx_t *idx;
    int i, exit_code = 0, r = 0;

    if (!h)
        return 1;
    if (!b)
        return 1;

    if (!opts->benchmark && bcf_hdr_write(out, h) < 0)
        return 1;

    if (opts->index) {
        if (bcf_idx_init(out, h, opts->min_shift, opts->index) < 0) {
            fprintf(stderr, "Failed to initialise index\n");
            return 1;
        }
    }

    if (optind + 1 < argc) {
        // A series of regions.
        if ((idx = bcf_index_load(argv[optind])) == 0) {
            fprintf(stderr, "[E::%s] fail to load the BVCF index\n", __func__);
            return 1;
        }

        for (i = optind + 1; i < argc; i++) {
            hts_itr_t *iter;
            if ((iter = bcf_itr_querys(idx, h, argv[i])) == 0) {
                fprintf(stderr, "[E::%s] fail to parse region '%s'\n", __func__, argv[i]);
                exit_code = 1;
                break;
            }
            while ((r = bcf_itr_next(in, iter, b)) >= 0) {
                if (!opts->benchmark && bcf_write1(out, h, b) < 0) {
                    fprintf(stderr, "Error writing output.\n");
                    exit_code = 1;
                    break;
                }
                if (opts->nreads && --opts->nreads == 0)
                    break;
            }
            if (r < -1) {
                fprintf(stderr, "Error reading input.\n");
                exit_code = 1;
            }
            hts_itr_destroy(iter);
            if (exit_code != 0) break;
        }

        hts_idx_destroy(idx);

    } else {
        // Whole file
        while ((r = bcf_read1(in, h, b)) >= 0) {
            if (!opts->benchmark && bcf_write1(out, h, b) < 0) {
                fprintf(stderr, "Error writing output.\n");
                exit_code = 1;
                break;
            }
            if (opts->nreads && --opts->nreads == 0)
                break;
        }
        if (r < -1) {
            fprintf(stderr, "Error reading input.\n");
            exit_code = 1;
        }
    }

    if (exit_code == 0 && opts->index) {
        if (bcf_idx_save(out) < 0) {
            fprintf(stderr, "Error saving index\n");
            exit_code = 1;
        }
    }

    bcf_destroy1(b);
    bcf_hdr_destroy(h);
    return exit_code;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x8(%rsp)
movq %r8, %r13
movq %rcx, %r12
movl %edx, %ebp
movq %rsi, 0x20(%rsp)
movl %edi, 0x14(%rsp)
movq %r8, %rdi
callq 0x2f3f7
movq %rax, %rbx
callq 0x3047e
movq %rax, %r14
testq %rbx, %rbx
sete %al
testq %r14, %r14
sete %cl
orb %al, %cl
movl $0x1, %r15d
jne 0x6b63
cmpl $0x0, 0x1c(%r12)
jne 0x69b2
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x300ca
testl %eax, %eax
js 0x6b63
movq 0x28(%r12), %rcx
testq %rcx, %rcx
je 0x69d6
movl 0x30(%r12), %edx
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x3c367
testl %eax, %eax
js 0x6b75
leal 0x1(%rbp), %r15d
cmpl 0x14(%rsp), %r15d
jge 0x6abf
movslq %ebp, %rax
movq 0x20(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
xorl %esi, %esi
callq 0x116c5
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x6b7c
movslq %r15d, %r15
movq 0x20(%rsp), %rax
movq (%rax,%r15,8), %rsi
movq 0x18(%rsp), %rdi
leaq 0x1a3(%rip), %rdx       # 0x6bc1
movq %rbx, %rcx
leaq 0x7375(%rip), %r8       # 0xdd9d
leaq 0x2ad3f(%rip), %r9      # 0x3176e
callq 0x10811
testq %rax, %rax
je 0x6b90
movq %rax, %rbp
testb $0x10, (%r13)
je 0x6b2a
movq 0x38(%r13), %rdi
movq %rbp, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x10a5e
testl %eax, %eax
js 0x6a94
cmpl $0x0, 0x1c(%r12)
jne 0x6a80
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x323c6
testl %eax, %eax
js 0x6b36
movl 0x14(%r12), %eax
testl %eax, %eax
je 0x6a40
decl %eax
movl %eax, 0x14(%r12)
jne 0x6a40
jmp 0x6a9d
cmpl $-0x1, %eax
jne 0x6b2f
movq %rbp, %rdi
callq 0xe951
incq %r15
cmpl 0x14(%rsp), %r15d
jne 0x6a09
movq 0x18(%rsp), %rdi
callq 0xb6ef
jmp 0x6b0a
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x30a59
testl %eax, %eax
js 0x6b05
cmpl $0x0, 0x1c(%r12)
jne 0x6af1
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x323c6
testl %eax, %eax
js 0x6bba
movl 0x14(%r12), %eax
testl %eax, %eax
je 0x6abf
decl %eax
movl %eax, 0x14(%r12)
jne 0x6abf
jmp 0x6b0a
cmpl $-0x1, %eax
jne 0x6b89
xorl %r15d, %r15d
cmpq $0x0, 0x28(%r12)
je 0x6b53
movq 0x8(%rsp), %rdi
callq 0x3c4ed
testl %eax, %eax
jns 0x6b53
callq 0x4c2e
jmp 0x6b4d
callq 0x4c66
callq 0x4c8f
jmp 0x6b3b
callq 0x4c4a
movq %rbp, %rdi
callq 0xe951
movq 0x18(%rsp), %rdi
callq 0xb6ef
movl $0x1, %r15d
movq %r14, %rdi
callq 0x30629
movq %rbx, %rdi
callq 0x2f254
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4bda
jmp 0x6b63
callq 0x4cab
movl $0x1, %r15d
jmp 0x6b63
callq 0x4bf6
jmp 0x6b4d
movq 0xc8441(%rip), %rax     # 0xcefd8
movq (%rax), %rdi
movq 0x20(%rsp), %rax
movq (%rax,%r15,8), %rcx
leaq 0xa1604(%rip), %rsi     # 0xa81ae
leaq 0xa166f(%rip), %rdx     # 0xa8220
xorl %eax, %eax
callq 0x4730
jmp 0x6b43
callq 0x4c12
jmp 0x6b4d