// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/header.c
// Function: sam_hdr_add_pg
int sam_hdr_add_pg(sam_hdr_t *bh, const char *name, ...) {
    sam_hrecs_t *hrecs;
    const char *specified_id = NULL, *specified_pn = NULL, *specified_pp = NULL;
    const char *key, *val;
    if (!bh)
        return -1;

    if (!(hrecs = bh->hrecs)) {
        if (sam_hdr_fill_hrecs(bh) != 0)
            return -1;
        hrecs = bh->hrecs;
    }

    bh->hrecs->pgs_changed = 1;
    if (sam_hdr_link_pg(bh) < 0) {
        hts_log_error("Error linking @PG lines");
        return -1;
    }

    va_list args;
    // Check for ID / PN / PP tags in varargs list
    va_start(args, name);
    while ((key = va_arg(args, const char *)) != NULL) {
        val = va_arg(args, const char *);
        if (!val) break;
        if (strcmp(key, "PN") == 0 && *val != '\0')
            specified_pn = val;
        else if (strcmp(key, "PP") == 0 && *val != '\0')
            specified_pp = val;
        else if (strcmp(key, "ID") == 0 && *val != '\0')
            specified_id = val;
    }
    va_end(args);

    if (specified_id && hrecs->pg_hash) {
        khint_t k = kh_get(m_s2i, hrecs->pg_hash, specified_id);
        if (k != kh_end(hrecs->pg_hash)) {
            hts_log_error("Header @PG ID:%s already present", specified_id);
            return -1;
        }
    }

    if (specified_pp && hrecs->pg_hash) {
        khint_t k = kh_get(m_s2i, hrecs->pg_hash, specified_pp);
        if (k == kh_end(hrecs->pg_hash)) {
            hts_log_error("Header @PG ID:%s referred to by PP tag not present",
                          specified_pp);
            return -1;
        }
    }

    if (!specified_pp && hrecs->npg_end) {
        /* Copy ends array to avoid us looping while modifying it */
        int *end = malloc(hrecs->npg_end * sizeof(int));
        int i, nends = hrecs->npg_end;

        if (!end)
            return -1;

        memcpy(end, hrecs->pg_end, nends * sizeof(*end));

        for (i = 0; i < nends; i++) {
            const char *id = !specified_id ? sam_hdr_pg_id(bh, name) : "";
            if (!id) {
                free(end);
                return -1;
            }
            assert(end[i] >= 0 && end[i] < hrecs->npg);
            va_start(args, name);
            if (-1 == sam_hrecs_vadd(hrecs, "PG", args,
                                     "ID", id,
                                     "PN", !specified_pn ? name : "",
                                     "PP", hrecs->pg[end[i]].name,
                                     NULL)) {
                free(end);
                return  -1;
            }
            va_end(args);
        }

        free(end);
    } else {
        const char *id = !specified_id ? sam_hdr_pg_id(bh, name) : "";
        if (!id)
            return -1;
        va_start(args, name);
        if (-1 == sam_hrecs_vadd(hrecs, "PG", args,
                                 "ID", id,
                                 "PN", !specified_pn ? name : "",
                                 NULL))
            return -1;
        va_end(args);
    }

    hrecs->dirty = 1;
    redact_header_text(bh);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdx, 0x50(%rsp)
movq %rcx, 0x58(%rsp)
movq %r8, 0x60(%rsp)
movq %r9, 0x68(%rsp)
testb %al, %al
je 0x6d1c2
movaps %xmm0, 0x70(%rsp)
movaps %xmm1, 0x80(%rsp)
movaps %xmm2, 0x90(%rsp)
movaps %xmm3, 0xa0(%rsp)
movaps %xmm4, 0xb0(%rsp)
movaps %xmm5, 0xc0(%rsp)
movaps %xmm6, 0xd0(%rsp)
movaps %xmm7, 0xe0(%rsp)
pushq $-0x1
popq %rbp
testq %rdi, %rdi
je 0x6d567
movq %rsi, %r15
movq %rdi, %rbx
movq 0x38(%rdi), %r14
testq %r14, %r14
je 0x6d34c
movl $0x1, 0x98(%r14)
movq %rbx, %rdi
callq 0x69e29
testl %eax, %eax
js 0x6d365
movq %r15, 0x30(%rsp)
leaq 0x40(%rsp), %r12
movq %r12, 0x20(%rsp)
leaq 0x130(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, 0x10(%rsp)
pushq $0x10
popq %rax
xorl %r13d, %r13d
xorl %r8d, %r8d
xorl %ebp, %ebp
cmpl $0x28, %eax
ja 0x6d248
movq %rcx, %rsi
movl %eax, %ecx
addq %r12, %rcx
addl $0x8, %eax
movl %eax, 0x10(%rsp)
jmp 0x6d251
leaq 0x8(%rcx), %rsi
movq %rsi, 0x18(%rsp)
movq (%rcx), %rdx
testq %rdx, %rdx
je 0x6d2e7
cmpl $0x28, %eax
ja 0x6d273
movq %rsi, %rcx
movl %eax, %esi
addq %r12, %rsi
addl $0x8, %eax
movl %eax, 0x10(%rsp)
jmp 0x6d27c
leaq 0x8(%rsi), %rcx
movq %rcx, 0x18(%rsp)
movq (%rsi), %rsi
testq %rsi, %rsi
je 0x6d2e7
movzbl (%rdx), %edi
cmpl $0x49, %edi
je 0x6d2bf
cmpl $0x50, %edi
jne 0x6d232
cmpb $0x4e, 0x1(%rdx)
jne 0x6d2a2
cmpb $0x0, 0x2(%rdx)
jne 0x6d2a2
cmpb $0x0, (%rsi)
jne 0x6d2df
cmpb $0x50, 0x1(%rdx)
jne 0x6d232
cmpb $0x0, 0x2(%rdx)
jne 0x6d232
cmpb $0x0, (%rsi)
je 0x6d232
movq %rsi, %r13
jmp 0x6d232
cmpb $0x44, 0x1(%rdx)
jne 0x6d232
cmpb $0x0, 0x2(%rdx)
jne 0x6d232
cmpb $0x0, (%rsi)
cmovneq %rsi, %rbp
jmp 0x6d232
movq %rsi, %r8
jmp 0x6d232
movq %r8, (%rsp)
testq %rbp, %rbp
je 0x6d30d
movq 0x70(%r14), %r15
testq %r15, %r15
je 0x6d30d
movq %r15, %rdi
movq %rbp, %rsi
callq 0x6b87d
cmpl (%r15), %eax
jne 0x6d549
testq %r13, %r13
je 0x6d382
movq 0x70(%r14), %r15
testq %r15, %r15
je 0x6d4a8
movq %r15, %rdi
movq %r13, %rsi
callq 0x6b87d
cmpl (%r15), %eax
jne 0x6d4a8
leaq 0x165a6(%rip), %rsi     # 0x838e0
leaq 0x165ed(%rip), %rdx     # 0x8392e
pushq $0x1
popq %rdi
movq %r13, %rcx
jmp 0x6d55d
movq %rbx, %rdi
callq 0x6933d
testl %eax, %eax
jne 0x6d567
movq 0x38(%rbx), %r14
jmp 0x6d1e1
leaq 0x16574(%rip), %rsi     # 0x838e0
leaq 0x1657c(%rip), %rdx     # 0x838ef
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
jmp 0x6d567
movslq 0x60(%r14), %r15
testq %r15, %r15
je 0x6d4a8
movq %rbp, 0x38(%rsp)
leaq (,%r15,4), %r13
movq %r13, %rdi
callq 0x4680
pushq $-0x1
popq %rbp
testq %rax, %rax
je 0x6d567
movq 0x78(%r14), %rsi
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq %r13, %rdx
callq 0x43c0
cmpq $0x0, (%rsp)
leaq 0xa986(%rip), %rax      # 0x77d56
cmoveq 0x30(%rsp), %rax
movq %rax, (%rsp)
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
xorl %r13d, %r13d
cmpq %r13, %r15
je 0x6d587
leaq 0xa960(%rip), %rax      # 0x77d56
cmpq $0x0, 0x38(%rsp)
jne 0x6d414
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
callq 0x6d050
testq %rax, %rax
je 0x6d57b
movq 0x8(%rsp), %rcx
movslq (%rcx,%r13,4), %r10
testq %r10, %r10
js 0x6d593
cmpl 0x58(%r14), %r10d
jge 0x6d593
movq %r12, 0x20(%rsp)
leaq 0x130(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movabsq $0x3000000010, %rcx     # imm = 0x3000000010
movq %rcx, 0x10(%rsp)
movq 0x68(%r14), %r11
shlq $0x5, %r10
movq %r14, %rdi
leaq 0x16227(%rip), %rsi     # 0x8368a
leaq 0x10(%rsp), %rdx
leaq 0xcbe7(%rip), %rcx      # 0x7a056
movq %rax, %r8
leaq 0x1648e(%rip), %r9      # 0x83907
xorl %eax, %eax
pushq $0x0
pushq (%r11,%r10)
leaq 0x16482(%rip), %r10     # 0x8390a
pushq %r10
pushq 0x18(%rsp)
callq 0x6a316
addq $0x20, %rsp
cmpl $-0x1, %eax
je 0x6d57b
incq %r13
jmp 0x6d3e6
leaq 0xa8a7(%rip), %r15      # 0x77d56
movq %r15, %r8
testq %rbp, %rbp
movq 0x30(%rsp), %r13
jne 0x6d4d3
movq %rbx, %rdi
movq %r13, %rsi
callq 0x6d050
movq %rax, %r8
testq %rax, %rax
je 0x6d564
leaq 0x10(%rsp), %rdx
movq %r12, 0x10(%rdx)
leaq 0x130(%rsp), %rax
movq %rax, 0x8(%rdx)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rdx)
cmpq $0x0, (%rsp)
cmoveq %r13, %r15
subq $0x10, %rsp
andq $0x0, 0x8(%rsp)
movq %r15, (%rsp)
leaq 0x16177(%rip), %rsi     # 0x8368a
leaq 0xcb3c(%rip), %rcx      # 0x7a056
leaq 0x163e6(%rip), %r9      # 0x83907
movq %r14, %rdi
xorl %eax, %eax
callq 0x6a316
popq %rcx
popq %rdx
cmpl $-0x1, %eax
je 0x6d564
movl $0x1, 0x90(%r14)
movq %rbx, %rdi
callq 0x6a1b4
xorl %ebp, %ebp
jmp 0x6d567
leaq 0x16390(%rip), %rsi     # 0x838e0
leaq 0x163b6(%rip), %rdx     # 0x8390d
pushq $0x1
popq %rdi
movq %rbp, %rcx
xorl %eax, %eax
callq 0x110c6
pushq $-0x1
popq %rbp
movl %ebp, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdi
callq 0x45c0
jmp 0x6d567
movq 0x8(%rsp), %rdi
callq 0x45c0
jmp 0x6d532
leaq 0x163c7(%rip), %rdi     # 0x83961
leaq 0x161ba(%rip), %rsi     # 0x8375b
leaq 0x163dc(%rip), %rcx     # 0x83984
movl $0x90e, %edx            # imm = 0x90E
callq 0x42f0