// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/test/sam.c
// Function: test_header_pg_loops
static void test_header_pg_loops(void) {
    static const char *header_texts[2] = {
        // Loop to self
        "data:,"
        "@HD\tVN:1.5\n"
        "@PG\tID:loop1\tPN:prog1\tPP:loop1\n",

        // circuit
        "data:,"
        "@HD\tVN:1.5\n"
        "@PG\tID:loop1\tPN:prog1\tPP:loop2\n"
        "@PG\tID:loop2\tPN:prog2\tPP:loop1\n"
    };

    static const char *expected[2] = {
        "@HD\tVN:1.5\n"
        "@PG\tID:loop1\tPN:prog1\tPP:loop1\n"
        "@PG\tID:new_prog\tPN:new_prog\tPP:loop1\n",

        "@HD\tVN:1.5\n"
        "@PG\tID:loop1\tPN:prog1\tPP:loop2\n"
        "@PG\tID:loop2\tPN:prog2\tPP:loop1\n"
        "@PG\tID:new_prog\tPN:new_prog\n"
    };

    int i, r;
    samFile *in = NULL;
    sam_hdr_t *header = NULL;
    const char *text = NULL;
    enum htsLogLevel old_log_level = hts_get_log_level();

    // Silence header loop warning
    hts_set_log_level(HTS_LOG_OFF);

    for (i = 0; i < 2; i++) {
        in = sam_open(header_texts[i], "r");
        if (!in) {
            fail("couldn't open file for PG loop test %d", i);
            goto err;
        }

        header = sam_hdr_read(in);
        if (!header) {
            fail("reading header for PG loop test %d", i);
            goto err;
        }

        r = sam_hdr_add_pg(header, "new_prog", NULL);
        if (r != 0) {
            fail("sam_hdr_add_pg new_prog for PG loop test %d", i);
            goto err;
        }

        text = sam_hdr_str(header);
        if (!text || strcmp(text, expected[i]) != 0) {
            fail("edited header does not match expected version for PG loop test %d", i);
            fprintf(stderr,
                    "---------- Expected:\n%s\n"
                    "++++++++++ Got:\n%s\n"
                    "====================\n",
                    expected[i], text);
            goto err;
        }
        sam_hdr_destroy(header);
        header = NULL;
        if (in) sam_close(in);
        in = NULL;
    }
    hts_set_log_level(old_log_level);
    return;

 err:
    sam_hdr_destroy(header);
    header = NULL;
    if (in) sam_close(in);
    hts_set_log_level(old_log_level);
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
callq 0x2ee00
movl %eax, -0x24(%rbp)
xorl %edi, %edi
callq 0x2ede0
movl $0x0, -0x4(%rbp)
cmpl $0x2, -0x4(%rbp)
jge 0x87d1
movslq -0x4(%rbp), %rcx
leaq 0x108e75(%rip), %rax    # 0x111510
movq (%rax,%rcx,8), %rdi
leaq 0xef3d2(%rip), %rsi     # 0xf7a78
callq 0x232d0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x86cc
movl -0x4(%rbp), %esi
leaq 0xe974c(%rip), %rdi     # 0xf1e0c
movb $0x0, %al
callq 0x5b50
jmp 0x87db
movq -0x10(%rbp), %rdi
callq 0x3c9b0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x86f6
movl -0x4(%rbp), %esi
leaq 0xe9749(%rip), %rdi     # 0xf1e33
movb $0x0, %al
callq 0x5b50
jmp 0x87db
movq -0x18(%rbp), %rdi
leaq 0xe9755(%rip), %rsi     # 0xf1e56
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0x19250
movl %eax, -0x8(%rbp)
cmpl $0x0, -0x8(%rbp)
je 0x872b
movl -0x4(%rbp), %esi
leaq 0xe9740(%rip), %rdi     # 0xf1e5f
movb $0x0, %al
callq 0x5b50
jmp 0x87db
movq -0x18(%rbp), %rdi
callq 0x13c70
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x875c
movq -0x20(%rbp), %rdi
movslq -0x4(%rbp), %rcx
leaq 0x108dd2(%rip), %rax    # 0x111520
movq (%rax,%rcx,8), %rsi
callq 0x4690
cmpl $0x0, %eax
je 0x879a
movl -0x4(%rbp), %esi
leaq 0xe9725(%rip), %rdi     # 0xf1e8b
movb $0x0, %al
callq 0x5b50
movq 0x10886c(%rip), %rax    # 0x110fe0
movq (%rax), %rdi
movslq -0x4(%rbp), %rcx
leaq 0x108d9e(%rip), %rax    # 0x111520
movq (%rax,%rcx,8), %rdx
movq -0x20(%rbp), %rcx
leaq 0xe9503(%rip), %rsi     # 0xf1c94
movb $0x0, %al
callq 0x46d0
jmp 0x87db
movq -0x18(%rbp), %rdi
callq 0x36f50
movq $0x0, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x87bb
movq -0x10(%rbp), %rdi
callq 0x253f0
movq $0x0, -0x10(%rbp)
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x8686
movl -0x24(%rbp), %edi
callq 0x2ede0
jmp 0x8804
movq -0x18(%rbp), %rdi
callq 0x36f50
movq $0x0, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x87fc
movq -0x10(%rbp), %rdi
callq 0x253f0
movl -0x24(%rbp), %edi
callq 0x2ede0
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)