// File: /workspace/github_c_makefile_star2_O2/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, %rbp
movq %rcx, %r12
movq %rdx, %rbx
movq %rsi, 0x10(%rsp)
movq %rdi, %r13
leaq 0x74417(%rip), %rsi     # 0x7f68a
callq 0x170e7
movq %rax, %r14
movq %rbx, (%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x170e7
movq %rax, %rbx
callq 0x224a4
movq %rax, %r15
testq %r14, %r14
je 0xb372
testq %rbx, %rbx
je 0xb381
testq %r15, %r15
je 0xb39b
testq %rbp, %rbp
je 0xb2cd
pushq $0x9
popq %rsi
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x17a5f
testl %eax, %eax
js 0xb419
movq %r13, 0x8(%rsp)
movq %r14, %rdi
callq 0x24c2e
testq %rax, %rax
je 0xb3bc
movq %rax, %r13
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2572d
testl %eax, %eax
movq (%rsp), %rbp
jns 0xb30a
leaq 0x6c97a(%rip), %rdi     # 0x77c7a
movq %rbp, %rsi
xorl %eax, %eax
callq 0x5b0d
pushq $0x4
popq %r12
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x279c2
testl %eax, %eax
js 0xb3ae
movq 0x38(%r15), %rcx
movzwl 0x12(%r15), %eax
addq %rcx, %rax
cqto
idivq %r12
testq %rdx, %rdx
je 0xb34d
leaq 0x6c94f(%rip), %rdi     # 0x77c90
movq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x5b0d
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x29349
testl %eax, %eax
jns 0xb30e
leaq 0x6c960(%rip), %rdi     # 0x77cc6
movq %rbp, %rsi
xorl %eax, %eax
callq 0x5b0d
jmp 0xb30e
leaq 0x6c88c(%rip), %rdi     # 0x77c05
movq %r13, %rsi
xorl %r13d, %r13d
jmp 0xb3cb
leaq 0x6c88e(%rip), %rdi     # 0x77c16
xorl %r13d, %r13d
movq (%rsp), %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x5b0d
jmp 0xb3d2
leaq 0x6c892(%rip), %rdi     # 0x77c34
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x5b0d
jmp 0xb3d2
cmpl $-0x1, %eax
je 0xb3d2
leaq 0x6c91a(%rip), %rdi     # 0x77cd4
jmp 0xb3c6
leaq 0x6c8a0(%rip), %rdi     # 0x77c63
xorl %r13d, %r13d
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x5b0d
movq %r15, %rdi
callq 0x22572
movq %r13, %rdi
callq 0x21bfe
testq %r14, %r14
je 0xb3ef
movq %r14, %rdi
callq 0x182bd
testq %rbx, %rbx
je 0xb40a
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x182bd
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6c827(%rip), %rdi     # 0x77c47
xorl %r13d, %r13d
movq %rbp, %rsi
movq (%rsp), %rdx
jmp 0xb392