// File: /workspace/github_c_makefile_star2_O2/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, %r15
movq %rdx, %r13
movq %rsi, 0x28(%rsp)
movq %rdi, 0x50(%rsp)
callq 0x34d0
movq %rax, 0x38(%rsp)
movq (%rax), %rax
decq %r13
movsbq 0x1(%r13), %rcx
incq %r13
testq %rcx, %rcx
je 0x7165
movzwl (%rax,%rcx,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
jne 0x714c
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
xorl %r14d, %r14d
movq %r15, 0x48(%rsp)
movq %r13, %r8
movb (%r13), %cl
testb %cl, %cl
je 0x7288
leaq 0x1(%r8), %r13
pushq $-0x1
popq %rsi
movsbq %cl, %rdx
movzwl (%rax,%rdx,2), %edx
btl $0xd, %edx
jb 0x71ba
testb %cl, %cl
je 0x71ba
movzbl %cl, %ecx
cmpl $0x2c, %ecx
je 0x71ba
movb (%r13), %cl
incq %r13
incl %esi
jmp 0x7195
movzbl -0x2(%r13), %eax
cmpl $0x2d, %eax
je 0x71cd
cmpl $0x2b, %eax
jne 0x752b
movq %r8, %rbp
movq %r8, %rdi
callq 0x7555
movq %rax, %rbx
movq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0x7588
cmpl $-0x1, %eax
je 0x750e
movl %eax, %r12d
xorl %r15d, %r15d
cmpb $0x2d, -0x2(%r13)
sete %cl
movq 0x10(%rsp), %rax
cmpq %rax, %r14
movq 0x8(%rsp), %rdi
jne 0x7243
movq %r14, 0x30(%rsp)
leaq (%rax,%rax), %r14
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %r14
leaq (,%r14,4), %rsi
movb %cl, 0x8(%rsp)
callq 0x3330
movb 0x8(%rsp), %cl
movq %rax, %rdi
movq %r14, 0x10(%rsp)
movq 0x30(%rsp), %r14
movb %cl, %r15b
leal (%r15,%r12,2), %eax
movq %rdi, 0x8(%rsp)
movl %eax, (%rdi,%r14,4)
incq %r14
movq %rbx, %rdi
callq 0x3060
movsbq -0x1(%r13), %rcx
testq %rcx, %rcx
je 0x7285
movq 0x38(%rsp), %rax
movq (%rax), %rax
movzwl (%rax,%rcx,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
movq %rbp, %r8
je 0x717f
jmp 0x7288
movq %rbp, %r8
testq %r14, %r14
je 0x752b
movq 0x28(%rsp), %rax
movq 0x20(%rax), %r12
movq 0x8(%rsp), %rax
movl -0x4(%rax,%r14,4), %esi
movl (%rax), %ebx
movq %r12, %rdi
movq %rbx, %rdx
callq 0x703e
movq %r12, 0x30(%rsp)
movq 0x10(%r12), %rdx
shrl %ebx
imulq $0x28, %rbx, %rsi
movl 0x20(%rdx,%rsi), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
cvtsi2sd %ecx, %xmm0
movq 0x18(%rdx,%rsi), %r12
movq %r12, %xmm1
punpckldq 0xf2af(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xf2b7(%rip), %xmm1     # 0x165a0
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
testq %rax, %rax
movq %rax, 0x40(%rsp)
je 0x7333
movq 0x18(%rax), %rax
subq %rax, %r12
imulq %rax, %rcx
movq %rcx, %xmm0
punpckldq 0xf275(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xf27d(%rip), %xmm0     # 0x165a0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
subsd %xmm1, %xmm2
pushq $0x1
popq %r15
movq 0xf251(%rip), %xmm1     # 0x16590
movapd 0xf259(%rip), %xmm3     # 0x165a0
movq 0x8(%rsp), %rcx
cmpq %r14, %r15
jae 0x7494
movq %r14, %rbp
movq 0x30(%rsp), %rdi
movq 0x10(%rdi), %rax
movl -0x4(%rcx,%r15,4), %r14d
movl (%rcx,%r15,4), %r13d
movl %r13d, %ebx
shrl %ebx
imulq $0x28, %rbx, %rcx
movq 0x18(%rax,%rcx), %rdx
movl 0x20(%rax,%rcx), %eax
movl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
andl %ecx, %eax
addq %rdx, %r12
cvtsi2sd %eax, %xmm5
movq %rdx, %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm3, %xmm0
movapd %xmm0, %xmm4
unpckhpd %xmm0, %xmm4            # xmm4 = xmm4[1],xmm0[1]
addsd %xmm0, %xmm4
movsd %xmm5, 0x38(%rsp)
mulsd %xmm5, %xmm4
addsd %xmm2, %xmm4
movapd %xmm4, 0x10(%rsp)
movq %r14, %rsi
movq %r13, %rdx
callq 0x703e
testq %rax, %rax
je 0x741f
movq 0x18(%rax), %rax
subq %rax, %r12
movq %rax, %xmm0
movq 0xf1b5(%rip), %xmm4     # 0x16590
punpckldq %xmm4, %xmm0    # xmm0 = xmm0[0],xmm4[0],xmm0[1],xmm4[1]
movapd 0xf1b9(%rip), %xmm3     # 0x165a0
subpd %xmm3, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x38(%rsp), %xmm0
mulsd %xmm1, %xmm0
movapd 0x10(%rsp), %xmm2
subsd %xmm0, %xmm2
movdqa %xmm4, %xmm1
incq %r15
movq 0x8(%rsp), %rcx
movq %rbp, %r14
jmp 0x734c
movq 0x15bd2(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rax
movl %r14d, %ecx
shrl %ecx
imulq $0x18, %rcx, %rcx
movq (%rax,%rcx), %rcx
andl $0x1, %r14d
leaq 0xf422(%rip), %rsi      # 0x1686c
movsbl (%r14,%rsi), %r8d
imulq $0x18, %rbx, %rdx
movq (%rax,%rdx), %r9
andl $0x1, %r13d
movsbl (%r13,%rsi), %eax
movl %eax, (%rsp)
leaq 0xf3c4(%rip), %rsi      # 0x1682f
leaq 0xf389(%rip), %rdx      # 0x167fb
xorl %eax, %eax
callq 0x3290
movq 0xf10f(%rip), %xmm1     # 0x16590
movapd 0xf117(%rip), %xmm3     # 0x165a0
movapd 0x10(%rsp), %xmm2
jmp 0x740f
movq 0x48(%rsp), %rbx
testq %rbx, %rbx
je 0x74be
movq %rbx, %rdi
movapd %xmm2, 0x10(%rsp)
callq 0x3130
movq %rbx, %rdi
movl %eax, %esi
callq 0x7555
movapd 0x10(%rsp), %xmm2
jmp 0x74c0
xorl %eax, %eax
movq 0x40(%rsp), %rdx
xorl %ecx, %ecx
testq %rdx, %rdx
setne %cl
movq 0x50(%rsp), %rdx
movq %rax, (%rdx)
andl $0x3fffffff, %r14d      # imm = 0x3FFFFFFF
shll $0x1e, %ecx
orl %r14d, %ecx
movl %ecx, 0x8(%rdx)
movq 0x8(%rsp), %rax
movq %rax, 0x10(%rdx)
movl %r12d, 0x18(%rdx)
movsd %xmm2, 0x20(%rdx)
andq $0x0, 0x28(%rdx)
movq %rdx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x15ae3(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
leaq 0xf2b7(%rip), %rsi      # 0x167d6
leaq 0xf2d5(%rip), %rdx      # 0x167fb
movq %rbx, %rcx
jmp 0x7546
movq 0x15ac6(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
leaq 0xf2d2(%rip), %rsi      # 0x1680e
leaq 0xf2b8(%rip), %rdx      # 0x167fb
movq %r8, %rcx
xorl %eax, %eax
callq 0x3290
pushq $0x1
popq %rdi
callq 0x3430