// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rdi
leaq 0xea291(%rip), %rsi     # 0xf7a78
callq 0x232d0
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x232d0
movq %rax, -0x38(%rbp)
callq 0x37e90
movq %rax, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xd830
movq -0x8(%rbp), %rsi
leaq 0xe3d89(%rip), %rdi     # 0xf15ad
movb $0x0, %al
callq 0x5b50
jmp 0xd9a2
cmpq $0x0, -0x38(%rbp)
jne 0xd852
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq 0xe3d78(%rip), %rdi     # 0xf15be
movb $0x0, %al
callq 0x5b50
jmp 0xd9a2
cmpq $0x0, -0x40(%rbp)
jne 0xd86c
leaq 0xe3d7c(%rip), %rdi     # 0xf15dc
movb $0x0, %al
callq 0x5b50
jmp 0xd9a2
cmpq $0x0, -0x28(%rbp)
je 0xd8a9
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl $0x9, %esi
movb $0x0, %al
callq 0x24100
cmpl $0x0, %eax
jge 0xd8a7
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0xe3d54(%rip), %rdi     # 0xf15ef
movb $0x0, %al
callq 0x5b50
jmp 0xd9a2
jmp 0xd8a9
movq -0x30(%rbp), %rdi
callq 0x3c9b0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0xd8d4
movq -0x8(%rbp), %rsi
leaq 0xe3d43(%rip), %rdi     # 0xf160b
movb $0x0, %al
callq 0x5b50
jmp 0xd9a2
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x3d9c0
cmpl $0x0, %eax
jge 0xd8f8
movq -0x18(%rbp), %rsi
leaq 0xe3d31(%rip), %rdi     # 0xf1622
movb $0x0, %al
callq 0x5b50
jmp 0xd8fa
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x41af0
movl %eax, -0x4c(%rbp)
cmpl $0x0, %eax
jl 0xd988
movq -0x40(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x40(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movl $0x4, %ecx
cqto
idivq %rcx
movl %edx, %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
je 0xd95b
movq -0x10(%rbp), %rsi
movl -0x50(%rbp), %edx
movq -0x40(%rbp), %rax
movq 0x38(%rax), %rcx
leaq 0xe3ce4(%rip), %rdi     # 0xf1638
movb $0x0, %al
callq 0x5b50
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x448b0
cmpl $0x0, %eax
jge 0xd983
movq -0x18(%rbp), %rsi
leaq 0xe3cf2(%rip), %rdi     # 0xf166e
movb $0x0, %al
callq 0x5b50
jmp 0xd8fa
cmpl $-0x1, -0x4c(%rbp)
jge 0xd9a0
movq -0x8(%rbp), %rsi
leaq 0xe3ce3(%rip), %rdi     # 0xf167c
movb $0x0, %al
callq 0x5b50
jmp 0xd9a2
movq -0x40(%rbp), %rdi
callq 0x380d0
movq $0x0, -0x40(%rbp)
movq -0x48(%rbp), %rdi
callq 0xd7a0
movq $0x0, -0x48(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xd9d4
movq -0x30(%rbp), %rdi
callq 0x253f0
cmpq $0x0, -0x38(%rbp)
je 0xd9e4
movq -0x38(%rbp), %rdi
callq 0x253f0
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)