// File: /workspace/github_c_makefile_star2_O3/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 $0x118, %rsp            # imm = 0x118
movq %rdx, 0x70(%rsp)
movq %rcx, 0x78(%rsp)
movq %r8, 0x80(%rsp)
movq %r9, 0x88(%rsp)
testb %al, %al
je 0x8983d
movaps %xmm0, 0x90(%rsp)
movaps %xmm1, 0xa0(%rsp)
movaps %xmm2, 0xb0(%rsp)
movaps %xmm3, 0xc0(%rsp)
movaps %xmm4, 0xd0(%rsp)
movaps %xmm5, 0xe0(%rsp)
movaps %xmm6, 0xf0(%rsp)
movaps %xmm7, 0x100(%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x89dc3
movq %rsi, %r14
movq %rdi, %rbx
movq 0x38(%rdi), %rax
testq %rax, %rax
je 0x899df
movq %rax, 0x8(%rsp)
movl $0x1, 0x98(%rax)
movq %rbx, %rdi
callq 0x84ea7
testl %eax, %eax
js 0x899f8
leaq 0x60(%rsp), %r8
movq %r8, 0x30(%rsp)
leaq 0x150(%rsp), %rcx
movq %rcx, 0x28(%rsp)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, 0x20(%rsp)
movl $0x10, %eax
movq $0x0, 0x10(%rsp)
xorl %r10d, %r10d
xorl %r9d, %r9d
cmpl $0x28, %eax
ja 0x898cd
movq %rcx, %rsi
movl %eax, %ecx
addq %r8, %rcx
addl $0x8, %eax
movl %eax, 0x20(%rsp)
jmp 0x898d6
leaq 0x8(%rcx), %rsi
movq %rsi, 0x28(%rsp)
movq (%rcx), %rdx
testq %rdx, %rdx
je 0x8996e
cmpl $0x28, %eax
ja 0x898f8
movq %rsi, %rcx
movl %eax, %esi
addq %r8, %rsi
addl $0x8, %eax
movl %eax, 0x20(%rsp)
jmp 0x89901
leaq 0x8(%rsi), %rcx
movq %rcx, 0x28(%rsp)
movq (%rsi), %rsi
testq %rsi, %rsi
je 0x8996e
movzbl (%rdx), %edi
cmpl $0x49, %edi
je 0x89946
cmpl $0x50, %edi
jne 0x898b7
cmpb $0x4e, 0x1(%rdx)
jne 0x89927
cmpb $0x0, 0x2(%rdx)
jne 0x89927
cmpb $0x0, (%rsi)
jne 0x89966
cmpb $0x50, 0x1(%rdx)
jne 0x898b7
cmpb $0x0, 0x2(%rdx)
jne 0x898b7
cmpb $0x0, (%rsi)
je 0x898b7
movq %rsi, 0x10(%rsp)
jmp 0x898b7
cmpb $0x44, 0x1(%rdx)
jne 0x898b7
cmpb $0x0, 0x2(%rdx)
jne 0x898b7
cmpb $0x0, (%rsi)
cmovneq %rsi, %r9
jmp 0x898b7
movq %rsi, %r10
jmp 0x898b7
movq %r10, 0x50(%rsp)
movq %r14, 0x48(%rsp)
movq %rbx, 0x58(%rsp)
movq %r9, 0x18(%rsp)
testq %r9, %r9
je 0x89aab
movq 0x8(%rsp), %rax
movq 0x70(%rax), %rax
movq %rax, (%rsp)
testq %rax, %rax
je 0x89aab
movq (%rsp), %rax
movl (%rax), %eax
testl %eax, %eax
je 0x89a17
movq %rax, 0x38(%rsp)
leal -0x1(%rax), %ebx
movq 0x18(%rsp), %rax
movb (%rax), %cl
testb %cl, %cl
je 0x89a1f
incq %rax
movl $0x811c9dc5, %r12d      # imm = 0x811C9DC5
movzbl %cl, %ecx
xorl %r12d, %ecx
imull $0x1000193, %ecx, %r12d # imm = 0x1000193
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x899c7
jmp 0x89a25
movq %rbx, %rdi
callq 0x8413e
testl %eax, %eax
jne 0x89dc3
movq 0x38(%rbx), %rax
jmp 0x8985e
leaq 0x185f1(%rip), %rsi     # 0xa1ff0
leaq 0x185f9(%rip), %rdx     # 0xa1fff
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
jmp 0x89dc3
xorl %r14d, %r14d
jmp 0x89aa2
movl $0x811c9dc5, %r12d      # imm = 0x811C9DC5
andl %ebx, %r12d
movq (%rsp), %rax
movq 0x10(%rax), %rsi
movl $0x1, %r13d
movl %r12d, %r14d
movq %rsi, 0x40(%rsp)
movl %r14d, %eax
shrl $0x4, %eax
movl (%rsi,%rax,4), %r15d
leal (%r14,%r14), %ebp
andl $0x1e, %ebp
movl %r15d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x89a90
testb $0x1, %al
jne 0x89a80
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x18(%rsp), %rsi
callq 0x46c0
movq 0x40(%rsp), %rsi
testl %eax, %eax
je 0x89a90
addl %r13d, %r14d
andl %ebx, %r14d
incl %r13d
cmpl %r12d, %r14d
jne 0x89a3e
jmp 0x89aab
movl %ebp, %ecx
shrl %cl, %r15d
testb $0x3, %r15b
movq 0x38(%rsp), %rax
cmovnel %eax, %r14d
cmpl %eax, %r14d
jne 0x89c47
cmpq $0x0, 0x10(%rsp)
je 0x89b12
movq 0x8(%rsp), %rax
movq 0x70(%rax), %rax
movq %rax, (%rsp)
testq %rax, %rax
je 0x89d16
movq (%rsp), %rax
movl (%rax), %edx
testl %edx, %edx
je 0x89c64
leal -0x1(%rdx), %esi
movq 0x10(%rsp), %rax
movb (%rax), %cl
testb %cl, %cl
movq %rdx, 0x38(%rsp)
je 0x89c6c
incq %rax
movl $0x811c9dc5, %r12d      # imm = 0x811C9DC5
movzbl %cl, %ecx
xorl %r12d, %ecx
imull $0x1000193, %ecx, %r12d # imm = 0x1000193
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x89af7
jmp 0x89c72
movq 0x8(%rsp), %rax
movslq 0x60(%rax), %r15
testq %r15, %r15
je 0x89d16
leaq (,%r15,4), %rbx
movq %rbx, %rdi
callq 0x4680
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x89dc3
movq %rax, %r13
movq 0x8(%rsp), %rax
movq 0x78(%rax), %rsi
movq %r13, %rdi
movq %rbx, %rdx
callq 0x43c0
testl %r15d, %r15d
movq 0x58(%rsp), %r14
jle 0x89c3a
cmpq $0x0, 0x50(%rsp)
leaq 0xc1f9(%rip), %rbx      # 0x95d6d
cmoveq 0x48(%rsp), %rbx
xorl %r12d, %r12d
leaq 0xc1e9(%rip), %rax      # 0x95d6d
cmpq $0x0, 0x18(%rsp)
jne 0x89ba2
movq %r14, %rdi
movq 0x48(%rsp), %rsi
callq 0x894fb
testq %rax, %rax
je 0x89dd7
movslq (%r13,%r12,4), %r10
testq %r10, %r10
movq 0x8(%rsp), %rdi
js 0x89de1
cmpl 0x58(%rdi), %r10d
jge 0x89de1
leaq 0x60(%rsp), %rcx
movq %rcx, 0x30(%rsp)
leaq 0x150(%rsp), %rcx
movq %rcx, 0x28(%rsp)
movabsq $0x3000000010, %rcx     # imm = 0x3000000010
movq %rcx, 0x20(%rsp)
movq 0x68(%rdi), %r11
shlq $0x5, %r10
leaq 0x181a6(%rip), %rsi     # 0xa1d9a
leaq 0x20(%rsp), %rdx
leaq 0xe4fb(%rip), %rcx      # 0x980fb
movq %rax, %r8
leaq 0x1840d(%rip), %r9      # 0xa2017
xorl %eax, %eax
pushq $0x0
pushq (%r11,%r10)
leaq 0x18401(%rip), %r10     # 0xa201a
pushq %r10
pushq %rbx
callq 0x85555
addq $0x20, %rsp
cmpl $-0x1, %eax
je 0x89dd7
incq %r12
cmpq %r12, %r15
jne 0x89b7d
movq %r13, %rdi
callq 0x45c0
jmp 0x89da3
leaq 0x183a2(%rip), %rsi     # 0xa1ff0
leaq 0x183c8(%rip), %rdx     # 0xa201d
movl $0x1, %edi
movq 0x18(%rsp), %rcx
jmp 0x89d0a
xorl %r14d, %r14d
jmp 0x89ced
movl $0x811c9dc5, %r12d      # imm = 0x811C9DC5
andl %esi, %r12d
movq (%rsp), %rax
movq 0x10(%rax), %rbx
movl $0x1, %r13d
movl %r12d, %r14d
movl %esi, 0x40(%rsp)
movl %r14d, %eax
shrl $0x4, %eax
movl (%rbx,%rax,4), %r15d
leal (%r14,%r14), %ebp
andl $0x1e, %ebp
movl %r15d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x89cdb
testb $0x1, %al
jne 0x89ccb
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x10(%rsp), %rsi
callq 0x46c0
movl 0x40(%rsp), %esi
testl %eax, %eax
je 0x89cdb
addl %r13d, %r14d
andl %esi, %r14d
incl %r13d
cmpl %r12d, %r14d
jne 0x89c8a
jmp 0x89cf2
movl %ebp, %ecx
shrl %cl, %r15d
testb $0x3, %r15b
movq 0x38(%rsp), %rdx
cmovnel %edx, %r14d
cmpl %edx, %r14d
jne 0x89d16
leaq 0x182f7(%rip), %rsi     # 0xa1ff0
leaq 0x1833e(%rip), %rdx     # 0xa203e
movl $0x1, %edi
movq 0x10(%rsp), %rcx
xorl %eax, %eax
callq 0x13de5
jmp 0x89dbe
leaq 0xc050(%rip), %rbx      # 0x95d6d
movq %rbx, %r8
cmpq $0x0, 0x18(%rsp)
movq 0x58(%rsp), %r14
movq 0x48(%rsp), %r15
jne 0x89d45
movq %r14, %rdi
movq %r15, %rsi
callq 0x894fb
movq %rax, %r8
testq %rax, %rax
je 0x89dbe
leaq 0x20(%rsp), %rdx
leaq 0x60(%rsp), %rax
movq %rax, 0x10(%rdx)
leaq 0x150(%rsp), %rax
movq %rax, 0x8(%rdx)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rdx)
cmpq $0x0, 0x50(%rsp)
cmoveq %r15, %rbx
leaq 0x1801d(%rip), %rsi     # 0xa1d9a
leaq 0xe377(%rip), %rcx      # 0x980fb
leaq 0x1828c(%rip), %r9      # 0xa2017
movq 0x8(%rsp), %rdi
xorl %eax, %eax
pushq $0x0
pushq %rbx
callq 0x85555
addq $0x10, %rsp
cmpl $-0x1, %eax
je 0x89dbe
movq 0x8(%rsp), %rax
movl $0x1, 0x90(%rax)
movq %r14, %rdi
callq 0x853ed
xorl %ebp, %ebp
jmp 0x89dc3
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x45c0
jmp 0x89dc3
leaq 0x18289(%rip), %rdi     # 0xa2071
leaq 0x1807c(%rip), %rsi     # 0xa1e6b
leaq 0x1829e(%rip), %rcx     # 0xa2094
movl $0x90e, %edx            # imm = 0x90E
callq 0x42f0