// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/test/sam.c
// Function: test_header_updates
static void test_header_updates(void) {
    static const char header_text[] =
        "@HD\tVN:1.4\n"
        "@SQ\tSN:chr1\tLN:100\n"
        "@SQ\tSN:chr2\tLN:200\n"
        "@SQ\tSN:chr3\tLN:300\n"
        "@RG\tID:run1\n"
        "@RG\tID:run2\n"
        "@RG\tID:run3\n"
        "@PG\tID:prog1\tPN:prog1\n";

    static const char expected[] =
        "@HD\tVN:1.4\n"
        "@SQ\tSN:1\tLN:100\n"
        "@SQ\tSN:chr2\tLN:2000\n"
        "@SQ\tSN:chr3\tLN:300\n"
        "@RG\tID:run1\tDS:hello\n"
        "@RG\tID:aliquot2\n"
        "@RG\tID:run3\n"
        "@PG\tID:prog1\tPN:prog1\n";

    static const char *expected_targets[] = { "1", "chr2", "chr3" };
    static const int   expected_lengths[] = { 100, 2000, 300 };
    const int expected_n_targets = sizeof(expected_targets) / sizeof(char *);

    sam_hdr_t *header = sam_hdr_parse(sizeof(header_text) - 1, header_text);
    const char *hdr_str;
    int r, i, old_log_level;

    if (!header) {
        fail("creating sam header");
        goto err;
    }

    if (sam_hdr_name2tid(header, "chr1") != 0) { // Should now be unknown
        fail("sam_hdr_name2tid(\"chr1\") != 0");
        goto err;
    }

    r = sam_hdr_update_line(header, "SQ", "SN", "chr2", "LN", "2000", NULL);
    if (r != 0) { fail("sam_hdr_update_line SQ SN chr2 LN 2000"); goto err; }
    r = sam_hdr_update_line(header, "SQ", "SN", "chr1", "SN", "1", NULL);
    if (r != 0) { fail("sam_hdr_update_line SQ SN chr1 SN 1"); goto err; }
    r = sam_hdr_update_line(header, "RG", "ID", "run1", "DS", "hello", NULL);
    if (r != 0) { fail("sam_hdr_update_line RG ID run1 DS hello"); goto err; }
    r = sam_hdr_update_line(header, "RG", "ID", "run2", "ID", "aliquot2", NULL);
    if (r != 0) { fail("sam_hdr_update_line RG ID run2 ID aliquot2"); goto err; }

    // These should fail
    old_log_level = hts_get_log_level();
    hts_set_log_level(HTS_LOG_OFF);

    r = sam_hdr_update_line(header, "PG", "ID", "prog1", "ID", "prog2", NULL);
    if (r == 0) { fail("sam_hdr_update_line PG ID prog1 ID prog2"); goto err; }

    r = sam_hdr_update_line(header, "SQ", "SN", "chr3", "SN", "chr2", NULL);
    if (r == 0) { fail("sam_hdr_update_line SQ SN chr3 SN chr2"); goto err; }

    r = sam_hdr_update_line(header, "RG", "ID", "run3", "ID", "run1", NULL);
    if (r == 0) { fail("sam_hdr_update_line RG ID run3 ID run1"); goto err; }

    hts_set_log_level(old_log_level);
    // End failing tests

    if (check_target_names(header, expected_n_targets, expected_targets,
                           expected_lengths) < 0) {
        goto err;
    }

    for (i = 0; i < expected_n_targets; i++) {
        if (sam_hdr_name2tid(header, expected_targets[i]) != i) {
            fail("sam_hdr_name2tid unexpected result");
            goto err;
        }
    }
    if (sam_hdr_name2tid(header, "chr1") != -1) { // Should now be unknown
        fail("sam_hdr_name2tid(\"chr1\") != -1");
        goto err;
    }

    hdr_str = sam_hdr_str(header);
    if (!hdr_str || strcmp(hdr_str, expected) != 0) {
        fail("edited header does not match expected version");
        fprintf(stderr,
                "---------- Expected:\n%s\n"
                "++++++++++ Got:\n%s\n"
                "====================\n",
                expected, hdr_str ? hdr_str : "<NULL>");
        goto err;
    }

 err:
    sam_hdr_destroy(header);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x3, -0x4(%rbp)
movl $0x7e, %edi
leaq 0xe7825(%rip), %rsi     # 0xf0050
callq 0x3c940
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x884e
leaq 0xe9690(%rip), %rdi     # 0xf1ed2
movb $0x0, %al
callq 0x5b50
jmp 0x8be1
movq -0x10(%rbp), %rdi
leaq 0xe968d(%rip), %rsi     # 0xf1ee6
callq 0x18e40
cmpl $0x0, %eax
je 0x8876
leaq 0xe9681(%rip), %rdi     # 0xf1eeb
movb $0x0, %al
callq 0x5b50
jmp 0x8be1
movq -0x10(%rbp), %rdi
leaq 0xe8ec1(%rip), %rsi     # 0xf1742
leaq 0xe8e7b(%rip), %rdx     # 0xf1703
leaq 0xe9763(%rip), %rcx     # 0xf1ff2
leaq 0xe8e70(%rip), %r8      # 0xf1706
leaq 0xe968e(%rip), %r9      # 0xf1f2b
xorl %eax, %eax
movq $0x0, (%rsp)
movb $0x0, %al
callq 0x159f0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x88ca
leaq 0xe964b(%rip), %rdi     # 0xf1f09
movb $0x0, %al
callq 0x5b50
jmp 0x8be1
movq -0x10(%rbp), %rdi
leaq 0xe8e6d(%rip), %rsi     # 0xf1742
leaq 0xe8e27(%rip), %r8      # 0xf1703
leaq 0xe9603(%rip), %rcx     # 0xf1ee6
leaq 0xea785(%rip), %r9      # 0xf306f
xorl %eax, %eax
movq %r8, %rdx
movq $0x0, (%rsp)
movb $0x0, %al
callq 0x159f0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x891a
leaq 0xe9622(%rip), %rdi     # 0xf1f30
movb $0x0, %al
callq 0x5b50
jmp 0x8be1
movq -0x10(%rbp), %rdi
leaq 0xe8e56(%rip), %rsi     # 0xf177b
leaq 0xe8e52(%rip), %rdx     # 0xf177e
leaq 0xe96e6(%rip), %rcx     # 0xf2019
leaq 0xecb63(%rip), %r8      # 0xf549d
leaq 0xe9635(%rip), %r9      # 0xf1f76
xorl %eax, %eax
movq $0x0, (%rsp)
movb $0x0, %al
callq 0x159f0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x896e
leaq 0xe95f2(%rip), %rdi     # 0xf1f54
movb $0x0, %al
callq 0x5b50
jmp 0x8be1
movq -0x10(%rbp), %rdi
leaq 0xe8e02(%rip), %rsi     # 0xf177b
leaq 0xe8dfe(%rip), %r8      # 0xf177e
leaq 0xe8dfa(%rip), %rcx     # 0xf1781
leaq 0xe9610(%rip), %r9      # 0xf1f9e
xorl %eax, %eax
movq %r8, %rdx
movq $0x0, (%rsp)
movb $0x0, %al
callq 0x159f0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x89be
leaq 0xe95ca(%rip), %rdi     # 0xf1f7c
movb $0x0, %al
callq 0x5b50
jmp 0x8be1
callq 0x2ee00
movl %eax, -0x24(%rbp)
xorl %edi, %edi
callq 0x2ede0
movq -0x10(%rbp), %rdi
leaq 0xe8fe3(%rip), %rsi     # 0xf19bb
leaq 0xe8d9f(%rip), %r8      # 0xf177e
leaq 0xe91c9(%rip), %rcx     # 0xf1baf
leaq 0xe95dd(%rip), %r9      # 0xf1fca
xorl %eax, %eax
movq %r8, %rdx
movq $0x0, (%rsp)
movb $0x0, %al
callq 0x159f0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x8a1d
leaq 0xe9596(%rip), %rdi     # 0xf1fa7
movb $0x0, %al
callq 0x5b50
jmp 0x8be1
movq -0x10(%rbp), %rdi
leaq 0xe8d1a(%rip), %rsi     # 0xf1742
leaq 0xe8cd4(%rip), %r8      # 0xf1703
leaq 0xe9497(%rip), %rcx     # 0xf1ecd
leaq 0xe95b5(%rip), %r9      # 0xf1ff2
xorl %eax, %eax
movq %r8, %rdx
movq $0x0, (%rsp)
movb $0x0, %al
callq 0x159f0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x8a6d
leaq 0xe956f(%rip), %rdi     # 0xf1fd0
movb $0x0, %al
callq 0x5b50
jmp 0x8be1
movq -0x10(%rbp), %rdi
leaq 0xe8d03(%rip), %rsi     # 0xf177b
leaq 0xe8cff(%rip), %r8      # 0xf177e
leaq 0xe8d59(%rip), %rcx     # 0xf17df
leaq 0xe958c(%rip), %r9      # 0xf2019
xorl %eax, %eax
movq %r8, %rdx
movq $0x0, (%rsp)
movb $0x0, %al
callq 0x159f0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x8abd
leaq 0xe9546(%rip), %rdi     # 0xf1ff7
movb $0x0, %al
callq 0x5b50
jmp 0x8be1
movl -0x24(%rbp), %edi
callq 0x2ede0
movq -0x10(%rbp), %rdi
movl $0x3, %esi
leaq 0x108a5b(%rip), %rdx    # 0x111530
leaq 0xe7680(%rip), %rcx     # 0xf015c
callq 0xd9f0
cmpl $0x0, %eax
jge 0x8aeb
jmp 0x8be1
movl $0x0, -0x20(%rbp)
cmpl $0x3, -0x20(%rbp)
jge 0x8b35
movq -0x10(%rbp), %rdi
movslq -0x20(%rbp), %rcx
leaq 0x108a29(%rip), %rax    # 0x111530
movq (%rax,%rcx,8), %rsi
callq 0x18e40
cmpl -0x20(%rbp), %eax
je 0x8b28
leaq 0xe9502(%rip), %rdi     # 0xf201e
movb $0x0, %al
callq 0x5b50
jmp 0x8be1
jmp 0x8b2a
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x8af2
movq -0x10(%rbp), %rdi
leaq 0xe93a6(%rip), %rsi     # 0xf1ee6
callq 0x18e40
cmpl $-0x1, %eax
je 0x8b5d
leaq 0xe94f0(%rip), %rdi     # 0xf2041
movb $0x0, %al
callq 0x5b50
jmp 0x8be1
movq -0x10(%rbp), %rdi
callq 0x13c70
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x8b86
movq -0x18(%rbp), %rdi
leaq 0xe7554(%rip), %rsi     # 0xf00d0
callq 0x4690
cmpl $0x0, %eax
je 0x8bdf
leaq 0xe8ef7(%rip), %rdi     # 0xf1a84
movb $0x0, %al
callq 0x5b50
movq 0x108445(%rip), %rax    # 0x110fe0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x8bb3
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x8bc0
leaq 0xe94a6(%rip), %rax     # 0xf2060
movq %rax, -0x38(%rbp)
jmp 0x8bc0
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rcx
leaq 0xe90c5(%rip), %rsi     # 0xf1c94
leaq 0xe74fa(%rip), %rdx     # 0xf00d0
movb $0x0, %al
callq 0x46d0
jmp 0x8be1
jmp 0x8be1
movq -0x10(%rbp), %rdi
callq 0x36f50
addq $0x40, %rsp
popq %rbp
retq