// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/test/sam.c
// Function: copy_check_alignment
static void copy_check_alignment(const char *infname, const char *informat,
    const char *outfname, const char *outmode, const char *outref)
{
    samFile *in = sam_open(infname, "r");
    samFile *out = sam_open(outfname, outmode);
    bam1_t *aln = bam_init1();
    bam_hdr_t *header = NULL;
    int res;

    if (!in) {
        fail("couldn't open %s", infname);
        goto err;
    }
    if (!out) {
        fail("couldn't open %s with mode %s", outfname, outmode);
        goto err;
    }
    if (!aln) {
        fail("bam_init1() failed");
        goto err;
    }

    if (outref) {
        if (hts_set_opt(out, CRAM_OPT_REFERENCE, outref) < 0) {
            fail("setting reference %s for %s", outref, outfname);
            goto err;
        }
    }

    header = sam_hdr_read(in);
    if (!header) {
        fail("reading header from %s", infname);
        goto err;
    }
    if (sam_hdr_write(out, header) < 0) fail("writing headers to %s", outfname);

    while ((res = sam_read1(in, header, aln)) >= 0) {
        int mod4 = ((intptr_t) bam_get_cigar(aln)) % 4;
        if (mod4 != 0)
            fail("%s CIGAR not 4-byte aligned; offset is 4k+%d for \"%s\"",
                 informat, mod4, bam_get_qname(aln));

        if (sam_write1(out, header, aln) < 0) fail("writing to %s", outfname);
    }
    if (res < -1) {
        fail("failed to read alignment from %s", infname);
    }

 err:
    bam_destroy1(aln);
    aln = NULL;
    bam_hdr_destroy(header);
    header = NULL;
    if (in) sam_close(in);
    if (out) sam_close(out);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %r12
movq %rcx, %rbp
movq %rdx, %rbx
movq %rsi, 0x10(%rsp)
movq %rdi, %r13
leaq 0x91aaf(%rip), %rsi     # 0x9d73f
callq 0x1b1e0
movq %rax, %r14
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x1b1e0
movq %rax, %rbx
callq 0x27f95
movq %rax, %r15
testq %r14, %r14
je 0xbded
testq %rbx, %rbx
je 0xbdfc
testq %r15, %r15
je 0xbe10
testq %r12, %r12
je 0xbced
movq %rbx, %rdi
movl $0x9, %esi
movq %r12, %rdx
xorl %eax, %eax
callq 0x1bb6e
testl %eax, %eax
js 0xbe5d
movq %r13, %rbp
movq %r14, %rdi
callq 0x2ad61
testq %rax, %rax
je 0xbe23
movq %rax, %r13
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2bf5a
testl %eax, %eax
js 0xbe2f
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2ed2f
testl %eax, %eax
js 0xbd9d
leaq 0x89fe0(%rip), %r12     # 0x95d10
movq 0x38(%r15), %rcx
movzwl 0x12(%r15), %eax
movq %rcx, %rdx
addq %rax, %rdx
leaq 0x3(%rcx,%rax), %rax
cmovnsq %rdx, %rax
andq $-0x4, %rax
subq %rax, %rdx
jne 0xbd77
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x32572
testl %eax, %eax
js 0xbd88
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2ed2f
testl %eax, %eax
jns 0xbd30
jmp 0xbd9d
movq %r12, %rdi
movq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x49e0
jmp 0xbd51
leaq 0x89fb7(%rip), %rdi     # 0x95d46
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x49e0
jmp 0xbd63
cmpl $-0x1, %eax
jne 0xbe47
movq %r15, %rdi
callq 0x2806b
movq %r13, %rdi
callq 0x27642
testq %r14, %r14
je 0xbdc3
movq %r14, %rdi
callq 0x1c442
testq %rbx, %rbx
je 0xbdde
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1c442
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x89e91(%rip), %rdi     # 0x95c85
movq %r13, %rsi
xorl %r13d, %r13d
jmp 0xbe51
leaq 0x89e93(%rip), %rdi     # 0x95c96
xorl %r13d, %r13d
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
jmp 0xbe6f
leaq 0x89e9d(%rip), %rdi     # 0x95cb4
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x49e0
jmp 0xbda6
leaq 0x89eb9(%rip), %rdi     # 0x95ce3
xorl %r13d, %r13d
jmp 0xbe4e
leaq 0x89ec4(%rip), %rdi     # 0x95cfa
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x49e0
jmp 0xbd17
leaq 0x89f06(%rip), %rdi     # 0x95d54
movq %rbp, %rsi
xorl %eax, %eax
callq 0x49e0
jmp 0xbda6
leaq 0x89e63(%rip), %rdi     # 0x95cc7
xorl %r13d, %r13d
movq %r12, %rsi
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x49e0
jmp 0xbda6