// File: karel-brinda[P]ococo/ext/htslib/cram/sam_header.c
// Function: sam_hdr_add_PG
int sam_hdr_add_PG(SAM_hdr *sh, const char *name, ...) {
    va_list args;

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

	if (!end)
	    return -1;

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

	for (i = 0; i < nends; i++) {
	    va_start(args, name);
	    if (-1 == sam_hdr_vadd(sh, "PG", args,
				   "ID", sam_hdr_PG_ID(sh, name),
				   "PN", name,
				   "PP", sh->pg[end[i]].name,
				   NULL)) {
		free(end);
		return  -1;
	    }
	    va_end(args);
	}

	free(end);
    } else {
	va_start(args, name);
	if (-1 == sam_hdr_vadd(sh, "PG", args,
			       "ID", sam_hdr_PG_ID(sh, name),
			       "PN", name,
			       NULL))
	    return -1;
	va_end(args);
    }

    //sam_hdr_dump(sh);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
testb %al, %al
je 0x5ed2f
movaps %xmm0, -0xd0(%rbp)
movaps %xmm1, -0xc0(%rbp)
movaps %xmm2, -0xb0(%rbp)
movaps %xmm3, -0xa0(%rbp)
movaps %xmm4, -0x90(%rbp)
movaps %xmm5, -0x80(%rbp)
movaps %xmm6, -0x70(%rbp)
movaps %xmm7, -0x60(%rbp)
movq %r9, -0xd8(%rbp)
movq %r8, -0xe0(%rbp)
movq %rcx, -0xe8(%rbp)
movq %rdx, -0xf0(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x6c(%rax)
je 0x5eeb8
movq -0x18(%rbp), %rax
movslq 0x6c(%rax), %rdi
shlq $0x2, %rdi
callq 0x47a0
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movl 0x6c(%rax), %eax
movl %eax, -0x50(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x5ed93
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x5ef5f
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rsi
movslq -0x50(%rbp), %rdx
shlq $0x2, %rdx
callq 0x4460
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jge 0x5eeaa
leaq -0x40(%rbp), %rax
leaq -0x100(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x10, (%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq -0x40(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x5ec30
movq -0x110(%rbp), %rdi
movq -0x108(%rbp), %rdx
movq %rax, %r8
movq -0x20(%rbp), %r11
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq -0x48(%rbp), %rcx
movslq -0x4c(%rbp), %rsi
movslq (%rcx,%rsi,4), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
leaq 0x1ed6e(%rip), %rsi     # 0x7dbb1
leaq 0x1e23f(%rip), %rcx     # 0x7d089
leaq 0x1ed63(%rip), %r9      # 0x7dbb4
leaq 0x1ed5f(%rip), %r10     # 0x7dbb7
xorl %ebx, %ebx
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movb $0x0, %al
callq 0x5c930
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x5ee98
movq -0x48(%rbp), %rdi
callq 0x46a0
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x5ef5f
leaq -0x40(%rbp), %rax
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x5edb6
movq -0x48(%rbp), %rdi
callq 0x46a0
jmp 0x5ef58
leaq -0x40(%rbp), %rax
leaq -0x100(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x10, (%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x120(%rbp)
leaq -0x40(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x5ec30
movq -0x120(%rbp), %rdi
movq -0x118(%rbp), %rdx
movq %rax, %r8
movq -0x20(%rbp), %rax
leaq 0x1ec96(%rip), %rsi     # 0x7dbb1
leaq 0x1e167(%rip), %rcx     # 0x7d089
leaq 0x1ec8b(%rip), %r9      # 0x7dbb4
xorl %r10d, %r10d
movq %rax, (%rsp)
movq $0x0, 0x8(%rsp)
movb $0x0, %al
callq 0x5c930
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x5ef54
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x5ef5f
leaq -0x40(%rbp), %rax
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %rbp
retq
nopl (%rax)