// File: /workspace/github_c_makefile_star2_O1/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 $0x128, %rsp            # imm = 0x128
movq %rdx, 0x80(%rsp)
movq %rcx, 0x88(%rsp)
movq %r8, 0x90(%rsp)
movq %r9, 0x98(%rsp)
testb %al, %al
je 0x8c17a
movaps %xmm0, 0xa0(%rsp)
movaps %xmm1, 0xb0(%rsp)
movaps %xmm2, 0xc0(%rsp)
movaps %xmm3, 0xd0(%rsp)
movaps %xmm4, 0xe0(%rsp)
movaps %xmm5, 0xf0(%rsp)
movaps %xmm6, 0x100(%rsp)
movaps %xmm7, 0x110(%rsp)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x8c748
movq %rsi, %r14
movq %rdi, %rbx
movq 0x38(%rdi), %rax
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x8c342
movq 0x38(%rbx), %rax
movl $0x1, 0x98(%rax)
movq %rbx, %rdi
callq 0x874af
testl %eax, %eax
js 0x8c360
movq %r14, 0x30(%rsp)
movq %rbx, 0x28(%rsp)
leaq 0x70(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0x160(%rsp), %rbp
movq %rbp, 0x48(%rsp)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, 0x40(%rsp)
movl $0x10, %r14d
movq $0x0, 0x38(%rsp)
leaq 0x18693(%rip), %r15     # 0xa4898
leaq 0xeedc(%rip), %r13      # 0x9b0e8
movq $0x0, 0x60(%rsp)
movq $0x0, 0x8(%rsp)
cmpl $0x28, %r14d
ja 0x8c23d
movq %rbp, %rax
movl %r14d, %ebp
leaq 0x70(%rsp), %rcx
addq %rcx, %rbp
addl $0x8, %r14d
movl %r14d, 0x40(%rsp)
jmp 0x8c246
leaq 0x8(%rbp), %rax
movq %rax, 0x48(%rsp)
movq (%rbp), %r12
testq %r12, %r12
je 0x8c2ec
cmpl $0x28, %r14d
ja 0x8c272
movq %rax, %rbp
movl %r14d, %eax
leaq 0x70(%rsp), %rcx
addq %rcx, %rax
addl $0x8, %r14d
movl %r14d, 0x40(%rsp)
jmp 0x8c27b
leaq 0x8(%rax), %rbp
movq %rbp, 0x48(%rsp)
movq (%rax), %rbx
testq %rbx, %rbx
je 0x8c2ec
movq %r12, %rdi
movq %r15, %rsi
callq 0x46c0
testl %eax, %eax
jne 0x8c297
cmpb $0x0, (%rbx)
jne 0x8c2d8
movq %r12, %rdi
leaq 0x185fa(%rip), %rsi     # 0xa489b
callq 0x46c0
testl %eax, %eax
jne 0x8c2af
cmpb $0x0, (%rbx)
jne 0x8c2e2
movq %r12, %rdi
movq %r13, %rsi
callq 0x46c0
testl %eax, %eax
jne 0x8c21e
cmpb $0x0, (%rbx)
movq 0x8(%rsp), %rax
cmovneq %rbx, %rax
movq %rax, 0x8(%rsp)
jmp 0x8c21e
movq %rbx, 0x60(%rsp)
jmp 0x8c21e
movq %rbx, 0x38(%rsp)
jmp 0x8c21e
movq 0x8(%rsp), %rcx
testq %rcx, %rcx
movq 0x18(%rsp), %rbx
je 0x8c425
movq 0x70(%rbx), %rsi
testq %rsi, %rsi
je 0x8c425
movl (%rsi), %eax
testl %eax, %eax
je 0x8c37f
leal -0x1(%rax), %edi
movb (%rcx), %dl
testb %dl, %dl
movq %rax, 0x20(%rsp)
je 0x8c387
leaq 0x1(%rcx), %rax
movl $0x811c9dc5, %r13d      # imm = 0x811C9DC5
movzbl %dl, %ecx
xorl %r13d, %ecx
imull $0x1000193, %ecx, %r13d # imm = 0x1000193
movb (%rax), %dl
incq %rax
testb %dl, %dl
jne 0x8c32a
jmp 0x8c38d
movq %rbx, %rdi
callq 0x866a8
testl %eax, %eax
jne 0x8c748
movq 0x38(%rbx), %rax
movq %rax, 0x18(%rsp)
jmp 0x8c1a1
leaq 0x1850a(%rip), %rsi     # 0xa4871
leaq 0x18512(%rip), %rdx     # 0xa4880
movl $0x1, %edi
xorl %eax, %eax
callq 0x14378
jmp 0x8c748
xorl %r14d, %r14d
jmp 0x8c41c
movl $0x811c9dc5, %r13d      # imm = 0x811C9DC5
andl %edi, %r13d
movq 0x10(%rsi), %rbx
movl $0x1, %r12d
movl %r13d, %r14d
movl %edi, 0x14(%rsp)
movq %rsi, 0x68(%rsp)
movl %r14d, %eax
shrl $0x4, %eax
movl (%rbx,%rax,4), %ebp
leal (%r14,%r14), %r15d
andl $0x1e, %r15d
movl %ebp, %eax
movl %r15d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x8c400
testb $0x1, %al
jne 0x8c3e8
movq 0x18(%rsi), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x8(%rsp), %rsi
callq 0x46c0
movl 0x14(%rsp), %edi
movq 0x68(%rsp), %rsi
testl %eax, %eax
je 0x8c400
addl %r12d, %r14d
andl %edi, %r14d
incl %r12d
cmpl %r13d, %r14d
jne 0x8c3a6
movq 0x20(%rsp), %rax
movl %eax, %r14d
jmp 0x8c412
movl %r15d, %ecx
shrl %cl, %ebp
testb $0x3, %bpl
movq 0x20(%rsp), %rax
cmovnel %eax, %r14d
movq 0x18(%rsp), %rbx
movq 0x8(%rsp), %rcx
cmpl %eax, %r14d
jne 0x8c5a7
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0x8c47c
movq 0x70(%rbx), %rsi
testq %rsi, %rsi
je 0x8c689
movl (%rsi), %edx
testl %edx, %edx
je 0x8c5bf
leal -0x1(%rdx), %edi
movb (%rax), %cl
testb %cl, %cl
movq %rdx, 0x20(%rsp)
je 0x8c5c7
incq %rax
movl $0x811c9dc5, %r13d      # imm = 0x811C9DC5
movzbl %cl, %ecx
xorl %r13d, %ecx
imull $0x1000193, %ecx, %r13d # imm = 0x1000193
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x8c461
jmp 0x8c5cd
movslq 0x60(%rbx), %r14
testq %r14, %r14
je 0x8c689
leaq (,%r14,4), %r12
movq %r12, %rdi
callq 0x4680
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x8c748
movq %rax, %r15
movq 0x78(%rbx), %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0x43c0
testl %r14d, %r14d
jle 0x8c595
cmpq $0x0, 0x60(%rsp)
leaq 0xc7fd(%rip), %rbp      # 0x98ccd
cmoveq 0x30(%rsp), %rbp
xorl %r12d, %r12d
leaq 0xc7ed(%rip), %r8       # 0x98ccd
cmpq $0x0, 0x8(%rsp)
jne 0x8c4fa
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x8be40
movq %rax, %r8
testq %r8, %r8
je 0x8c75d
movslq (%r15,%r12,4), %r10
testq %r10, %r10
js 0x8c767
cmpl 0x58(%rbx), %r10d
jge 0x8c767
leaq 0x70(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0x160(%rsp), %rax
movq %rax, 0x48(%rsp)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, 0x40(%rsp)
movq 0x68(%rbx), %r11
shlq $0x5, %r10
movq %rbx, %rdi
leaq 0x180c9(%rip), %rsi     # 0xa461b
leaq 0x40(%rsp), %rdx
leaq 0xeb8a(%rip), %rcx      # 0x9b0e8
leaq 0x18333(%rip), %r9      # 0xa4898
xorl %eax, %eax
pushq $0x0
pushq (%r11,%r10)
leaq 0x18327(%rip), %r10     # 0xa489b
pushq %r10
pushq %rbp
callq 0x87b3b
addq $0x20, %rsp
cmpl $-0x1, %eax
je 0x8c75d
incq %r12
cmpq %r12, %r14
jne 0x8c4d9
movq %r15, %rdi
callq 0x45c0
movq 0x28(%rsp), %rbx
jmp 0x8c72e
leaq 0x182c3(%rip), %rsi     # 0xa4871
leaq 0x182e9(%rip), %rdx     # 0xa489e
movl $0x1, %edi
jmp 0x8c677
xorl %r14d, %r14d
jmp 0x8c657
movl $0x811c9dc5, %r13d      # imm = 0x811C9DC5
andl %edi, %r13d
movq 0x10(%rsi), %rbx
movl $0x1, %r15d
movl %r13d, %r14d
movl %edi, 0x14(%rsp)
movq %rsi, 0x68(%rsp)
movl %r14d, %eax
shrl $0x4, %eax
movl (%rbx,%rax,4), %r12d
leal (%r14,%r14), %ebp
andl $0x1e, %ebp
movl %r12d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x8c640
testb $0x1, %al
jne 0x8c628
movq 0x18(%rsi), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x38(%rsp), %rsi
callq 0x46c0
movl 0x14(%rsp), %edi
movq 0x68(%rsp), %rsi
testl %eax, %eax
je 0x8c640
addl %r15d, %r14d
andl %edi, %r14d
incl %r15d
cmpl %r13d, %r14d
jne 0x8c5e6
movq 0x20(%rsp), %rdx
movl %edx, %r14d
jmp 0x8c652
movl %ebp, %ecx
shrl %cl, %r12d
testb $0x3, %r12b
movq 0x20(%rsp), %rdx
cmovnel %edx, %r14d
movq 0x8(%rsp), %rcx
cmpl %edx, %r14d
movq 0x38(%rsp), %rax
jne 0x8c689
leaq 0x18209(%rip), %rsi     # 0xa4871
leaq 0x18250(%rip), %rdx     # 0xa48bf
movl $0x1, %edi
movq %rax, %rcx
xorl %eax, %eax
callq 0x14378
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x8c748
testq %rcx, %rcx
je 0x8c6a1
leaq 0xc638(%rip), %r8       # 0x98ccd
movq 0x28(%rsp), %rbx
movq 0x30(%rsp), %r14
jmp 0x8c6b9
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq 0x30(%rsp), %r14
movq %r14, %rsi
callq 0x8be40
movq %rax, %r8
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testq %r8, %r8
je 0x8c748
leaq 0x40(%rsp), %rdx
leaq 0x70(%rsp), %rax
movq %rax, 0x10(%rdx)
leaq 0x160(%rsp), %rax
movq %rax, 0x8(%rdx)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rdx)
cmpq $0x0, 0x60(%rsp)
leaq 0xc5d1(%rip), %r10      # 0x98ccd
cmoveq %r14, %r10
leaq 0x17f14(%rip), %rsi     # 0xa461b
leaq 0xe9da(%rip), %rcx      # 0x9b0e8
leaq 0x18183(%rip), %r9      # 0xa4898
movq 0x18(%rsp), %rdi
xorl %eax, %eax
pushq $0x0
pushq %r10
callq 0x87b3b
addq $0x10, %rsp
cmpl $-0x1, %eax
je 0x8c748
movq 0x18(%rsp), %rax
movl $0x1, 0x90(%rax)
movq %rbx, %rdi
callq 0x879db
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x45c0
jmp 0x8c748
leaq 0x18184(%rip), %rdi     # 0xa48f2
leaq 0x17f77(%rip), %rsi     # 0xa46ec
leaq 0x18199(%rip), %rcx     # 0xa4915
movl $0x90e, %edx            # imm = 0x90E
callq 0x42f0