// File: /workspace/github_c_makefile_star2_O3/c-zhou[P]oatk/path.c
// Function: make_path_from_str
path_t make_path_from_str(asg_t *asg, char *path_str, char *sid)
{
    int circ;
    uint32_t v, cov;
    uint64_t len, len1;
    double wlen;
    kvec_t(uint32_t) vt;
    char *ptr, *s;

    kv_init(vt);

    while (isspace(*path_str) && *path_str != '\0')
        ++path_str;

    while (*path_str != '\0') {
        ptr = path_str;
        while (!isspace(*ptr) && *ptr != ',' && *ptr !='\0')
            ++ptr;

        if (*(ptr-1) == '+' || *(ptr-1) == '-') {
            s = strdup1(path_str, ptr - path_str - 1);
            v = asg_name2id(asg, s);
            if (v == UINT32_MAX) {
                fprintf(stderr, "[E::%s] sequence does not exist: %s\n", __func__, s);
                exit(EXIT_FAILURE);
            }
            v = (v<<1) | (*(ptr-1)=='-');
            kv_push(uint32_t, vt , v);
            free(s);
        } else {
            fprintf(stderr, "[E::%s] invalid path string: %s\n", __func__, path_str);
            exit(EXIT_FAILURE);
        }

        if (isspace(*ptr) || *ptr == '\0') break;
        path_str = ptr + 1;
    }
    
    if (vt.n == 0) {
        fprintf(stderr, "[E::%s] invalid path string: %s\n", __func__, path_str);
        exit(EXIT_FAILURE);
    }

    size_t i;
    asmg_t *g;
    asmg_arc_t *a;
    g = asg->asmg;
    a = asmg_arc1(g, vt.a[vt.n-1], vt.a[0]);
    circ = !!a;
    len = g->vtx[vt.a[0]>>1].len;
    cov = g->vtx[vt.a[0]>>1].cov;
    wlen = (double) cov * len;
    if (circ) len -= a->ls, wlen -= cov * a->ls;
    for (i = 1; i < vt.n; ++i) {
        len1 = g->vtx[vt.a[i]>>1].len;
        cov = g->vtx[vt.a[i]>>1].cov;
        len += len1;
        wlen += (double) cov * len1;
        a = asmg_arc1(g, vt.a[i-1], vt.a[i]);
        if (!a) {
            fprintf(stderr, "[W::%s] gap introduced as link does not exist: %s%c -> %s%c\n", __func__,
                    asg->seg[vt.a[i-1]>>1].name, "+-"[vt.a[i-1]&1],
                    asg->seg[vt.a[i]>>1].name, "+-"[vt.a[i]&1]);
        } else {
            len -= a->ls;
            wlen -= (double) cov * a->ls;
        }
    }

    path_t path = {sid? strdup1(sid, strlen(sid)) : 0, vt.n, circ, 0, vt.a, len, wlen, .0};
    
    return path;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, 0x40(%rsp)
movq %rdx, %r12
movq %rsi, 0x10(%rsp)
movq %rdi, 0x48(%rsp)
callq 0x34d0
movq %rax, 0x50(%rsp)
movq (%rax), %r15
decq %r12
movsbq 0x1(%r12), %rax
incq %r12
testq %rax, %rax
je 0x87d9
movzwl (%r15,%rax,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
jne 0x87be
testb %al, %al
je 0x8bc8
xorl %ebx, %ebx
movq $0x0, 0x38(%rsp)
xorl %r9d, %r9d
movq %r12, %r13
movsbq %al, %rcx
movzwl (%r15,%rcx,2), %ecx
btl $0xd, %ecx
jb 0x8823
movq %r12, %r13
testb %al, %al
je 0x8823
movzbl %al, %eax
cmpl $0x2c, %eax
je 0x8823
movsbq 0x1(%r13), %rax
incq %r13
movzwl (%r15,%rax,2), %ecx
btl $0xd, %ecx
jae 0x8804
movq %rbx, 0x20(%rsp)
movq %r9, 0x18(%rsp)
movzbl -0x1(%r13), %eax
cmpl $0x2d, %eax
je 0x8840
cmpl $0x2b, %eax
jne 0x8bc0
movl %r12d, %ebx
notl %ebx
addl %r13d, %ebx
movl %r13d, %edi
subl %r12d, %edi
callq 0x32f0
movq %rax, %r14
movq %rax, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x32c0
movb $0x0, (%r14,%rbx)
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x8bd0
cmpl $-0x1, %eax
je 0x8bb8
movl %eax, %ebx
xorl %ebp, %ebp
cmpb $0x2d, -0x1(%r13)
sete %al
movq 0x20(%rsp), %rcx
cmpq 0x38(%rsp), %rcx
movq 0x18(%rsp), %rdi
jne 0x88d6
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movb %al, 0xf(%rsp)
movl $0x2, %eax
cmoveq %rax, %rdx
movq %rdx, 0x38(%rsp)
leaq (,%rdx,4), %rsi
callq 0x3330
movq 0x20(%rsp), %rcx
movq %rax, %rdi
movq 0x50(%rsp), %rax
movq (%rax), %r15
movb 0xf(%rsp), %al
movb %al, %bpl
leal (%rbp,%rbx,2), %eax
leaq 0x1(%rcx), %rbx
movq %rdi, %rbp
movl %eax, (%rdi,%rcx,4)
movq %r14, %rdi
callq 0x3060
movsbq (%r13), %rax
testq %rax, %rax
je 0x891c
movzwl (%r15,%rax,2), %eax
andl $0x2000, %eax           # imm = 0x2000
movq %rbp, %r9
jne 0x891f
movb 0x1(%r13), %al
incq %r13
movq %r13, %r12
testb %al, %al
jne 0x87f2
jmp 0x891f
movq %rbp, %r9
movq %rbx, 0x18(%rsp)
testq %rbx, %rbx
je 0x8bc8
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rbx
movq 0x20(%rsp), %rdi
movl (%r9,%rdi,4), %edx
movl (%r9), %eax
movq 0x38(%rbx), %rcx
movq (%rcx,%rdx,8), %rcx
testq %rcx, %rcx
je 0x8979
movq 0x30(%rbx), %rsi
movq (%rsi,%rdx,8), %rdx
leaq (%rdx,%rdx,2), %r13
shlq $0x4, %r13
addq 0x28(%rbx), %r13
cmpq %rax, 0x8(%r13)
jne 0x8970
testb $0x40, 0x23(%r13)
je 0x897c
addq $0x30, %r13
decq %rcx
jne 0x8963
xorl %r13d, %r13d
movq 0x10(%rbx), %rcx
shrl %eax
leaq (%rax,%rax,4), %rdx
movl 0x20(%rcx,%rdx,8), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
cvtsi2sd %eax, %xmm1
movq 0x18(%rcx,%rdx,8), %r14
movq %r14, %xmm2
punpckldq 0x11beb(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x11bf3(%rip), %xmm2    # 0x1a5a0
movapd %xmm2, %xmm0
unpckhpd %xmm2, %xmm0            # xmm0 = xmm0[1],xmm2[1]
addsd %xmm2, %xmm0
mulsd %xmm1, %xmm0
testq %r13, %r13
je 0x89f2
movq 0x18(%r13), %rcx
subq %rcx, %r14
imulq %rcx, %rax
movq %rax, %xmm1
punpckldq 0x11bb6(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x11bbe(%rip), %xmm1    # 0x1a5a0
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
subsd %xmm2, %xmm0
testq %rdi, %rdi
je 0x8b24
addq $0x10, 0x10(%rsp)
movq 0x18(%rsp), %rax
cmpq $0x3, %rax
movl $0x2, %r15d
cmovaeq %rax, %r15
movl $0x1, %r12d
movl $0x3fffffff, %r10d      # imm = 0x3FFFFFFF
movq 0x11b68(%rip), %xmm4    # 0x1a590
movapd 0x11b70(%rip), %xmm5    # 0x1a5a0
movl -0x4(%r9,%r12,4), %esi
movl (%r9,%r12,4), %ecx
movl %ecx, %edx
shrl %edx
leaq (%rdx,%rdx,4), %rax
movq 0x10(%rbx), %rdi
movq 0x18(%rdi,%rax,8), %r8
movl 0x20(%rdi,%rax,8), %eax
andl %r10d, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
addq %r8, %r14
movq %r8, %xmm2
punpckldq %xmm4, %xmm2    # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
subpd %xmm5, %xmm2
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
addsd %xmm2, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm0, %xmm3
movq 0x38(%rbx), %rax
movq (%rax,%rsi,8), %rax
testq %rax, %rax
je 0x8ab9
movq 0x28(%rbx), %rdi
movq 0x30(%rbx), %r8
movq (%r8,%rsi,8), %r8
leaq (%r8,%r8,2), %r8
shlq $0x4, %r8
addq %r8, %rdi
addq $0x20, %rdi
cmpq %rcx, -0x18(%rdi)
jne 0x8ab0
testb $0x40, 0x3(%rdi)
je 0x8aea
addq $0x30, %rdi
decq %rax
jne 0x8aa4
movq 0x10(%rsp), %rdi
movapd %xmm3, 0x20(%rsp)
callq 0x370e
movapd 0x11acf(%rip), %xmm5    # 0x1a5a0
movq 0x11ab7(%rip), %xmm4    # 0x1a590
movl $0x3fffffff, %r10d      # imm = 0x3FFFFFFF
movapd 0x20(%rsp), %xmm3
movq %rbp, %r9
jmp 0x8b12
movq -0x8(%rdi), %rax
subq %rax, %r14
movq %rax, %xmm0
punpckldq %xmm4, %xmm0    # xmm0 = xmm0[0],xmm4[0],xmm0[1],xmm4[1]
subpd %xmm5, %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
mulsd %xmm2, %xmm1
subsd %xmm1, %xmm3
incq %r12
movapd %xmm3, %xmm0
cmpq %r15, %r12
jne 0x8a30
jmp 0x8b28
movapd %xmm0, %xmm3
movq 0x40(%rsp), %r15
testq %r15, %r15
je 0x8b6f
movq %r15, %rdi
movapd %xmm3, 0x20(%rsp)
callq 0x3130
movq %rax, %r12
leal 0x1(%rax), %edi
callq 0x32f0
movq %rax, %rbx
movl %r12d, %r12d
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x32c0
movapd 0x20(%rsp), %xmm3
movq %rbp, %r9
movb $0x0, (%rbx,%r12)
jmp 0x8b71
xorl %ebx, %ebx
xorl %ecx, %ecx
testq %r13, %r13
setne %cl
movq 0x48(%rsp), %rax
movq %rbx, (%rax)
movq 0x18(%rsp), %rdx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
shll $0x1e, %ecx
orl %edx, %ecx
movl %ecx, 0x8(%rax)
movq %r9, 0x10(%rax)
movl %r14d, 0x18(%rax)
movsd %xmm3, 0x20(%rax)
movq $0x0, 0x28(%rax)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x3769
movq %r12, %rdi
callq 0x3794
movq %r12, %rdi
callq 0x37bf