// File: /workspace/github_c_makefile_star2_O1/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 0x93d2a(%rip), %rsi     # 0x9f73b
callq 0x1b857
movq %rax, %r14
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x1b857
movq %rax, %rbx
callq 0x28947
movq %rax, %r15
testq %r14, %r14
je 0xbb6e
testq %rbx, %rbx
je 0xbb7d
testq %r15, %r15
je 0xbb91
testq %r12, %r12
je 0xba6e
movq %rbx, %rdi
movl $0x9, %esi
movq %r12, %rdx
xorl %eax, %eax
callq 0x1c1ea
testl %eax, %eax
js 0xbbde
movq %r13, %rbp
movq %r14, %rdi
callq 0x2b6fd
testq %rax, %rax
je 0xbba4
movq %rax, %r13
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2ca7e
testl %eax, %eax
js 0xbbb0
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2f8d9
testl %eax, %eax
js 0xbb1e
leaq 0x8c1df(%rip), %r12     # 0x97c90
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 0xbaf8
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x330c3
testl %eax, %eax
js 0xbb09
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2f8d9
testl %eax, %eax
jns 0xbab1
jmp 0xbb1e
movq %r12, %rdi
movq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x49e0
jmp 0xbad2
leaq 0x8c1b6(%rip), %rdi     # 0x97cc6
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x49e0
jmp 0xbae4
cmpl $-0x1, %eax
jne 0xbbc8
movq %r15, %rdi
callq 0x28a24
movq %r13, %rdi
callq 0x27fc6
testq %r14, %r14
je 0xbb44
movq %r14, %rdi
callq 0x1cac1
testq %rbx, %rbx
je 0xbb5f
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1cac1
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8c090(%rip), %rdi     # 0x97c05
movq %r13, %rsi
xorl %r13d, %r13d
jmp 0xbbd2
leaq 0x8c092(%rip), %rdi     # 0x97c16
xorl %r13d, %r13d
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
jmp 0xbbf0
leaq 0x8c09c(%rip), %rdi     # 0x97c34
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x49e0
jmp 0xbb27
leaq 0x8c0b8(%rip), %rdi     # 0x97c63
xorl %r13d, %r13d
jmp 0xbbcf
leaq 0x8c0c3(%rip), %rdi     # 0x97c7a
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x49e0
jmp 0xba98
leaq 0x8c105(%rip), %rdi     # 0x97cd4
movq %rbp, %rsi
xorl %eax, %eax
callq 0x49e0
jmp 0xbb27
leaq 0x8c062(%rip), %rdi     # 0x97c47
xorl %r13d, %r13d
movq %r12, %rsi
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x49e0
jmp 0xbb27