// File: /workspace/github_c_makefile_star2_O1/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, 0x10(%rsp)
movq %r8, %r13
movq %rcx, %r12
movl %edx, %ebx
movq %rsi, 0x18(%rsp)
movl %edi, 0x8(%rsp)
movq %r8, %rdi
callq 0x306ef
movq %rax, %r15
callq 0x316f3
movq %rax, %r14
movq %r15, (%rsp)
testq %r15, %r15
sete %al
testq %r14, %r14
sete %cl
orb %al, %cl
movl $0x1, %ebp
jne 0x6c22
cmpl $0x0, 0x1c(%r12)
jne 0x69e7
movq 0x10(%rsp), %rdi
movq (%rsp), %rsi
callq 0x31334
testl %eax, %eax
js 0x6c22
movq 0x28(%r12), %rcx
testq %rcx, %rcx
je 0x6a0c
movl 0x30(%r12), %edx
movq 0x10(%rsp), %rdi
movq (%rsp), %rsi
callq 0x3d180
testl %eax, %eax
js 0x6bd1
leal 0x1(%rbx), %r15d
cmpl 0x8(%rsp), %r15d
jge 0x6b6c
movslq %ebx, %rax
movq 0x18(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x11aaa
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x6bd8
cmpl 0x8(%rsp), %r15d
jge 0x6bc5
movslq %r15d, %r15
xorl %ebx, %ebx
movl %ebx, 0xc(%rsp)
movq 0x18(%rsp), %rax
movq (%rax,%r15,8), %rsi
movq 0x20(%rsp), %rdi
leaq 0x1e4(%rip), %rdx       # 0x6c4b
movq (%rsp), %rcx
leaq 0x76eb(%rip), %r8       # 0xe15d
leaq 0x2bfb0(%rip), %r9      # 0x32a29
callq 0x10bf5
movq %rax, %rbx
testq %rax, %rax
je 0x6b37
testb $0x10, (%r13)
jne 0x6abd
movl $0x1, %edi
leaq 0xa3df0(%rip), %rsi     # 0xaa88d
leaq 0xa3df6(%rip), %rdx     # 0xaa89a
xorl %eax, %eax
callq 0xa63c
callq 0x4050
movl $0x16, (%rax)
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
jmp 0x6ad0
movq 0x38(%r13), %rdi
movq %rbx, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x10e7e
movl %eax, %ebp
testl %ebp, %ebp
js 0x6b03
cmpl $0x0, 0x1c(%r12)
jne 0x6af1
movq 0x10(%rsp), %rdi
movq (%rsp), %rsi
movq %r14, %rdx
callq 0x33623
testl %eax, %eax
js 0x6b5d
movl 0x14(%r12), %eax
testl %eax, %eax
je 0x6a8a
decl %eax
movl %eax, 0x14(%r12)
jne 0x6a8a
cmpl $-0x2, %ebp
jle 0x6b4e
movq %rbx, %rdi
callq 0xed17
xorl %eax, %eax
cmpl $0x0, 0xc(%rsp)
setne %al
movl %eax, %ebx
testb %al, %al
jne 0x6bc5
incq %r15
cmpl 0x8(%rsp), %r15d
jne 0x6a4e
jmp 0x6bc5
movq 0x18(%rsp), %rax
leaq (%rax,%r15,8), %rdi
callq 0x4c1e
movb $0x1, %al
movl $0x1, %ebx
jmp 0x6b1c
callq 0x4c02
movl $0x1, 0xc(%rsp)
jmp 0x6b08
callq 0x4be6
movl $0x1, 0xc(%rsp)
jmp 0x6b03
movq %r13, %rdi
movq (%rsp), %rsi
movq %r14, %rdx
callq 0x31cce
movl %eax, %ebx
xorl %ebp, %ebp
testl %eax, %eax
js 0x6be9
cmpl $0x0, 0x1c(%r12)
jne 0x6ba0
movq 0x10(%rsp), %rdi
movq (%rsp), %rsi
movq %r14, %rdx
callq 0x33623
testl %eax, %eax
js 0x6bdf
movl 0x14(%r12), %eax
testl %eax, %eax
je 0x6bb2
decl %eax
movl %eax, 0x14(%r12)
je 0x6be9
movq %r13, %rdi
movq (%rsp), %rsi
movq %r14, %rdx
callq 0x31cce
movl %eax, %ebx
jmp 0x6b7f
movq 0x20(%rsp), %rdi
callq 0xbb22
jmp 0x6bf0
callq 0x4b92
jmp 0x6c22
callq 0x4c5f
jmp 0x6c22
callq 0x4bae
movl $0x1, %ebp
cmpl $-0x2, %ebx
movl %ebp, %ebx
jle 0x6c33
movl $0x1, %ebp
testl %ebx, %ebx
jne 0x6c11
xorl %ebp, %ebp
cmpq $0x0, 0x28(%r12)
je 0x6c11
movq 0x10(%rsp), %rdi
callq 0x3d306
testl %eax, %eax
js 0x6c3f
movq %r14, %rdi
callq 0x31896
movq (%rsp), %rdi
callq 0x30556
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4bca
movl $0x1, %ebx
jmp 0x6bf0
callq 0x4c43
movl $0x1, %ebp
jmp 0x6c11