// File: /workspace/github_c_makefile_star2_O1/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), %r13
addq $0x3, %r12
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %edi, %edi
xorl %eax, %eax
xorl %ecx, %ecx
movzbl -0x1(%r12), %ebp
cmpl $0x9, %ebp
je 0x7c52
testl %ebp, %ebp
jne 0x7ca2
movb $0x0, -0x1(%r12)
testl %ecx, %ecx
je 0x7c6d
cmpl $0x1, %ecx
jne 0x7c70
cmpb $0x2a, (%r13)
jne 0x7c7d
xorl %r15d, %r15d
jmp 0x7c88
movq %r13, %r14
incl %ecx
testb %bpl, %bpl
setne %dl
movq %r12, %r13
jmp 0x7c9e
movq %r13, %rdi
callq 0x4b60
movq %rax, %r15
xorl %edx, %edx
testb %bpl, %bpl
movq %r12, %rdi
cmoveq %rdx, %rdi
movl $0x1, %eax
movl $0x1, %ecx
testb %dl, %dl
je 0x7ca7
incq %r12
jmp 0x7c43
testl %eax, %eax
je 0x7ce2
leaq 0x14(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x8(%rsp), %rsi
movq $0x0, (%rsi)
callq 0x6640
movl %eax, %ebp
testl %eax, %eax
je 0x7cec
movq 0x8(%rsp), %rsi
leaq 0x20768(%rip), %rdx     # 0x28441
movl %ebp, %edi
callq 0x6199
jmp 0x7cee
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x7e60
xorl %eax, %eax
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x7d13
cmpb $0x69, (%rax)
jne 0x7d13
movl 0x1(%rax), %r12d
movq 0x8(%rsp), %rsi
movl %ebp, %edi
movq %rax, %rdx
callq 0x62c4
movl %eax, %ebp
testq %r15, %r15
je 0x7d25
movq %r15, %rdi
callq 0x2110
movq %rax, %r13
jmp 0x7d2f
xorl %r13d, %r13d
testl %r12d, %r12d
cmovgl %r12d, %r13d
testl %r12d, %r12d
js 0x7d49
cmpl %r12d, %r13d
je 0x7d49
leaq 0x2a4b0(%rip), %rax     # 0x321f0
cmpl $0x2, (%rax)
jge 0x7e6f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4bc1
movq 0x10(%rbx), %rcx
movl %eax, %eax
shlq $0x6, %rax
leaq (%rcx,%rax), %r14
movl %r13d, (%rcx,%rax)
movq %r15, 0x20(%rcx,%rax)
testl %ebp, %ebp
jle 0x7e34
movq 0x8(%rsp), %r15
leaq 0x2070d(%rip), %rdx     # 0x2848c
movl %ebp, %edi
movq %r15, %rsi
callq 0x6199
testq %rax, %rax
je 0x7df0
movq %rax, %r12
cmpb $0x5a, (%rax)
jne 0x7df0
movq %r12, %rsi
incq %rsi
movq %rbx, %rdi
callq 0x506c
movl %eax, 0x8(%r14)
movl $0x0, 0xc(%r14)
movl %ebp, %edi
movq %r15, %rsi
movq %r12, %rdx
callq 0x62c4
movl %eax, %ebp
leaq 0x206c9(%rip), %rdx     # 0x2848f
movl %eax, %edi
movq %r15, %rsi
callq 0x6199
testq %rax, %rax
je 0x7df0
cmpb $0x69, (%rax)
jne 0x7df0
movl 0x1(%rax), %ecx
movl %ecx, 0xc(%r14)
movl %ebp, %edi
movq %r15, %rsi
movq %rax, %rdx
callq 0x62c4
movl %eax, %ebp
leaq 0x2069b(%rip), %rdx     # 0x28492
movl %ebp, %edi
movq %r15, %rsi
callq 0x6199
testq %rax, %rax
je 0x7e29
cmpb $0x69, (%rax)
jne 0x7e29
movl 0x1(%rax), %ecx
movl %ecx, 0x10(%r14)
cmpl 0x8(%rbx), %ecx
jbe 0x7e1a
movl %ecx, 0x8(%rbx)
movl %ebp, %edi
movq %r15, %rsi
movq %rax, %rdx
callq 0x62c4
movl %eax, %ebp
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5264
testl %ebp, %ebp
jle 0x7e4f
movl 0x14(%rsp), %eax
movl %eax, 0x30(%r14)
movl %ebp, 0x34(%r14)
movq 0x8(%rsp), %rax
movq %rax, 0x38(%r14)
jmp 0x7e5e
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x7e5e
callq 0x2040
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2a182(%rip), %rax     # 0x31ff8
movq (%rax), %rdi
leaq 0x205c4(%rip), %rsi     # 0x28444
movq %r14, %rdx
movl %r12d, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x2210
jmp 0x7d49