// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/test/sam.c
// Function: check_big_ref
static void check_big_ref(int parse_header)
{
    static const char sam_text[] = "data:,"
        "@HD\tVN:1.4\n"
        "@SQ\tSN:large#1\tLN:5000000000\n"
        "@SQ\tSN:small#1\tLN:100\n"
        "@SQ\tSN:large#2\tLN:4611686018427387904\n"
        "@SQ\tSN:small#2\tLN:1\n"
        "r1\t0\tlarge#1\t4999999000\t50\t8M\t*\t0\t0\tACGTACGT\tabcdefgh\n"
        "r2\t0\tsmall#1\t1\t50\t8M\t*\t0\t0\tACGTACGT\tabcdefgh\n"
        "r3\t0\tlarge#2\t4611686018427387000\t50\t8M\t*\t0\t0\tACGTACGT\tabcdefgh\n"
        "p1\t99\tlarge#2\t1\t50\t8M\t=\t4611686018427387895\t4611686018427387903\tACGTACGT\tabcdefgh\n"
        "p1\t147\tlarge#2\t4611686018427387895\t50\t8M\t=\t1\t-4611686018427387903\tACGTACGT\tabcdefgh\n"
        "r4\t0\tsmall#2\t2\t50\t8M\t*\t0\t0\tACGTACGT\tabcdefgh\n";
    const hts_pos_t expected_lengths[] = {
        5000000000LL, 100LL, 4611686018427387904LL, 1LL
    };
    const int expected_tids[] = {
        0, 1, 2, 2, 2, 3
    };
    const int expected_mtid[] = {
        -1, -1, -1, 2, 2, -1
    };
    const hts_pos_t expected_positions[] = {
        4999999000LL - 1, 1LL - 1, 4611686018427387000LL - 1, 1LL - 1,
        4611686018427387895LL - 1, 2LL - 1
    };
    const hts_pos_t expected_mpos[] = {
        -1, -1, -1, 4611686018427387895LL - 1, 1LL - 1, -1
    };
    samFile *in = NULL, *out = NULL;
    sam_hdr_t *header = NULL, *dup_header = NULL;
    bam1_t *aln = bam_init1();
    const int num_refs = sizeof(expected_lengths) / sizeof(expected_lengths[0]);
    const int num_align = sizeof(expected_tids) / sizeof(expected_tids[0]);
    const char *outfname = "test/sam_big_ref.tmp.sam_";
    int i, r;
    char buffer[sizeof(sam_text) + 1024];
    FILE *inf = NULL;
    size_t bytes;

    if (!aln) {
        fail("Out of memory");
        goto cleanup;
    }

    in = sam_open(sam_text, "r");
    if (!in) {
        fail("Opening SAM file");
        goto cleanup;
    }
    out = sam_open(outfname, "w");
    if (!out) {
        fail("Opening output SAM file \"%s\"", outfname);
        goto cleanup;
    }
    header = sam_hdr_read(in);
    if (!header) {
        fail("Reading SAM header");
        goto cleanup;
    }
    if (parse_header) {
        // This will force the header to be parsed
        if (sam_hdr_count_lines(header, "SQ") != num_refs) {
            fail("Wrong number of SQ lines in header");
            goto cleanup;
        }
    }
    if (check_ref_lengths(header, expected_lengths, num_refs, "header") < 0)
        goto cleanup;

    dup_header = sam_hdr_dup(header);
    if (!dup_header) {
        fail("Failed to duplicate header");
    }

    if (check_ref_lengths(dup_header, expected_lengths,
                          num_refs, "duplicate header") < 0)
        goto cleanup;

    if (sam_hdr_count_lines(dup_header, "SQ") != num_refs) {
        fail("Wrong number of SQ lines in duplicate header");
        goto cleanup;
    }

    if (check_ref_lengths(dup_header, expected_lengths,
                          num_refs, "parsed duplicate header") < 0)
        goto cleanup;

    if (sam_hdr_write(out, header) < 0) {
        fail("Failed to write SAM header");
        goto cleanup;
    }
    i = 0;
    while ((r = sam_read1(in, header, aln)) >= 0) {
        if (i >= num_align) {
            fail("Too many alignment records.\n");
            goto cleanup;
        }
        if (aln->core.tid != expected_tids[i]) {
            fail("Wrong tid for record %d : expected %d got %d\n",
                 i, expected_tids[i], aln->core.tid);
            goto cleanup;
        }
        if (aln->core.mtid != expected_mtid[i]) {
            fail("Wrong mate tid for record %d : expected %d got %d\n",
                 i, expected_mtid[i], aln->core.mtid);
            goto cleanup;
        }
        if (aln->core.pos != expected_positions[i]) {
            fail("Wrong position for record %d : "
                 "expected %"PRIhts_pos" got %"PRIhts_pos"\n",
                 i, expected_positions[i], aln->core.pos);
        }
        if (aln->core.mpos != expected_mpos[i]) {
            fail("Wrong mate position for record %d : "
                 "expected %"PRIhts_pos" got %"PRIhts_pos"\n",
                 i, expected_mpos[i], aln->core.mpos);
        }
        if (sam_write1(out, header, aln) < 0) {
            fail("Failed to write alignment record %d\n", i);
            goto cleanup;
        }
        i++;
    }
    if (r < -1) {
        fail("Error reading SAM alignment\n");
        goto cleanup;
    }
    if (i < num_align) {
        fail("Not enough alignment records\n");
        goto cleanup;
    }
    r = sam_close(in); in = NULL;
    if (r < 0) {
        fail("sam_close(in)");
        goto cleanup;
    }
    r = sam_close(out); out = NULL;
    if (r < 0) {
        fail("sam_close(out)");
        goto cleanup;
    }

    inf = fopen(outfname, "r");
    if (!inf) {
        fail("Opening \"%s\"", outfname);
        goto cleanup;
    }
    bytes = fread(buffer, 1, sizeof(buffer), inf);
    if (bytes != sizeof(sam_text) - 7
        || memcmp(buffer, sam_text + 6, bytes - 7) != 0) {
        fail("Output file does not match original version");
        fprintf(stderr,
                "---------- Expected:\n%.*s\n"
                "++++++++++ Got:\n%.*s\n"
                "====================\n",
                (int) sizeof(sam_text) - 7, sam_text + 6,
                (int) bytes, buffer);
        goto cleanup;
    }

 cleanup:
    bam_destroy1(aln);
    sam_hdr_destroy(header);
    sam_hdr_destroy(dup_header);
    if (in) sam_close(in);
    if (out) sam_close(out);
    if (inf) fclose(inf);
    unlink(outfname);
    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x668, %rsp            # imm = 0x668
movl %edi, %ebp
pxor %xmm0, %xmm0
movdqa %xmm0, 0x10(%rsp)
movdqa %xmm0, 0x20(%rsp)
movdqa %xmm0, 0x30(%rsp)
movabsq $0x12a05ee17, %rax      # imm = 0x12A05EE17
movq %rax, 0x10(%rsp)
movabsq $0x3ffffffffffffff6, %rax # imm = 0x3FFFFFFFFFFFFFF6
leaq -0x37f(%rax), %rcx
movq %rcx, 0x20(%rsp)
movq %rax, 0x30(%rsp)
movq $0x1, 0x38(%rsp)
movdqa %xmm0, 0x50(%rsp)
movdqa %xmm0, 0x60(%rsp)
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x40(%rsp)
movq $-0x1, %rcx
movq %rcx, 0x50(%rsp)
movq %rax, 0x58(%rsp)
movq %rcx, 0x68(%rsp)
callq 0x28947
movq %rax, %rbx
testq %rax, %rax
je 0xb229
leaq 0x8fb14(%rip), %rdi     # 0x9aab0
leaq 0x94798(%rip), %rsi     # 0x9f73b
callq 0x1b857
testq %rax, %rax
je 0xb232
movq %rax, %r13
leaq 0x8dae4(%rip), %rdi     # 0x98a9f
leaq 0x939f1(%rip), %rsi     # 0x9e9b3
callq 0x1b857
testq %rax, %rax
je 0xb2ab
movq %rax, %r15
movq %r13, %rdi
callq 0x2b6fd
testq %rax, %rax
je 0xb2ce
movq %rax, %r14
testl %ebp, %ebp
je 0xb003
leaq 0x8cda8(%rip), %rsi     # 0x97d9a
movq %r14, %rdi
callq 0x13c45
cmpl $0x4, %eax
jne 0xb2e7
leaq 0x901d6(%rip), %rsi     # 0x9b1e0
leaq 0x9387c(%rip), %rdx     # 0x9e88d
movq %r14, %rdi
callq 0xc255
testl %eax, %eax
js 0xb170
movq %r14, %rdi
callq 0x28119
movq %rax, %r12
testq %rax, %rax
je 0xb2fd
leaq 0x901a4(%rip), %rsi     # 0x9b1e0
leaq 0x8db37(%rip), %rdx     # 0x98b7a
movq %r12, %rdi
callq 0xc255
testl %eax, %eax
js 0xb173
leaq 0x8cd40(%rip), %rsi     # 0x97d9a
movq %r12, %rdi
callq 0x13c45
cmpl $0x4, %eax
jne 0xb310
leaq 0x9016e(%rip), %rsi     # 0x9b1e0
leaq 0x8dafa(%rip), %rdx     # 0x98b73
movq %r12, %rdi
callq 0xc255
testl %eax, %eax
js 0xb173
movq %r15, %rdi
movq %r14, %rsi
callq 0x2ca7e
testl %eax, %eax
js 0xb35b
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2f8d9
testl %eax, %eax
js 0xb18e
movq %r12, %rax
movq %r15, %r12
movq %rax, 0x8(%rsp)
movq $-0x1, %r15
xorl %ebp, %ebp
cmpq $0x5, %r15
je 0xb3ca
movl 0x8(%rbx), %ecx
leaq 0x8fbd6(%rip), %rax     # 0x9acb0
movl (%rbp,%rax), %edx
cmpl %edx, %ecx
jne 0xb3dc
movl 0x1c(%rbx), %ecx
leaq 0x8fbe0(%rip), %rax     # 0x9acd0
movl (%rbp,%rax), %edx
cmpl %edx, %ecx
jne 0xb3e8
movq (%rbx), %rcx
movq 0x18(%rsp,%r15,8), %rdx
cmpq %rdx, %rcx
jne 0xb148
movq 0x20(%rbx), %rcx
movq 0x48(%rsp,%r15,8), %rdx
cmpq %rdx, %rcx
jne 0xb15c
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x330c3
testl %eax, %eax
js 0xb400
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2f8d9
incq %r15
addq $0x4, %rbp
testl %eax, %eax
jns 0xb0c6
jmp 0xb17a
leal 0x1(%r15), %esi
leaq 0x8dad1(%rip), %rdi     # 0x98c24
xorl %eax, %eax
callq 0x49e0
jmp 0xb109
leal 0x1(%r15), %esi
leaq 0x8daf2(%rip), %rdi     # 0x98c59
xorl %eax, %eax
callq 0x49e0
jmp 0xb117
xorl %r12d, %r12d
xorl %ebp, %ebp
jmp 0xb24e
cmpq $0x5, %r15
setb %cl
movq 0x8(%rsp), %rdx
movq %r12, %r15
movq %rdx, %r12
jmp 0xb190
movb $0x1, %cl
cmpl $-0x1, %eax
jne 0xb364
testb %cl, %cl
jne 0xb36d
movq %r13, %rdi
callq 0x1cac1
testl %eax, %eax
js 0xb382
movq %r15, %rdi
callq 0x1cac1
testl %eax, %eax
js 0xb397
leaq 0x8d8d7(%rip), %rdi     # 0x98a9f
leaq 0x9456c(%rip), %rsi     # 0x9f73b
callq 0x45b0
testq %rax, %rax
je 0xb3ad
movq %rax, %rbp
leaq 0x70(%rsp), %rdi
movl $0x1, %esi
movl $0x5f4, %edx            # imm = 0x5F4
movq %rax, %rcx
callq 0x4790
movq %rax, %r15
cmpq $0x1ed, %rax            # imm = 0x1ED
jne 0xb319
leaq 0x8f8a9(%rip), %rsi     # 0x9aab6
leaq 0x70(%rsp), %rdi
movl $0x1e6, %edx            # imm = 0x1E6
callq 0x44c0
testl %eax, %eax
jne 0xb319
xorl %r15d, %r15d
jmp 0xb24b
leaq 0x8d889(%rip), %rdi     # 0x98ab9
jmp 0xb239
leaq 0x8d88e(%rip), %rdi     # 0x98ac7
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x49e0
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %r13d, %r13d
movq %rbx, %rdi
callq 0x28a24
movq %r14, %rdi
callq 0x27fc6
movq %r12, %rdi
callq 0x27fc6
testq %r13, %r13
je 0xb273
movq %r13, %rdi
callq 0x1cac1
testq %r15, %r15
je 0xb280
movq %r15, %rdi
callq 0x1cac1
testq %rbp, %rbp
je 0xb28d
movq %rbp, %rdi
callq 0x44a0
leaq 0x8d80b(%rip), %rdi     # 0x98a9f
callq 0x41f0
addq $0x668, %rsp            # imm = 0x668
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8d826(%rip), %rdi     # 0x98ad8
leaq 0x8d7e6(%rip), %rsi     # 0x98a9f
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x49e0
xorl %r14d, %r14d
xorl %r15d, %r15d
jmp 0xb173
leaq 0x8d820(%rip), %rdi     # 0x98af5
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x49e0
xorl %r14d, %r14d
jmp 0xb173
leaq 0x8d81a(%rip), %rdi     # 0x98b08
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x49e0
jmp 0xb173
leaq 0x8d827(%rip), %rdi     # 0x98b2b
xorl %eax, %eax
callq 0x49e0
jmp 0xb035
leaq 0x8d82f(%rip), %rdi     # 0x98b46
jmp 0xb374
leaq 0x8d9fd(%rip), %rdi     # 0x98d1d
xorl %eax, %eax
callq 0x49e0
movq 0xb0cb2(%rip), %rax     # 0xbbfe0
movq (%rax), %rdi
leaq 0x8cdd2(%rip), %rsi     # 0x9810a
leaq 0x8f777(%rip), %rcx     # 0x9aab6
leaq 0x70(%rsp), %r9
movl $0x1ed, %edx            # imm = 0x1ED
movl %r15d, %r8d
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x4700
jmp 0xb24b
leaq 0x8d829(%rip), %rdi     # 0x98b8b
jmp 0xb374
leaq 0x8d94d(%rip), %rdi     # 0x98cb8
jmp 0xb374
leaq 0x8d961(%rip), %rdi     # 0x98cd5
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x49e0
jmp 0xb24e
leaq 0x8d96a(%rip), %rdi     # 0x98cf3
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x49e0
jmp 0xb24b
leaq 0x8d963(%rip), %rdi     # 0x98d01
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x49e0
jmp 0xb249
leaq 0x8d95c(%rip), %rdi     # 0x98d10
leaq 0x8d6e4(%rip), %rsi     # 0x98a9f
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x49e0
jmp 0xb249
leaq 0x8d7d5(%rip), %rdi     # 0x98ba6
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x49e0
jmp 0xb416
incl %r15d
leaq 0x8d7dd(%rip), %rdi     # 0x98bc3
jmp 0xb3f2
incl %r15d
leaq 0x8d7ff(%rip), %rdi     # 0x98bf1
xorl %ebp, %ebp
movl %r15d, %esi
xorl %eax, %eax
callq 0x49e0
jmp 0xb416
incl %r15d
leaq 0x8d889(%rip), %rdi     # 0x98c93
xorl %ebp, %ebp
movl %r15d, %esi
xorl %eax, %eax
callq 0x49e0
movq 0x8(%rsp), %rax
movq %r12, %r15
movq %rax, %r12
jmp 0xb24e