// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/sam_header.c
// Function: sam_hdr_add_lines
int sam_hdr_add_lines(SAM_hdr *sh, const char *lines, int len) {
    int i, lno, text_offset;
    char *hdr;

    if (!len)
	len = strlen(lines);

    text_offset = ks_len(&sh->text);
    if (EOF == kputsn(lines, len, &sh->text))
	return -1;
    hdr = ks_str(&sh->text) + text_offset;

    for (i = 0, lno = 1; i < len && hdr[i] != '\0'; i++, lno++) {
	khint32_t type;
	khint_t k;

	int l_start = i, new;
	SAM_hdr_type *h_type;
	SAM_hdr_tag *h_tag, *last;

	if (hdr[i] != '@') {
	    int j;
	    for (j = i; j < len && hdr[j] != '\0' && hdr[j] != '\n'; j++)
		;
	    sam_hdr_error("Header line does not start with '@'",
			  &hdr[l_start], len - l_start, lno);
	    return -1;
	}

	type = (hdr[i+1]<<8) | hdr[i+2];
	if (hdr[i+1] < 'A' || hdr[i+1] > 'z' ||
	    hdr[i+2] < 'A' || hdr[i+2] > 'z') {
	    sam_hdr_error("Header line does not have a two character key",
			  &hdr[l_start], len - l_start, lno);
	    return -1;
	}

	i += 3;
	if (hdr[i] == '\n')
	    continue;

	// Add the header line type
	if (!(h_type = pool_alloc(sh->type_pool)))
	    return -1;
	if (-1 == (k = kh_put(sam_hdr, sh->h, type, &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;
	}

	// Parse the tags on this line
	last = NULL;
	if ((type>>8) == 'C' && (type&0xff) == 'O') {
	    int j;
	    if (hdr[i] != '\t') {
		sam_hdr_error("Missing tab",
			      &hdr[l_start], len - l_start, lno);
		return -1;
	    }

	    for (j = ++i; j < len && hdr[j] != '\0' && hdr[j] != '\n'; j++)
		;

	    if (!(h_type->tag = h_tag = pool_alloc(sh->tag_pool)))
		return -1;
	    h_tag->str = string_ndup(sh->str_pool, &hdr[i], j-i);
	    h_tag->len = j-i;
	    h_tag->next = NULL;
	    if (!h_tag->str)
		return -1;

	    i = j;

	} else {
	    do {
		int j;
		if (hdr[i] != '\t') {
		    sam_hdr_error("Missing tab",
				  &hdr[l_start], len - l_start, lno);
		    return -1;
		}

		for (j = ++i; j < len && hdr[j] != '\0' && hdr[j] != '\n' && hdr[j] != '\t'; j++)
		    ;
	    
		if (!(h_tag = pool_alloc(sh->tag_pool)))
		    return -1;
		h_tag->str = string_ndup(sh->str_pool, &hdr[i], j-i);
		h_tag->len = j-i;
		h_tag->next = NULL;
		if (!h_tag->str)
		    return -1;

		if (h_tag->len < 3 || h_tag->str[2] != ':') {
		    sam_hdr_error("Malformed key:value pair",
				  &hdr[l_start], len - l_start, lno);
		    return -1;
		}
	    
		if (last)
		    last->next = h_tag;
		else
		    h_type->tag = h_tag;

		last = h_tag;
		i = j;
	    } while (i < len && hdr[i] != '\0' && hdr[i] != '\n');
	}

	/* Update RG/SQ hashes */
	if (-1 == sam_hdr_update_hashes(sh, type, h_type))
	    return -1;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %r12d
movq %rsi, %rbx
movq %rdi, %rcx
testl %edx, %edx
movq %rdi, 0x10(%rsp)
jne 0x320ca
movq %rbx, %rdi
callq 0x4210
movq 0x10(%rsp), %rcx
movq %rax, %r12
movq (%rcx), %r14
movq %rbx, %rdi
movl %r12d, %esi
movq %rcx, %rbx
movq %rcx, %rdx
callq 0x3243d
pushq $-0x1
popq %rcx
cmpl $-0x1, %eax
je 0x3240d
movslq %r14d, %r15
addq 0x10(%rbx), %r15
movslq %r12d, %rax
movq %rax, 0x38(%rsp)
pushq $0x1
popq %rcx
xorl %r14d, %r14d
movq %r12, 0x28(%rsp)
movl %r12d, %esi
subl %r14d, %esi
jle 0x323c0
movslq %r14d, %rax
movb (%r15,%rax), %dl
testb %dl, %dl
je 0x323c0
leaq (%r15,%rax), %rdi
cmpb $0x40, %dl
jne 0x323da
movsbl 0x1(%rdi), %r13d
leal -0x7b(%r13), %edx
cmpb $-0x3a, %dl
jb 0x323ec
movsbl 0x2(%rdi), %ebp
leal -0x7b(%rbp), %edx
cmpb $-0x3a, %dl
jb 0x323ec
movl %ecx, 0x8(%rsp)
leaq 0x3(%rax), %r12
cmpb $0xa, 0x3(%r15,%rax)
je 0x323aa
movq %rdi, 0x18(%rsp)
movl %esi, 0xc(%rsp)
movq 0x28(%rbx), %rdi
callq 0x3f4d4
movq 0x10(%rsp), %rcx
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x3240a
movl %r13d, %esi
shll $0x8, %esi
orl %ebp, %esi
movq 0x18(%rcx), %rdi
movl %esi, 0x30(%rsp)
leaq 0x34(%rsp), %rdx
callq 0x324d9
movq 0x10(%rsp), %rdi
cmpl $-0x1, %eax
je 0x3240a
cmpl $0x0, 0x34(%rsp)
movq 0x18(%rdi), %rcx
movq 0x20(%rcx), %rcx
movl %eax, %eax
je 0x321d4
movq 0x20(%rsp), %rdx
movq %rdx, (%rcx,%rax,8)
movq %rdx, (%rdx)
movq %rdx, 0x8(%rdx)
xorl %eax, %eax
jmp 0x321fd
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rcx
cmpq %rax, (%rcx)
movq 0x20(%rsp), %rdx
jne 0x3241e
movq %rdx, (%rcx)
movq %rcx, 0x8(%rdx)
movq %rdx, 0x8(%rax)
movq %rax, (%rdx)
movl 0x18(%rcx), %eax
incl %eax
movl %eax, 0x18(%rdx)
xorb $0x43, %r13b
xorb $0x4f, %bpl
orb %r13b, %bpl
jne 0x3225a
cmpb $0x9, (%r15,%r12)
movq 0x38(%rsp), %rdx
jne 0x323cd
addl $0x4, %r14d
movslq %r14d, %r14
movq 0x28(%rsp), %rax
cmpl %r14d, %eax
movl %r14d, %r12d
cmovgl %eax, %r12d
movq %r14, %rax
cmpq %rdx, %rax
jge 0x32340
movzbl (%r15,%rax), %ecx
testl %ecx, %ecx
je 0x3233d
cmpl $0xa, %ecx
je 0x3233d
incq %rax
jmp 0x32236
addq $0x10, %rdx
movq %rdx, 0x40(%rsp)
movb (%r15,%r12), %al
xorl %ebp, %ebp
cmpb $0x9, %al
movq 0x38(%rsp), %rdx
jne 0x323cd
incl %r12d
movslq %r12d, %r13
movq 0x28(%rsp), %rax
cmpl %r13d, %eax
movl %r13d, %r12d
cmovgl %eax, %r12d
movq %r13, %rax
movl $0x601, %esi            # imm = 0x601
cmpq %rdx, %rax
jge 0x322af
movzbl (%r15,%rax), %ecx
cmpl $0xa, %ecx
ja 0x322a7
btl %ecx, %esi
jb 0x322ac
incq %rax
jmp 0x32293
movl %eax, %r12d
movq 0x30(%rdi), %rdi
callq 0x3f4d4
movq 0x10(%rsp), %rcx
testq %rax, %rax
je 0x3240a
movq %rax, %r14
movq 0x20(%rcx), %rdi
leaq (%r15,%r13), %rsi
movl %r12d, %ebx
subl %r13d, %ebx
movslq %ebx, %r13
movq %r13, %rdx
callq 0x3489a
movq 0x10(%rsp), %rdi
movq %rax, 0x8(%r14)
movl %r13d, 0x10(%r14)
andq $0x0, (%r14)
testq %rax, %rax
je 0x3240a
cmpl $0x3, %ebx
jl 0x323c4
cmpb $0x3a, 0x2(%rax)
jne 0x323c4
testq %rbp, %rbp
cmoveq 0x40(%rsp), %rbp
movq %r14, (%rbp)
cmpl 0x28(%rsp), %r12d
jge 0x32392
movslq %r12d, %rax
movzbl (%r15,%rax), %eax
cmpl $0xa, %eax
je 0x32392
movq %r14, %rbp
testl %eax, %eax
jne 0x32269
jmp 0x32392
movl %eax, %r12d
movq 0x30(%rdi), %rdi
callq 0x3f4d4
movq 0x10(%rsp), %rcx
movq %rax, %rbx
movq 0x20(%rsp), %rax
movq %rbx, 0x10(%rax)
testq %rbx, %rbx
je 0x3240a
movq 0x20(%rcx), %rdi
leaq (%r15,%r14), %rsi
movl %r12d, %eax
subl %r14d, %eax
movslq %eax, %r14
movq %r14, %rdx
callq 0x3489a
movq 0x10(%rsp), %rdi
movq %rax, 0x8(%rbx)
movl %r14d, 0x10(%rbx)
andq $0x0, (%rbx)
testq %rax, %rax
je 0x3240a
movl 0x30(%rsp), %esi
movq 0x20(%rsp), %rdx
callq 0x3263b
movq 0x10(%rsp), %rbx
cmpl $-0x1, %eax
je 0x3240a
incl %r12d
movl 0x8(%rsp), %ecx
incl %ecx
movl %r12d, %r14d
movq 0x28(%rsp), %r12
jmp 0x32104
xorl %ecx, %ecx
jmp 0x3240d
leaq 0x14373(%rip), %rdi     # 0x4673e
jmp 0x323d4
leaq 0x1435e(%rip), %rdi     # 0x46732
movl 0x8(%rsp), %ecx
jmp 0x323fc
movq %rdi, 0x18(%rsp)
movl %esi, 0xc(%rsp)
leaq 0x142a3(%rip), %rdi     # 0x4668d
jmp 0x323fc
movq %rdi, 0x18(%rsp)
movl %esi, 0xc(%rsp)
leaq 0x142b5(%rip), %rdi     # 0x466b1
movq 0x18(%rsp), %rsi
movl 0xc(%rsp), %edx
callq 0x3249b
pushq $-0x1
popq %rcx
movl %ecx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x142ba(%rip), %rdi     # 0x466df
leaq 0x142c0(%rip), %rsi     # 0x466ec
leaq 0x142cb(%rip), %rcx     # 0x466fe
movl $0x14f, %edx            # imm = 0x14F
callq 0x4360