// File: /workspace/github_cpp_makefile_star2_O1/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, %ebp
movq %rsi, %r15
movq %rdi, %r13
testl %edx, %edx
jne 0x3e108
movq %r15, %rdi
callq 0x4230
movq %rax, %rbp
movq (%r13), %rbx
movslq %ebp, %r12
leaq (%rbx,%r12), %rax
addq $0x2, %rax
cmpq %rax, 0x8(%r13)
jae 0x3e17f
leaq (%rbx,%r12), %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, %r14
shrq $0x20, %r14
orq %rcx, %r14
incq %r14
movq 0x10(%r13), %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3e566
movq %rax, 0x10(%r13)
movq %r14, 0x8(%r13)
movl %r12d, %r14d
movq 0x10(%r13), %rdi
addq (%r13), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x4420
movq %r14, %rcx
addq (%r13), %r12
movq %r12, (%r13)
movq 0x10(%r13), %rax
movb $0x0, (%rax,%r12)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $-0x1, %ecx
je 0x3e56b
testl %ecx, %ecx
jle 0x3e562
movq %r13, %r15
movslq %ebx, %r12
addq 0x10(%r13), %r12
movl $0x1, (%rsp)
xorl %r13d, %r13d
movq %rbp, 0x30(%rsp)
movq %rcx, 0x8(%rsp)
movq %r15, 0x18(%rsp)
movslq %r13d, %rax
movb (%r12,%rax), %cl
testb %cl, %cl
je 0x3e562
leaq (%r12,%rax), %rsi
cmpb $0x40, %cl
jne 0x3e4cb
movsbl 0x1(%rsi), %r14d
leal -0x7b(%r14), %ecx
cmpb $-0x3a, %cl
jb 0x3e4d9
movsbl 0x2(%rsi), %ebx
leal -0x7b(%rbx), %ecx
cmpb $-0x3b, %cl
jbe 0x3e4d9
leaq 0x3(%rax), %rbp
cmpb $0xa, 0x3(%r12,%rax)
jne 0x3e239
movl $0x4, 0x4(%rsp)
jmp 0x3e525
movq %rsi, 0x20(%rsp)
movq 0x28(%r15), %rdi
callq 0x4e186
movl $0x1, 0x4(%rsp)
testq %rax, %rax
je 0x3e525
movq %rax, 0x10(%rsp)
movl %r14d, %esi
shll $0x8, %esi
orl %ebx, %esi
movq 0x18(%r15), %rdi
movl %esi, 0x40(%rsp)
leaq 0x44(%rsp), %rdx
callq 0x3e599
cmpl $-0x1, %eax
je 0x3e525
cmpl $0x0, 0x44(%rsp)
movq 0x18(%r15), %rcx
movq 0x20(%rcx), %rcx
movl %eax, %eax
je 0x3e2a5
movq 0x10(%rsp), %rdx
movq %rdx, (%rcx,%rax,8)
movq %rdx, (%rdx)
movq %rdx, 0x8(%rdx)
xorl %eax, %eax
jmp 0x3e2ce
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rcx
cmpq %rax, (%rcx)
jne 0x3e57a
movq 0x10(%rsp), %rdx
movq %rdx, (%rcx)
movq %rcx, 0x8(%rdx)
movq %rdx, 0x8(%rax)
movq %rax, (%rdx)
movl 0x18(%rcx), %eax
incl %eax
movq 0x8(%rsp), %rcx
movl %eax, 0x18(%rdx)
xorb $0x43, %r14b
xorb $0x4f, %bl
orb %r14b, %bl
jne 0x3e36f
cmpb $0x9, (%r12,%rbp)
jne 0x3e545
addl $0x4, %r13d
movslq %r13d, %rbp
movl %r13d, %ebx
cmpl 0x30(%rsp), %r13d
jge 0x3e31d
movq %rbp, %rbx
movzbl (%r12,%rbx), %eax
testl %eax, %eax
je 0x3e31d
cmpl $0xa, %eax
je 0x3e31d
incq %rbx
cmpq %rbx, %rcx
jne 0x3e305
movl %ecx, %ebx
movq 0x30(%r15), %rdi
callq 0x4e186
movq %rax, %r14
movq 0x10(%rsp), %rax
movq %r14, 0x10(%rax)
testq %r14, %r14
je 0x3e4fc
movq 0x20(%r15), %rdi
leaq (%r12,%rbp), %rsi
movl %ebx, %eax
subl %ebp, %eax
movslq %eax, %r13
movq %r13, %rdx
callq 0x41f57
movq %rax, 0x8(%r14)
movl %r13d, 0x10(%r14)
movq $0x0, (%r14)
testq %rax, %rax
setne %al
cmovnel %ebx, %ebp
jmp 0x3e501
movq 0x30(%rsp), %rax
subl %r13d, %eax
movl %eax, 0x3c(%rsp)
movl %ecx, %eax
subl %r13d, %eax
movl %eax, 0x38(%rsp)
movq $0x0, 0x28(%rsp)
movslq %ebp, %rax
cmpb $0x9, (%r12,%rax)
jne 0x3e484
incl %ebp
movslq %ebp, %r13
movl %ebp, %ebx
cmpl %ecx, %ebp
jge 0x3e3c7
movq %r13, %rbx
movzbl (%r12,%rbx), %eax
cmpl $0xa, %eax
ja 0x3e3bd
movl $0x601, %edx            # imm = 0x601
btl %eax, %edx
jb 0x3e3c7
incq %rbx
cmpq %rbx, %rcx
jne 0x3e3a9
movl %ecx, %ebx
movq 0x30(%r15), %rdi
callq 0x4e186
testq %rax, %rax
je 0x3e432
movq %rax, %r14
movq 0x20(%r15), %rdi
leaq (%r12,%r13), %rsi
movl %ebx, %r15d
subl %r13d, %r15d
movslq %r15d, %r13
movq %r13, %rdx
callq 0x41f57
movq %rax, 0x8(%r14)
movl %r13d, 0x10(%r14)
movq $0x0, (%r14)
testq %rax, %rax
je 0x3e436
cmpl $0x3, %r15d
movq 0x8(%rsp), %rcx
jl 0x3e4a5
cmpb $0x3a, 0x2(%rax)
jne 0x3e4a5
movq 0x28(%rsp), %rax
testq %rax, %rax
movq 0x18(%rsp), %r15
je 0x3e444
movq %r14, (%rax)
jmp 0x3e44d
xorl %eax, %eax
jmp 0x3e43d
xorl %eax, %eax
movq 0x18(%rsp), %r15
movq 0x8(%rsp), %rcx
jmp 0x3e456
movq 0x10(%rsp), %rax
movq %r14, 0x10(%rax)
movb $0x1, %al
movl %ebx, %ebp
movq %r14, 0x28(%rsp)
testb %al, %al
je 0x3e525
cmpl %ecx, %ebp
jge 0x3e508
movslq %ebp, %rax
movzbl (%r12,%rax), %eax
cmpl $0xa, %eax
je 0x3e508
testl %eax, %eax
jne 0x3e38d
jmp 0x3e508
leaq 0x17287(%rip), %rdi     # 0x55712
movq 0x20(%rsp), %rsi
movl 0x3c(%rsp), %edx
movl (%rsp), %ecx
callq 0x5a28
movq 0x8(%rsp), %rcx
xorl %eax, %eax
jmp 0x3e456
leaq 0x17272(%rip), %rdi     # 0x5571e
movq 0x20(%rsp), %rsi
movl 0x38(%rsp), %edx
movl (%rsp), %ecx
callq 0x5a28
movq 0x8(%rsp), %rcx
xorl %eax, %eax
movq 0x18(%rsp), %r15
jmp 0x3e456
movl %ebp, %edx
subl %r13d, %edx
leaq 0x17196(%rip), %rdi     # 0x5566d
jmp 0x3e4ea
movq 0x8(%rsp), %rax
movl %eax, %edx
subl %r13d, %edx
leaq 0x171a7(%rip), %rdi     # 0x55691
movl (%rsp), %ecx
callq 0x5a28
movl $0x1, 0x4(%rsp)
jmp 0x3e528
xorl %eax, %eax
movl %r13d, %ebp
movl %ebp, %r13d
testb %al, %al
je 0x3e528
movq %r15, %rdi
movl 0x40(%rsp), %esi
movq 0x10(%rsp), %rdx
callq 0x3e6f4
xorl %ecx, %ecx
cmpl $-0x1, %eax
sete %cl
movl %ecx, 0x4(%rsp)
movl %ebp, %r13d
testb $0x3, 0x4(%rsp)
jne 0x3e566
incl %r13d
incl (%rsp)
movq 0x30(%rsp), %rbp
cmpl %ebp, %r13d
jl 0x3e1e2
jmp 0x3e562
movl %ecx, %edx
subl %r13d, %edx
leaq 0x171c1(%rip), %rdi     # 0x55712
movq 0x20(%rsp), %rsi
movl (%rsp), %ecx
callq 0x5a28
xorl %eax, %eax
jmp 0x3e501
xorl %eax, %eax
jmp 0x3e56b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1713e(%rip), %rdi     # 0x556bf
leaq 0x17144(%rip), %rsi     # 0x556cc
leaq 0x1714f(%rip), %rcx     # 0x556de
movl $0x14f, %edx            # imm = 0x14F
callq 0x4350