// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %rbx
subq $0x1e8, %rsp            # imm = 0x1E8
testb %al, %al
je 0xddd98
movaps %xmm0, -0x120(%rbp)
movaps %xmm1, -0x110(%rbp)
movaps %xmm2, -0x100(%rbp)
movaps %xmm3, -0xf0(%rbp)
movaps %xmm4, -0xe0(%rbp)
movaps %xmm5, -0xd0(%rbp)
movaps %xmm6, -0xc0(%rbp)
movaps %xmm7, -0xb0(%rbp)
movq %r9, -0x128(%rbp)
movq %r8, -0x130(%rbp)
movq %rcx, -0x138(%rbp)
movq %rdx, -0x140(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xddde7
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0xde448
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0xdde1f
movq -0x18(%rbp), %rdi
callq 0xd7490
cmpl $0x0, %eax
je 0xdde13
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0xde448
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movl $0x1, 0x98(%rax)
movq -0x18(%rbp), %rdi
callq 0xd8810
cmpl $0x0, %eax
jge 0xdde65
movl $0x1, %edi
leaq 0x1a481(%rip), %rsi     # 0xf82cc
leaq 0x1a489(%rip), %rdx     # 0xf82db
movb $0x0, %al
callq 0x1b030
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0xde448
leaq -0x70(%rbp), %rax
leaq -0x150(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x10, (%rax)
leaq -0x70(%rbp), %rax
movq %rax, -0x160(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x154(%rbp)
cmpl $0x28, %eax
ja 0xddec4
movq -0x160(%rbp), %rcx
movl -0x154(%rbp), %edx
movslq %edx, %rax
addq 0x10(%rcx), %rax
addl $0x8, %edx
movl %edx, (%rcx)
movq %rax, -0x168(%rbp)
jmp 0xddee1
movq -0x160(%rbp), %rcx
movq 0x8(%rcx), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, 0x8(%rcx)
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0xddff3
leaq -0x70(%rbp), %rax
movq %rax, -0x178(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x16c(%rbp)
cmpl $0x28, %eax
ja 0xddf34
movq -0x178(%rbp), %rcx
movl -0x16c(%rbp), %edx
movslq %edx, %rax
addq 0x10(%rcx), %rax
addl $0x8, %edx
movl %edx, (%rcx)
movq %rax, -0x180(%rbp)
jmp 0xddf51
movq -0x178(%rbp), %rcx
movq 0x8(%rcx), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, 0x8(%rcx)
movq %rax, -0x180(%rbp)
movq -0x180(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0xddf6b
jmp 0xddff3
movq -0x48(%rbp), %rdi
leaq 0x1a37d(%rip), %rsi     # 0xf82f3
callq 0x4690
cmpl $0x0, %eax
jne 0xddf96
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xddf96
movq -0x50(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0xddfee
movq -0x48(%rbp), %rdi
leaq 0x1a355(%rip), %rsi     # 0xf82f6
callq 0x4690
cmpl $0x0, %eax
jne 0xddfc1
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xddfc1
movq -0x50(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0xddfec
movq -0x48(%rbp), %rdi
leaq 0x1464d(%rip), %rsi     # 0xf2619
callq 0x4690
cmpl $0x0, %eax
jne 0xddfea
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xddfea
movq -0x50(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0xddfec
jmp 0xddfee
jmp 0xdde89
leaq -0x70(%rbp), %rax
cmpq $0x0, -0x30(%rbp)
je 0xde058
movq -0x28(%rbp), %rax
cmpq $0x0, 0x70(%rax)
je 0xde058
movq -0x28(%rbp), %rax
movq 0x70(%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0xdae00
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x28(%rbp), %rcx
movq 0x70(%rcx), %rcx
cmpl (%rcx), %eax
je 0xde056
movq -0x30(%rbp), %rcx
movl $0x1, %edi
leaq 0x1a290(%rip), %rsi     # 0xf82cc
leaq 0x1a2b6(%rip), %rdx     # 0xf82f9
movb $0x0, %al
callq 0x1b030
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0xde448
jmp 0xde058
cmpq $0x0, -0x40(%rbp)
je 0xde0b9
movq -0x28(%rbp), %rax
cmpq $0x0, 0x70(%rax)
je 0xde0b9
movq -0x28(%rbp), %rax
movq 0x70(%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0xdae00
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
movq -0x28(%rbp), %rcx
movq 0x70(%rcx), %rcx
cmpl (%rcx), %eax
jne 0xde0b7
movq -0x40(%rbp), %rcx
movl $0x1, %edi
leaq 0x1a22f(%rip), %rsi     # 0xf82cc
leaq 0x1a276(%rip), %rdx     # 0xf831a
movb $0x0, %al
callq 0x1b030
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0xde448
jmp 0xde0b9
cmpq $0x0, -0x40(%rbp)
jne 0xde30d
movq -0x28(%rbp), %rax
cmpl $0x0, 0x60(%rax)
je 0xde30d
movq -0x28(%rbp), %rax
movslq 0x60(%rax), %rdi
shlq $0x2, %rdi
callq 0x4650
movq %rax, -0x80(%rbp)
movq -0x28(%rbp), %rax
movl 0x60(%rax), %eax
movl %eax, -0x88(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0xde107
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0xde448
movq -0x80(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x78(%rax), %rsi
movslq -0x88(%rbp), %rdx
shlq $0x2, %rdx
callq 0x43b0
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x88(%rbp), %eax
jge 0xde2ff
cmpq $0x0, -0x30(%rbp)
jne 0xde15c
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xddba0
movq %rax, -0x188(%rbp)
jmp 0xde16c
leaq 0x11e12(%rip), %rax     # 0xeff75
movq %rax, -0x188(%rbp)
jmp 0xde16c
movq -0x188(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
jne 0xde199
movq -0x80(%rbp), %rdi
callq 0x45a0
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0xde448
movq -0x80(%rbp), %rax
movslq -0x84(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jl 0xde1c3
movq -0x80(%rbp), %rax
movslq -0x84(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x28(%rbp), %rcx
cmpl 0x58(%rcx), %eax
jge 0xde1c3
jmp 0xde1e2
leaq 0x1a183(%rip), %rdi     # 0xf834d
leaq 0x19f76(%rip), %rsi     # 0xf8147
movl $0x90e, %edx            # imm = 0x90E
leaq 0x1a193(%rip), %rcx     # 0xf8370
callq 0x42e0
leaq -0x70(%rbp), %rax
leaq -0x150(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x10, (%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x1a0(%rbp)
leaq -0x70(%rbp), %rax
movq %rax, -0x198(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x190(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0xde23e
movq -0x20(%rbp), %rax
movq %rax, -0x1a8(%rbp)
jmp 0xde24e
leaq 0x11d30(%rip), %rax     # 0xeff75
movq %rax, -0x1a8(%rbp)
jmp 0xde24e
movq -0x190(%rbp), %r8
movq -0x198(%rbp), %rdx
movq -0x1a0(%rbp), %rdi
movq -0x1a8(%rbp), %r11
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rax
movq -0x80(%rbp), %rcx
movslq -0x84(%rbp), %rsi
movslq (%rcx,%rsi,4), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
leaq 0x19de4(%rip), %rsi     # 0xf8076
leaq 0x14380(%rip), %rcx     # 0xf2619
leaq 0x1a053(%rip), %r9      # 0xf82f3
leaq 0x1a04f(%rip), %r10     # 0xf82f6
xorl %ebx, %ebx
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movb $0x0, %al
callq 0xd8ff0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0xde2e7
movq -0x80(%rbp), %rdi
callq 0x45a0
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0xde448
leaq -0x70(%rbp), %rax
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0xde12d
movq -0x80(%rbp), %rdi
callq 0x45a0
jmp 0xde42a
cmpq $0x0, -0x30(%rbp)
jne 0xde32a
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xddba0
movq %rax, -0x1b0(%rbp)
jmp 0xde33a
leaq 0x11c44(%rip), %rax     # 0xeff75
movq %rax, -0x1b0(%rbp)
jmp 0xde33a
movq -0x1b0(%rbp), %rax
movq %rax, -0x98(%rbp)
cmpq $0x0, -0x98(%rbp)
jne 0xde35e
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0xde448
leaq -0x70(%rbp), %rax
leaq -0x150(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x10, (%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x1c8(%rbp)
leaq -0x70(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x1b8(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0xde3ba
movq -0x20(%rbp), %rax
movq %rax, -0x1d0(%rbp)
jmp 0xde3ca
leaq 0x11bb4(%rip), %rax     # 0xeff75
movq %rax, -0x1d0(%rbp)
jmp 0xde3ca
movq -0x1b8(%rbp), %r8
movq -0x1c0(%rbp), %rdx
movq -0x1c8(%rbp), %rdi
movq -0x1d0(%rbp), %rax
leaq 0x19c89(%rip), %rsi     # 0xf8076
leaq 0x14225(%rip), %rcx     # 0xf2619
leaq 0x19ef8(%rip), %r9      # 0xf82f3
xorl %r10d, %r10d
movq %rax, (%rsp)
movq $0x0, 0x8(%rsp)
movb $0x0, %al
callq 0xd8ff0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0xde426
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0xde448
leaq -0x70(%rbp), %rax
movq -0x28(%rbp), %rax
movl $0x1, 0x90(%rax)
movq -0x18(%rbp), %rdi
callq 0xd8e20
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)