// File: /workspace/github_c_makefile_star2_O2/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)
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, 0x60(%rsp)
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x40(%rsp)
orq $-0x1, 0x50(%rsp)
movq %rax, 0x58(%rsp)
orq $-0x1, 0x68(%rsp)
callq 0x224a4
movq %rax, %rbx
testq %rax, %rax
je 0xaa7f
leaq 0x701fc(%rip), %rdi     # 0x7aab0
leaq 0x74dcf(%rip), %rsi     # 0x7f68a
callq 0x170e7
testq %rax, %rax
je 0xaa88
movq %rax, %r13
leaq 0x6e1cf(%rip), %rdi     # 0x78aa2
leaq 0x74029(%rip), %rsi     # 0x7e903
callq 0x170e7
testq %rax, %rax
je 0xaaa6
movq %rax, %r12
movq %r13, %rdi
callq 0x24c2e
testq %rax, %rax
je 0xaac6
movq %rax, %r14
testl %ebp, %ebp
je 0xa91b
leaq 0x6d493(%rip), %rsi     # 0x77d9d
movq %r14, %rdi
callq 0x116d4
cmpl $0x4, %eax
jne 0xaadc
leaq 0x708be(%rip), %rsi     # 0x7b1e0
leaq 0x73eb4(%rip), %rdx     # 0x7e7dd
movq %r14, %rdi
callq 0xba20
testl %eax, %eax
js 0xaaef
movq %r14, %rdi
callq 0x21d2a
movq %rax, %r15
testq %rax, %rax
jne 0xa957
leaq 0x6e1de(%rip), %rdi     # 0x78b2e
xorl %eax, %eax
callq 0x5b0d
leaq 0x70882(%rip), %rsi     # 0x7b1e0
leaq 0x6e218(%rip), %rdx     # 0x78b7d
movq %r15, %rdi
callq 0xba20
testl %eax, %eax
js 0xaaf2
leaq 0x6d421(%rip), %rsi     # 0x77d9d
movq %r15, %rdi
callq 0x116d4
cmpl $0x4, %eax
jne 0xab51
leaq 0x7084c(%rip), %rsi     # 0x7b1e0
leaq 0x6e1db(%rip), %rdx     # 0x78b76
movq %r15, %rdi
callq 0xba20
testl %eax, %eax
js 0xaaf2
movq %r12, %rdi
movq %r14, %rsi
callq 0x2572d
testl %eax, %eax
js 0xab63
xorl %ebp, %ebp
movq $0x0, 0x8(%rsp)
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x279c2
testl %eax, %eax
js 0xab6c
movq 0x8(%rsp), %rsi
cmpq $0x6, %rsi
je 0xab7a
movl 0x8(%rbx), %ecx
leaq 0x702b8(%rip), %rax     # 0x7acb0
movl (%rbp,%rax), %edx
cmpl %edx, %ecx
jne 0xab83
movl 0x1c(%rbx), %ecx
leaq 0x702c2(%rip), %rax     # 0x7acd0
movl (%rbp,%rax), %edx
cmpl %edx, %ecx
jne 0xab8c
movq (%rbx), %rcx
movq 0x10(%rsp,%rsi,8), %rdx
cmpq %rdx, %rcx
je 0xaa3a
leaq 0x6e1f9(%rip), %rdi     # 0x78c27
xorl %eax, %eax
callq 0x5b0d
movq 0x8(%rsp), %rsi
movq 0x20(%rbx), %rcx
movq 0x40(%rsp,%rsi,8), %rdx
cmpq %rdx, %rcx
je 0xaa5b
leaq 0x6e20d(%rip), %rdi     # 0x78c5c
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x5b0d
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x29349
testl %eax, %eax
js 0xaba1
incq 0x8(%rsp)
addq $0x4, %rbp
jmp 0xa9c9
leaq 0x6e036(%rip), %rdi     # 0x78abc
jmp 0xaa8f
leaq 0x6e03b(%rip), %rdi     # 0x78aca
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x5b0d
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %ebp, %ebp
xorl %r13d, %r13d
jmp 0xaaf4
leaq 0x6e02e(%rip), %rdi     # 0x78adb
leaq 0x6dfee(%rip), %rsi     # 0x78aa2
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x5b0d
xorl %r14d, %r14d
xorl %r12d, %r12d
jmp 0xaaf2
leaq 0x6e02b(%rip), %rdi     # 0x78af8
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x5b0d
xorl %r14d, %r14d
jmp 0xaaf2
leaq 0x6e028(%rip), %rdi     # 0x78b0b
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x5b0d
jmp 0xaaf2
xorl %r15d, %r15d
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x22572
movq %r14, %rdi
callq 0x21bfe
movq %r15, %rdi
callq 0x21bfe
testq %r13, %r13
je 0xab19
movq %r13, %rdi
callq 0x182bd
testq %r12, %r12
je 0xab26
movq %r12, %rdi
callq 0x182bd
testq %rbp, %rbp
je 0xab33
movq %rbp, %rdi
callq 0x44a0
leaq 0x6df68(%rip), %rdi     # 0x78aa2
callq 0x41f0
addq $0x668, %rsp            # imm = 0x668
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6dff1(%rip), %rdi     # 0x78b49
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x5b0d
jmp 0xaaf4
leaq 0x6e024(%rip), %rdi     # 0x78b8e
jmp 0xab58
cmpl $-0x1, %eax
je 0xabbb
leaq 0x6e143(%rip), %rdi     # 0x78cbb
jmp 0xab58
leaq 0x6e028(%rip), %rdi     # 0x78ba9
jmp 0xab58
leaq 0x6e03c(%rip), %rdi     # 0x78bc6
jmp 0xab93
leaq 0x6e061(%rip), %rdi     # 0x78bf4
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x5b0d
jmp 0xaaf4
leaq 0x6e0ee(%rip), %rdi     # 0x78c96
xorl %ebp, %ebp
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x5b0d
jmp 0xaaf4
cmpq $0x5, 0x8(%rsp)
ja 0xabcc
leaq 0x6e10e(%rip), %rdi     # 0x78cd8
jmp 0xab58
movq %r13, %rdi
callq 0x182bd
testl %eax, %eax
js 0xac41
movq %r12, %rdi
callq 0x182bd
testl %eax, %eax
js 0xac56
leaq 0x6deb7(%rip), %rdi     # 0x78aa2
leaq 0x74a98(%rip), %rsi     # 0x7f68a
callq 0x45b0
testq %rax, %rax
je 0xac6c
movq %rax, %rbp
leaq 0x70(%rsp), %rdi
pushq $0x1
popq %rsi
movl $0x5f4, %edx            # imm = 0x5F4
movq %rax, %rcx
callq 0x4790
movq %rax, %r13
cmpq $0x1ed, %rax            # imm = 0x1ED
jne 0xac89
leaq 0x6fe90(%rip), %rsi     # 0x7aab6
leaq 0x70(%rsp), %rdi
movl $0x1e6, %edx            # imm = 0x1E6
callq 0x44c0
testl %eax, %eax
jne 0xac89
xorl %r12d, %r12d
jmp 0xaaa1
leaq 0x6e0ae(%rip), %rdi     # 0x78cf6
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x5b0d
jmp 0xaaa1
leaq 0x6e0a7(%rip), %rdi     # 0x78d04
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x5b0d
jmp 0xaa9f
leaq 0x6e0a0(%rip), %rdi     # 0x78d13
leaq 0x6de28(%rip), %rsi     # 0x78aa2
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x5b0d
jmp 0xaa9f
leaq 0x6e090(%rip), %rdi     # 0x78d20
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x5b0d
movq 0x9733f(%rip), %rax     # 0xa1fe0
movq (%rax), %rdi
leaq 0x6d462(%rip), %rsi     # 0x7810d
leaq 0x6fe04(%rip), %rcx     # 0x7aab6
leaq 0x70(%rsp), %r9
movl $0x1ed, %edx            # imm = 0x1ED
movl %r13d, %r8d
xorl %eax, %eax
callq 0x4700
jmp 0xaaa1