// File: /workspace/github_cpp_makefile_star2_O1/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 $0x118, %rsp            # imm = 0x118
movq %rdx, %r13
movq %rdi, %rbx
movq %rcx, 0x78(%rsp)
movq %r8, 0x80(%rsp)
movq %r9, 0x88(%rsp)
testb %al, %al
je 0x3ee2a
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)
movsbl (%rsi), %ebp
movq %rsi, 0x58(%rsp)
movsbl 0x1(%rsi), %r15d
movq (%rdi), %rax
leaq 0x1(%rax), %rcx
cmpq %rcx, 0x8(%rdi)
jae 0x3ee9f
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %r14
shrq $0x20, %r14
orq %rcx, %r14
incq %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3f75c
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movb $0x40, (%rcx,%rax)
movq (%rbx), %rax
leaq 0x4(%rax), %rcx
cmpq %rcx, 0x8(%rbx)
jae 0x3ef1d
addq $0x3, %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %r14
shrq $0x20, %r14
orq %rcx, %r14
incq %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3f75c
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
movq 0x58(%rsp), %rdx
movzwl (%rdx), %edx
movw %dx, (%rcx,%rax)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x2(%rax), %rdx
movq %rdx, (%rbx)
movb $0x0, 0x2(%rcx,%rax)
movq 0x28(%rbx), %rdi
callq 0x4e186
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x3f75c
shll $0x8, %ebp
orl %r15d, %ebp
movq 0x18(%rbx), %rdi
leaq 0x4c(%rsp), %rdx
movl %ebp, %esi
callq 0x3e599
cmpl $-0x1, %eax
je 0x3f75c
cmpl $0x0, 0x4c(%rsp)
movq 0x18(%rbx), %rcx
movq 0x20(%rcx), %rcx
movl %eax, %eax
je 0x3ef9e
movq 0x38(%rsp), %rdx
movq %rdx, (%rcx,%rax,8)
movq %rdx, (%rdx)
movq %rdx, 0x8(%rdx)
xorl %eax, %eax
jmp 0x3efc7
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rcx
cmpq %rax, (%rcx)
movq 0x38(%rsp), %rdx
jne 0x3f773
movq %rdx, (%rcx)
movq %rcx, 0x8(%rdx)
movq %rdx, 0x8(%rax)
movq %rax, (%rdx)
movl 0x18(%rcx), %eax
incl %eax
movl %eax, 0x18(%rdx)
leaq 0x60(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x150(%rsp), %rax
movq %rax, 0x28(%rsp)
movabsq $0x3000000018, %rax     # imm = 0x3000000018
movq %rax, 0x20(%rsp)
addq $0x10, %rdx
movq %rdx, 0x50(%rsp)
movq $0x0, 0x10(%rsp)
movq %r13, 0x18(%rsp)
movl 0x20(%rsp), %ecx
cmpq $0x28, %rcx
ja 0x3f022
movq %rcx, %rax
addq 0x30(%rsp), %rax
addl $0x8, %ecx
movl %ecx, 0x20(%rsp)
jmp 0x3f030
movq 0x28(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x28(%rsp)
movq (%rax), %r12
testq %r12, %r12
je 0x3f053
movl 0x20(%rsp), %ecx
cmpq $0x28, %rcx
ja 0x3f05d
movq %rcx, %rax
addq 0x30(%rsp), %rax
addl $0x8, %ecx
movl %ecx, 0x20(%rsp)
jmp 0x3f06b
movl $0x2, %ecx
jmp 0x3f34c
movq 0x28(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x28(%rsp)
movq (%rax), %r15
movq (%rbx), %rax
leaq 0x1(%rax), %rcx
cmpq %rcx, 0x8(%rbx)
jae 0x3f0d6
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %r14
shrq $0x20, %r14
orq %rcx, %r14
incq %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3f347
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movb $0x9, (%rcx,%rax)
movq 0x30(%rbx), %rdi
callq 0x4e186
movl $0x1, %ecx
testq %rax, %rax
je 0x3f34c
movq %rax, 0x40(%rsp)
movq %r15, (%rsp)
movq %r13, %rbp
movq (%rbx), %r13
movq %r12, %rdi
callq 0x4230
movq %rax, %r14
movslq %r14d, %r15
movq %r13, 0x8(%rsp)
leaq (%r15,%r13), %rax
addq $0x2, %rax
movq %rbp, %r13
cmpq %rax, 0x8(%rbx)
jae 0x3f19d
movq 0x8(%rsp), %rax
addq %r15, %rax
incq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %r13
shrq $0x20, %r13
orq %rcx, %r13
incq %r13
movq 0x10(%rbx), %rdi
movq %r13, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3f342
movq %rax, 0x10(%rbx)
movq %r13, 0x8(%rbx)
movq 0x18(%rsp), %r13
movq 0x10(%rbx), %rdi
addq (%rbx), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x4420
addq (%rbx), %r15
movq %r15, (%rbx)
movq 0x10(%rbx), %rax
movb $0x0, (%rax,%r15)
cmpl $-0x1, %r14d
je 0x3f347
movq (%rbx), %rax
leaq 0x1(%rax), %rcx
cmpq %rcx, 0x8(%rbx)
movq (%rsp), %r15
jae 0x3f234
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %r14
shrq $0x20, %r14
orq %rcx, %r14
incq %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3f347
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movb $0x3a, (%rcx,%rax)
movq %r15, %rdi
callq 0x4230
movq %rax, %r12
movslq %r12d, %r14
movq (%rbx), %rax
leaq (%r14,%rax), %rcx
addq $0x2, %rcx
cmpq %rcx, 0x8(%rbx)
jae 0x3f2ca
addq %r14, %rax
incq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %r15
shrq $0x20, %r15
orq %rcx, %r15
incq %r15
movq 0x10(%rbx), %rdi
movq %r15, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3f347
movq %rax, 0x10(%rbx)
movq %r15, 0x8(%rbx)
movq (%rsp), %r15
movq 0x10(%rbx), %rdi
addq (%rbx), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4420
addq (%rbx), %r14
movq %r14, (%rbx)
movq 0x10(%rbx), %rax
movb $0x0, (%rax,%r14)
cmpl $-0x1, %r12d
je 0x3f347
movq (%rbx), %rax
movq 0x8(%rsp), %rcx
movslq %ecx, %rsi
subq %rcx, %rax
movq 0x40(%rsp), %r14
movl %eax, 0x10(%r14)
movq 0x20(%rbx), %rdi
addq 0x10(%rbx), %rsi
movslq %eax, %rdx
callq 0x41f57
movq %rax, 0x8(%r14)
movq $0x0, (%r14)
testq %rax, %rax
je 0x3f347
movq 0x10(%rsp), %rax
testq %rax, %rax
cmoveq 0x50(%rsp), %rax
movq %r14, (%rax)
xorl %ecx, %ecx
movq %r14, 0x10(%rsp)
jmp 0x3f34c
movq 0x18(%rsp), %r13
movl $0x1, %ecx
testl %ecx, %ecx
je 0x3f007
cmpl $0x2, %ecx
jne 0x3f75c
movl (%r13), %ecx
cmpq $0x28, %rcx
ja 0x3f377
movq %rcx, %rax
addq 0x10(%r13), %rax
addl $0x8, %ecx
movl %ecx, (%r13)
jmp 0x3f383
movq 0x8(%r13), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r13)
movq (%rax), %r12
testq %r12, %r12
je 0x3f3a5
movl (%r13), %ecx
cmpq $0x28, %rcx
ja 0x3f3af
movq %rcx, %rax
addq 0x10(%r13), %rax
addl $0x8, %ecx
movl %ecx, (%r13)
jmp 0x3f3bb
movl $0x4, %ecx
jmp 0x3f696
movq 0x8(%r13), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r13)
movq (%rax), %r15
movq (%rbx), %rax
leaq 0x1(%rax), %rcx
cmpq %rcx, 0x8(%rbx)
jae 0x3f426
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %r14
shrq $0x20, %r14
orq %rcx, %r14
incq %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3f691
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movb $0x9, (%rcx,%rax)
movq 0x30(%rbx), %rdi
callq 0x4e186
movl $0x1, %ecx
testq %rax, %rax
je 0x3f696
movq %rax, 0x40(%rsp)
movq %r15, (%rsp)
movq (%rbx), %rbp
movq %r12, %rdi
callq 0x4230
movq %rax, %r14
movslq %r14d, %r15
movq %rbp, 0x8(%rsp)
leaq (%r15,%rbp), %rax
addq $0x2, %rax
cmpq %rax, 0x8(%rbx)
jae 0x3f4e7
movq 0x8(%rsp), %rax
addq %r15, %rax
incq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %r13
shrq $0x20, %r13
orq %rcx, %r13
incq %r13
movq 0x10(%rbx), %rdi
movq %r13, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3f68c
movq %rax, 0x10(%rbx)
movq %r13, 0x8(%rbx)
movq 0x18(%rsp), %r13
movq 0x10(%rbx), %rdi
addq (%rbx), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x4420
addq (%rbx), %r15
movq %r15, (%rbx)
movq 0x10(%rbx), %rax
movb $0x0, (%rax,%r15)
cmpl $-0x1, %r14d
je 0x3f691
movq (%rbx), %rax
leaq 0x1(%rax), %rcx
cmpq %rcx, 0x8(%rbx)
movq (%rsp), %r15
jae 0x3f57e
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %r14
shrq $0x20, %r14
orq %rcx, %r14
incq %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3f691
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movb $0x3a, (%rcx,%rax)
movq %r15, %rdi
callq 0x4230
movq %rax, %r12
movslq %r12d, %r14
movq (%rbx), %rax
leaq (%r14,%rax), %rcx
addq $0x2, %rcx
cmpq %rcx, 0x8(%rbx)
jae 0x3f614
addq %r14, %rax
incq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %r15
shrq $0x20, %r15
orq %rcx, %r15
incq %r15
movq 0x10(%rbx), %rdi
movq %r15, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3f691
movq %rax, 0x10(%rbx)
movq %r15, 0x8(%rbx)
movq (%rsp), %r15
movq 0x10(%rbx), %rdi
addq (%rbx), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4420
addq (%rbx), %r14
movq %r14, (%rbx)
movq 0x10(%rbx), %rax
movb $0x0, (%rax,%r14)
cmpl $-0x1, %r12d
je 0x3f691
movq (%rbx), %rax
movq 0x8(%rsp), %rcx
movslq %ecx, %rsi
subq %rcx, %rax
movq 0x40(%rsp), %r14
movl %eax, 0x10(%r14)
movq 0x20(%rbx), %rdi
addq 0x10(%rbx), %rsi
movslq %eax, %rdx
callq 0x41f57
movq %rax, 0x8(%r14)
movq $0x0, (%r14)
testq %rax, %rax
je 0x3f691
movq 0x10(%rsp), %rax
testq %rax, %rax
cmoveq 0x50(%rsp), %rax
movq %r14, (%rax)
xorl %ecx, %ecx
movq %r14, 0x10(%rsp)
jmp 0x3f696
movq 0x18(%rsp), %r13
movl $0x1, %ecx
testl %ecx, %ecx
je 0x3f35d
cmpl $0x4, %ecx
jne 0x3f75c
movq (%rbx), %rax
leaq 0x2(%rax), %rcx
cmpq %rcx, 0x8(%rbx)
movq 0x38(%rsp), %r15
jae 0x3f713
incq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %r14
shrq $0x20, %r14
orq %rcx, %r14
incq %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3f75c
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movb $0xa, (%rcx,%rax)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
movb $0x0, (%rcx,%rax)
movq 0x58(%rsp), %rcx
movsbl (%rcx), %eax
shll $0x8, %eax
movsbl 0x1(%rcx), %esi
orl %eax, %esi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x3e6f4
cmpl $-0x1, %eax
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
je 0x3f761
movl 0x18(%r15), %eax
jmp 0x3f761
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x15f45(%rip), %rdi     # 0x556bf
leaq 0x15f4b(%rip), %rsi     # 0x556cc
leaq 0x15faf(%rip), %rcx     # 0x55737
movl $0x1ca, %edx            # imm = 0x1CA
callq 0x4350