// File: /workspace/github_c_makefile_star2_O3/lh3[P]minigraph/gfa-io.c
// Function: gfa_parse_S
int gfa_parse_S(gfa_t *g, char *s)
{
	int i, is_ok = 0;
	char *p, *q, *seg = 0, *seq = 0, *rest = 0;
	uint32_t sid, len = 0;
	for (i = 0, p = q = s + 2;; ++p) {
		if (*p == 0 || *p == '\t') {
			int c = *p;
			*p = 0;
			if (i == 0) seg = q;
			else if (i == 1) {
				seq = q[0] == '*'? 0 : gfa_strdup(q);
				is_ok = 1, rest = c? p + 1 : 0;
				break;
			}
			++i, q = p + 1;
			if (c == 0) break;
		}
	}
	if (is_ok) { // all mandatory fields read
		int l_aux, m_aux = 0, LN = -1;
		uint8_t *aux = 0, *s_LN = 0;
		gfa_seg_t *s;
		l_aux = gfa_aux_parse(rest, &aux, &m_aux); // parse optional tags
		s_LN = l_aux? gfa_aux_get(l_aux, aux, "LN") : 0;
		if (s_LN && s_LN[0] == 'i') {
			LN = *(int32_t*)(s_LN + 1);
			l_aux = gfa_aux_del(l_aux, aux, s_LN);
		}
		if (seq == 0) {
			if (LN >= 0) len = LN;
		} else len = strlen(seq);
		if (LN >= 0 && len != LN && gfa_verbose >= 2)
			fprintf(stderr, "[W] for segment '%s', LN:i:%d tag is different from sequence length %d\n", seg, LN, len);
		sid = gfa_add_seg(g, seg);
		s = &g->seg[sid];
		s->len = len, s->seq = seq;
		if (l_aux > 0) {
			uint8_t *s_SN = 0, *s_SO = 0, *s_SR = 0;
			s_SN = gfa_aux_get(l_aux, aux, "SN");
			if (s_SN && *s_SN == 'Z') { // then parse stable tags
				s->snid = gfa_sseq_add(g, (char*)(s_SN + 1)), s->soff = 0;
				l_aux = gfa_aux_del(l_aux, aux, s_SN);
				s_SO = gfa_aux_get(l_aux, aux, "SO");
				if (s_SO && *s_SO == 'i') {
					s->soff = *(int32_t*)(s_SO + 1);
					l_aux = gfa_aux_del(l_aux, aux, s_SO);
				}
			}
			s_SR = gfa_aux_get(l_aux, aux, "SR");
			if (s_SR && *s_SR == 'i') {
				s->rank = *(int32_t*)(s_SR + 1);
				if (s->rank > g->max_rank) g->max_rank = s->rank;
				l_aux = gfa_aux_del(l_aux, aux, s_SR);
			}
			gfa_sseq_update(g, s);
		}
		if (l_aux > 0)
			s->aux.m_aux = m_aux, s->aux.l_aux = l_aux, s->aux.aux = aux;
		else if (aux)
			free(aux);
	} else return -1;
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x2(%rsi), %rdi
addq $0x3, %r12
xorl %r14d, %r14d
xorl %eax, %eax
movzbl -0x1(%r12), %ebp
cmpl $0x9, %ebp
je 0x8190
testl %ebp, %ebp
jne 0x81ae
movb $0x0, -0x1(%r12)
testl %eax, %eax
je 0x81a1
cmpl $0x1, %eax
jne 0x81a4
jmp 0x81bd
movq %rdi, %r14
testb %bpl, %bpl
je 0x81b3
incl %eax
movq %r12, %rdi
incq %r12
jmp 0x8181
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x8380
xorl %r13d, %r13d
cmpb $0x2a, (%rdi)
jne 0x81ca
xorl %r15d, %r15d
jmp 0x81d2
callq 0x4a43
movq %rax, %r15
testb %bpl, %bpl
cmoveq %r13, %r12
leaq 0xc(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x10(%rsp), %rsi
movq $0x0, (%rsi)
movq %r12, %rdi
callq 0x6628
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x8239
movl %eax, %ebp
movq 0x10(%rsp), %r13
leaq 0x20231(%rip), %rdx     # 0x28441
movl %eax, %edi
movq %r13, %rsi
callq 0x616c
testq %rax, %rax
je 0x823b
cmpb $0x69, (%rax)
jne 0x823b
movl 0x1(%rax), %r12d
movl %ebp, %edi
movq %r13, %rsi
movq %rax, %rdx
callq 0x6293
movl %eax, %ebp
jmp 0x823b
xorl %ebp, %ebp
testq %r15, %r15
je 0x824d
movq %r15, %rdi
callq 0x2110
movq %rax, %r13
jmp 0x8257
xorl %r13d, %r13d
testl %r12d, %r12d
cmovgl %r12d, %r13d
testl %r12d, %r12d
js 0x8271
cmpl %r12d, %r13d
je 0x8271
leaq 0x29f88(%rip), %rax     # 0x321f0
cmpl $0x2, (%rax)
jge 0x838f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4aa4
movq 0x10(%rbx), %r14
movl %eax, %eax
shlq $0x6, %rax
movl %r13d, (%r14,%rax)
movq %r15, 0x20(%r14,%rax)
movq 0x10(%rsp), %r15
testl %ebp, %ebp
jle 0x8371
addq %rax, %r14
leaq 0x201e6(%rip), %rdx     # 0x2848c
movl %ebp, %edi
movq %r15, %rsi
callq 0x616c
testq %rax, %rax
je 0x8317
movq %rax, %r12
cmpb $0x5a, (%rax)
jne 0x8317
movq %r12, %rsi
incq %rsi
movq %rbx, %rdi
callq 0x4f76
movl %eax, 0x8(%r14)
movl $0x0, 0xc(%r14)
movl %ebp, %edi
movq %r15, %rsi
movq %r12, %rdx
callq 0x6293
movl %eax, %ebp
leaq 0x201a2(%rip), %rdx     # 0x2848f
movl %eax, %edi
movq %r15, %rsi
callq 0x616c
testq %rax, %rax
je 0x8317
cmpb $0x69, (%rax)
jne 0x8317
movl 0x1(%rax), %ecx
movl %ecx, 0xc(%r14)
movl %ebp, %edi
movq %r15, %rsi
movq %rax, %rdx
callq 0x6293
movl %eax, %ebp
leaq 0x20174(%rip), %rdx     # 0x28492
movl %ebp, %edi
movq %r15, %rsi
callq 0x616c
testq %rax, %rax
je 0x8350
cmpb $0x69, (%rax)
jne 0x8350
movl 0x1(%rax), %ecx
movl %ecx, 0x10(%r14)
cmpl 0x8(%rbx), %ecx
jbe 0x8341
movl %ecx, 0x8(%rbx)
movl %ebp, %edi
movq %r15, %rsi
movq %rax, %rdx
callq 0x6293
movl %eax, %ebp
movq %rbx, %rdi
movq %r14, %rsi
callq 0x516d
testl %ebp, %ebp
jle 0x8371
movl 0xc(%rsp), %eax
movl %eax, 0x30(%r14)
movl %ebp, 0x34(%r14)
movq %r15, 0x38(%r14)
jmp 0x837e
testq %r15, %r15
je 0x837e
movq %r15, %rdi
callq 0x2040
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x29c62(%rip), %rax     # 0x31ff8
movq (%rax), %rdi
leaq 0x200a4(%rip), %rsi     # 0x28444
movq %r14, %rdx
movl %r12d, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x2210
jmp 0x8271