// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/sam_header.c
// Function: sam_hdr_vadd
int sam_hdr_vadd(SAM_hdr *sh, const char *type, va_list ap, ...) {
    va_list args;
    SAM_hdr_type *h_type;
    SAM_hdr_tag *h_tag, *last;
    int new;
    khint32_t type_i = (type[0]<<8) | type[1], k;

    if (EOF == kputc_('@', &sh->text))
	return -1;
    if (EOF == kputsn(type, 2, &sh->text))
	return -1;

    if (!(h_type = pool_alloc(sh->type_pool)))
	return -1;
    if (-1 == (k = kh_put(sam_hdr, sh->h, type_i, &new)))
	return -1;

    // Form the ring, either with self or other lines of this type
    if (!new) {
	SAM_hdr_type *t = kh_val(sh->h, k), *p;
	p = t->prev;
	    
	assert(p->next == t);
	p->next = h_type;
	h_type->prev = p;

	t->prev = h_type;
	h_type->next = t;
	h_type->order = p->order + 1;
    } else {
	kh_val(sh->h, k) = h_type;
	h_type->prev = h_type->next = h_type;
	h_type->order = 0;
    }

    last = NULL;

    // Any ... varargs
    va_start(args, ap);
    for (;;) {
	char *k, *v;
	int idx;
	
	if (!(k = (char *)va_arg(args, char *)))
	    break;
	v = va_arg(args, char *);

	if (EOF == kputc_('\t', &sh->text))
	    return -1;

	if (!(h_tag = pool_alloc(sh->tag_pool)))
	    return -1;
	idx = ks_len(&sh->text);
	
	if (EOF == kputs(k, &sh->text))
	    return -1;
	if (EOF == kputc_(':', &sh->text))
	    return -1;
	if (EOF == kputs(v, &sh->text))
	    return -1;

	h_tag->len = ks_len(&sh->text) - idx;
	h_tag->str = string_ndup(sh->str_pool,
				 ks_str(&sh->text) + idx,
				 h_tag->len);
	h_tag->next = NULL;
	if (!h_tag->str)
	    return -1;

	if (last)
	    last->next = h_tag;
	else
	    h_type->tag = h_tag;
	
	last = h_tag;
    }
    va_end(args);

    // Plus the specified va_list params
    for (;;) {
	char *k, *v;
	int idx;
	
	if (!(k = (char *)va_arg(ap, char *)))
	    break;
	v = va_arg(ap, char *);

	if (EOF == kputc_('\t', &sh->text))
	    return -1;

	if (!(h_tag = pool_alloc(sh->tag_pool)))
	    return -1;
	idx = ks_len(&sh->text);
	
	if (EOF == kputs(k, &sh->text))
	    return -1;
	if (EOF == kputc_(':', &sh->text))
	    return -1;
	if (EOF == kputs(v, &sh->text))
	    return -1;

	h_tag->len = ks_len(&sh->text) - idx;
	h_tag->str = string_ndup(sh->str_pool,
				 ks_str(&sh->text) + idx,
				 h_tag->len);
	h_tag->next = NULL;
	if (!h_tag->str)
	    return -1;

	if (last)
	    last->next = h_tag;
	else
	    h_type->tag = h_tag;
	
	last = h_tag;
    }
    va_end(ap);

    if (EOF == kputc('\n', &sh->text))
	return -1;

    int itype = (type[0]<<8) | type[1];
    if (-1 == sam_hdr_update_hashes(sh, itype, h_type))
	return -1;

    return h_type->order;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r14
movq %rcx, 0x58(%rsp)
movq %r8, 0x60(%rsp)
movq %r9, 0x68(%rsp)
testb %al, %al
je 0x32c07
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)
movsbl (%rsi), %ebp
movsbl 0x1(%rsi), %ebx
pushq $0x40
popq %rdi
movq %r14, %rsi
callq 0x32f79
pushq $-0x1
popq %rcx
cmpl $-0x1, %eax
je 0x32f46
pushq $0x2
popq %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0x3243d
cmpl $-0x1, %eax
je 0x32f43
movq 0x28(%r14), %rdi
callq 0x3f4d4
testq %rax, %rax
je 0x32f43
movq %rax, 0x18(%rsp)
shll $0x8, %ebp
orl %ebx, %ebp
movq 0x18(%r14), %rdi
leaq 0x24(%rsp), %rdx
movl %ebp, %esi
callq 0x324d9
cmpl $-0x1, %eax
je 0x32f43
cmpl $0x0, 0x24(%rsp)
movq 0x18(%r14), %rcx
movq 0x20(%rcx), %rcx
movl %eax, %eax
je 0x32c99
movq 0x18(%rsp), %rdx
movq %rdx, (%rcx,%rax,8)
movq %rdx, %rcx
movq %rdx, (%rdx)
movq %rdx, 0x8(%rdx)
xorl %eax, %eax
jmp 0x32cc5
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rcx
cmpq %rax, (%rcx)
jne 0x32f5a
movq 0x18(%rsp), %rdx
movq %rdx, (%rcx)
movq %rcx, 0x8(%rdx)
movq %rdx, 0x8(%rax)
movq %rax, (%rdx)
movl 0x18(%rcx), %eax
movq %rdx, %rcx
incl %eax
movl %eax, 0x18(%rcx)
leaq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x130(%rsp), %rax
movq %rax, 0x8(%rsp)
movabsq $0x3000000018, %rax     # imm = 0x3000000018
movq %rax, (%rsp)
addq $0x10, %rcx
movq %rcx, 0x28(%rsp)
xorl %ebx, %ebx
movq %r15, 0x38(%rsp)
movq %r13, 0x30(%rsp)
movl (%rsp), %eax
cmpq $0x28, %rax
ja 0x32d1b
movq %rax, %rcx
addq 0x10(%rsp), %rcx
addl $0x8, %eax
movl %eax, (%rsp)
jmp 0x32d29
movq 0x8(%rsp), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movq (%rcx), %r12
testq %r12, %r12
je 0x32ed6
cmpl $0x28, %eax
ja 0x32d49
movl %eax, %ecx
addq 0x10(%rsp), %rcx
addl $0x8, %eax
movl %eax, (%rsp)
jmp 0x32d57
movq 0x8(%rsp), %rcx
leaq 0x8(%rcx), %rax
movq %rax, 0x8(%rsp)
movq (%rcx), %r13
pushq $0x9
popq %rdi
movq %r14, %rsi
callq 0x32f79
cmpl $-0x1, %eax
je 0x32f43
movq 0x30(%r14), %rdi
callq 0x3f4d4
testq %rax, %rax
je 0x32f43
movq %rax, %rbp
movq (%r14), %r15
movq %r12, %rdi
movq %r14, %rsi
callq 0x32fb4
cmpl $-0x1, %eax
je 0x32f43
pushq $0x3a
popq %rdi
movq %r14, %rsi
callq 0x32f79
cmpl $-0x1, %eax
je 0x32f43
movq %r13, %rdi
movq %r14, %rsi
callq 0x32fb4
cmpl $-0x1, %eax
je 0x32f43
movq (%r14), %rax
movslq %r15d, %rsi
subq %r15, %rax
movl %eax, 0x10(%rbp)
movq 0x20(%r14), %rdi
addq 0x10(%r14), %rsi
movslq %eax, %rdx
callq 0x3489a
movq %rax, 0x8(%rbp)
andq $0x0, (%rbp)
testq %rax, %rax
je 0x32f43
testq %rbx, %rbx
cmoveq 0x28(%rsp), %rbx
movq %rbp, (%rbx)
movq %rbp, %rbx
movq 0x30(%rsp), %r13
jmp 0x32d02
cmpl $0x28, %eax
ja 0x32e1d
movl %eax, %ecx
addq 0x10(%r13), %rcx
addl $0x8, %eax
movl %eax, (%r13)
jmp 0x32e29
movq 0x8(%r13), %rcx
leaq 0x8(%rcx), %rax
movq %rax, 0x8(%r13)
movq (%rcx), %r13
pushq $0x9
popq %rdi
movq %r14, %rsi
callq 0x32f79
cmpl $-0x1, %eax
je 0x32f43
movq 0x30(%r14), %rdi
callq 0x3f4d4
testq %rax, %rax
je 0x32f43
movq %rax, %rbp
movq (%r14), %r15
movq %r12, %rdi
movq %r14, %rsi
callq 0x32fb4
cmpl $-0x1, %eax
je 0x32f43
pushq $0x3a
popq %rdi
movq %r14, %rsi
callq 0x32f79
cmpl $-0x1, %eax
je 0x32f43
movq %r13, %rdi
movq %r14, %rsi
callq 0x32fb4
cmpl $-0x1, %eax
je 0x32f43
movq (%r14), %rax
movslq %r15d, %rsi
subq %r15, %rax
movl %eax, 0x10(%rbp)
movq 0x20(%r14), %rdi
addq 0x10(%r14), %rsi
movslq %eax, %rdx
callq 0x3489a
movq %rax, 0x8(%rbp)
andq $0x0, (%rbp)
testq %rax, %rax
je 0x32f43
testq %rbx, %rbx
cmoveq 0x28(%rsp), %rbx
movq %rbp, (%rbx)
movq %rbp, %rbx
movq 0x30(%rsp), %r13
movl (%r13), %eax
cmpq $0x28, %rax
ja 0x32ef0
movq %rax, %rcx
addq 0x10(%r13), %rcx
addl $0x8, %eax
movl %eax, (%r13)
jmp 0x32efc
movq 0x8(%r13), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%r13)
movq (%rcx), %r12
testq %r12, %r12
jne 0x32e09
movq %r14, %rdi
callq 0x32fd7
cmpl $-0x1, %eax
je 0x32f43
movq 0x38(%rsp), %rcx
movsbl (%rcx), %eax
shll $0x8, %eax
movsbl 0x1(%rcx), %esi
orl %eax, %esi
movq %r14, %rdi
movq 0x18(%rsp), %rbx
movq %rbx, %rdx
callq 0x3263b
cmpl $-0x1, %eax
pushq $-0x1
popq %rcx
je 0x32f46
movl 0x18(%rbx), %ecx
jmp 0x32f46
pushq $-0x1
popq %rcx
movl %ecx, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1377e(%rip), %rdi     # 0x466df
leaq 0x13784(%rip), %rsi     # 0x466ec
leaq 0x137e8(%rip), %rcx     # 0x46757
movl $0x1ca, %edx            # imm = 0x1CA
callq 0x4360