// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/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, %r14d
movq %rsi, %r15
movq %rdi, %rbp
testl %edx, %edx
jne 0x616ac
movq %r15, %rdi
callq 0x62d0
movq %rax, %r14
movq (%rbp), %rbx
movslq %r14d, %rax
movq %rax, 0x30(%rsp)
addq %rbx, %rax
incq %rax
cmpq 0x8(%rbp), %rax
jae 0x616cd
movq 0x10(%rbp), %rax
movq %rbx, %rdi
jmp 0x6171f
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, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%rbp)
movq 0x10(%rbp), %rdi
callq 0x6c80
testq %rax, %rax
je 0x61a9a
movq %rax, 0x10(%rbp)
movq (%rbp), %rdi
addq %rax, %rdi
movq %r15, %rsi
movq 0x30(%rsp), %r15
movq %r15, %rdx
callq 0x6570
movq (%rbp), %rax
addq %r15, %rax
movq %rax, (%rbp)
movq 0x10(%rbp), %rcx
movb $0x0, (%rcx,%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $-0x1, %r15d
je 0x61a9f
testl %r14d, %r14d
jle 0x61a63
movslq %ebx, %rdx
addq 0x10(%rbp), %rdx
movl $0x1, %ecx
xorl %esi, %esi
movq %rbp, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movslq %esi, %rbx
movb (%rdx,%rbx), %al
testb %al, %al
je 0x61a63
leaq (%rdx,%rbx), %rdi
cmpb $0x40, %al
jne 0x61aae
movsbl 0x1(%rdi), %r15d
leal -0x7b(%r15), %eax
cmpb $-0x3a, %al
jb 0x61ac0
movsbl 0x2(%rdi), %r12d
leal -0x7b(%r12), %eax
cmpb $-0x3a, %al
jb 0x61ac0
movl %ecx, (%rsp)
leaq 0x3(%rbx), %r13
cmpb $0xa, 0x3(%rdx,%rbx)
je 0x61a45
movq %rdi, 0x20(%rsp)
movl %esi, 0x4(%rsp)
movq 0x28(%rbp), %rdi
callq 0x86942
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x61a9a
movl %r15d, %ebp
shll $0x8, %ebp
orl %r12d, %ebp
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
movl %ebp, %esi
leaq 0x3c(%rsp), %rdx
callq 0x61afa
movq 0x18(%rsp), %rdx
cmpl $-0x1, %eax
je 0x61a9a
cmpl $0x0, 0x3c(%rsp)
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq 0x20(%rcx), %rcx
movl %eax, %eax
je 0x6183f
movq 0x28(%rsp), %rsi
movq %rsi, (%rcx,%rax,8)
movq %rsi, (%rsi)
movq %rsi, 0x8(%rsi)
xorl %eax, %eax
jmp 0x61868
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rcx
cmpq %rax, (%rcx)
movq 0x28(%rsp), %rsi
jne 0x61adb
movq %rsi, (%rcx)
movq %rcx, 0x8(%rsi)
movq %rsi, 0x8(%rax)
movq %rax, (%rsi)
movl 0x18(%rcx), %eax
incl %eax
movl %eax, 0x18(%rsi)
xorb $0x43, %r15b
xorb $0x4f, %r12b
orb %r15b, %r12b
jne 0x618cd
cmpb $0x9, (%rdx,%r13)
movq 0x10(%rsp), %r14
jne 0x61ad2
addq $0x4, %rbx
movl %ebx, %r13d
cmpl %r14d, %ebx
jge 0x619cf
leaq (%rdx,%rbx), %rax
movq 0x30(%rsp), %rcx
subq %rbx, %rcx
xorl %r13d, %r13d
movzbl (%rax,%r13), %edx
testl %edx, %edx
je 0x619cc
cmpl $0xa, %edx
je 0x619cc
incq %r13
cmpq %r13, %rcx
jne 0x618a7
movl %r14d, %r13d
jmp 0x619cf
addq $0x10, %rsi
movq %rsi, 0x40(%rsp)
movb (%rdx,%r13), %al
xorl %r15d, %r15d
cmpb $0x9, %al
jne 0x61a67
movslq %r13d, %rbx
incq %rbx
movl %ebx, %r13d
movq 0x10(%rsp), %rsi
cmpl %esi, %ebx
jge 0x6192a
leaq (%rdx,%rbx), %rax
movq 0x30(%rsp), %rcx
subq %rbx, %rcx
xorl %r13d, %r13d
movl $0x601, %edi            # imm = 0x601
movzbl (%rax,%r13), %edx
cmpl $0xa, %edx
ja 0x6191a
btl %edx, %edi
jb 0x61927
incq %r13
cmpq %r13, %rcx
jne 0x6190b
movl %esi, %r13d
jmp 0x6192a
addl %ebx, %r13d
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rdi
callq 0x86942
movq 0x18(%rsp), %rcx
testq %rax, %rax
je 0x61a9a
movq %rax, %r12
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rdi
movslq %ebx, %rsi
addq %rcx, %rsi
movl %r13d, %r14d
subl %ebx, %r14d
movslq %r14d, %rbx
movq %rbx, %rdx
callq 0x651d9
movq 0x18(%rsp), %rdx
movq %rax, 0x8(%r12)
movl %ebx, 0x10(%r12)
movq $0x0, (%r12)
testq %rax, %rax
je 0x61a9a
cmpl $0x3, %r14d
jl 0x61a70
cmpb $0x3a, 0x2(%rax)
movq 0x10(%rsp), %r14
jne 0x61a7e
testq %r15, %r15
cmoveq 0x40(%rsp), %r15
movq %r12, (%r15)
cmpl %r14d, %r13d
jge 0x61a2a
movslq %r13d, %rax
movzbl (%rdx,%rax), %eax
cmpl $0xa, %eax
je 0x61a2a
movq %r12, %r15
testl %eax, %eax
jne 0x618dd
jmp 0x61a2a
addl %ebx, %r13d
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rdi
callq 0x86942
movq 0x18(%rsp), %rcx
movq %rax, %r15
movq 0x28(%rsp), %rax
movq %r15, 0x10(%rax)
testq %r15, %r15
je 0x61a9a
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rdi
movslq %ebx, %rsi
addq %rcx, %rsi
movl %r13d, %eax
subl %ebx, %eax
movslq %eax, %r12
movq %r12, %rdx
callq 0x651d9
movq %rax, 0x8(%r15)
movl %r12d, 0x10(%r15)
movq $0x0, (%r15)
testq %rax, %rax
je 0x61a9a
movq 0x8(%rsp), %rdi
movl %ebp, %esi
movq 0x28(%rsp), %rdx
callq 0x61c68
movq 0x18(%rsp), %rdx
cmpl $-0x1, %eax
je 0x61a9a
incl %r13d
movl (%rsp), %ecx
incl %ecx
movl %r13d, %esi
movq 0x10(%rsp), %r14
cmpl %r14d, %r13d
movq 0x8(%rsp), %rbp
jl 0x6177a
xorl %eax, %eax
jmp 0x61a9f
leaq 0x38062(%rip), %rdi     # 0x99ad0
jmp 0x61a77
leaq 0x38065(%rip), %rdi     # 0x99adc
movq 0x10(%rsp), %r14
jmp 0x61a85
leaq 0x38057(%rip), %rdi     # 0x99adc
movl (%rsp), %ecx
subl 0x4(%rsp), %r14d
movq 0x20(%rsp), %rsi
movl %r14d, %edx
callq 0x7b18
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, 0x20(%rsp)
movl %esi, 0x4(%rsp)
leaq 0x37f6d(%rip), %rdi     # 0x99a2b
jmp 0x61a88
movq %rdi, 0x20(%rsp)
movl %esi, 0x4(%rsp)
leaq 0x37f7f(%rip), %rdi     # 0x99a4f
jmp 0x61a88
leaq 0x37ff7(%rip), %rdi     # 0x99ad0
jmp 0x61a85
leaq 0x37f9b(%rip), %rdi     # 0x99a7d
leaq 0x37fa1(%rip), %rsi     # 0x99a8a
leaq 0x37fac(%rip), %rcx     # 0x99a9c
movl $0x14f, %edx            # imm = 0x14F
callq 0x6460