// File: /workspace/github_c_makefile_star2_O3/c-zhou[P]oatk/graph.c
// Function: asmg_path_exists
int asmg_path_exists(asmg_t *g, uint32_t source, uint32_t sink, uint32_t step, uint64_t dist, uint32_t *_step, uint64_t *_dist)
{
    // TODO dealing with graphs with deleted vertices and arcs
    // detect path between two vertices
    if (source >= asmg_vtx_n(g) || sink >= asmg_vtx_n(g))
        return 0;
    
    if (_step) *_step = 0;
    if (_dist) *_dist = 0;

    uint32_t i, v, r, nv;
    uint64_t x, rd;
    int8_t *flag;
    kdq_u64_t *q;
    kdq_u64_t *d;
    asmg_arc_t *av;

    int exists = 0;

    if (step == 0)
        step = UINT32_MAX;
    if (dist == 0)
        dist = UINT64_MAX;
    q = kdq_init(uint64_t, 0);
    d = kdq_init(uint64_t, 0);
    MYCALLOC(flag, asmg_vtx_n(g));
    kdq_push(uint64_t, q, (uint64_t)source<<32);
    kdq_push(uint64_t, d, 0);
    while (kdq_size(q) > 0) {
        x = *kdq_shift(uint64_t, q);
        v = x>>32;
        r = (uint32_t) x;
        rd = *kdq_shift(uint64_t, d);
        if (flag[v]) continue; // already visited
        flag[v] = 1;
        if (r < step && rd < dist) {
            nv = asmg_arc_n(g, v);
            av = asmg_arc_a(g, v);
            for (i = 0; i < nv; ++i) {
                if (av[i].w == sink) {
                    exists = 1;
                    if (_step) *_step = r;
                    if (_dist) *_dist = rd;
                    goto do_clean;
                }
                if (flag[av[i].w] == 0) {
                    kdq_push(uint64_t, q, (uint64_t)av[i].w<<32 | (r + 1));
                    kdq_push(uint64_t, d, rd + g->vtx[av[i].w>>1].len - av[i].ls);
                }
            }
        }
    }
    assert(kdq_size(d) == 0);

do_clean:
    kdq_destroy(uint64_t, q);
    kdq_destroy(uint64_t, d);
    free(flag);

    return exists;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %esi, %r14d
movq (%rdi), %rax
addq %rax, %rax
xorl %ebp, %ebp
cmpq %r14, %rax
jbe 0x1a592
movl %edx, %edx
cmpq %rdx, %rax
jbe 0x1a592
movq 0xa0(%rsp), %rax
testq %r9, %r9
je 0x19cc2
movl $0x0, (%r9)
movq %rdx, 0x18(%rsp)
movq %rdi, 0x20(%rsp)
movq %r9, 0x58(%rsp)
testq %rax, %rax
je 0x19cdd
movq $0x0, (%rax)
movabsq $0x3ffffffffffffff, %r13 # imm = 0x3FFFFFFFFFFFFFF
xorl %ebx, %ebx
movl %ecx, 0xc(%rsp)
cmpl $0x1, %ecx
movl $0x0, %eax
sbbl %eax, %eax
movl %eax, 0x2c(%rsp)
movq %r8, 0x48(%rsp)
cmpq $0x1, %r8
movl $0x0, %eax
sbbq %rax, %rax
movq %rax, 0x50(%rsp)
movl $0x1, %esi
movl $0x28, %edx
xorl %edi, %edi
callq 0x1d660
movq %rax, %r12
movq (%rax), %rax
andq %r13, %rax
btsq $0x3b, %rax
movq %rax, (%r12)
movl $0x3, %r15d
movq %r15, 0x10(%r12)
movl $0x20, %esi
xorl %edi, %edi
callq 0x1d7c1
movq %rax, 0x18(%r12)
movq %rbx, 0x20(%r12)
movl $0x1, %esi
movl $0x28, %edx
xorl %edi, %edi
callq 0x1d660
movq %rax, %rbp
movq (%rax), %rax
andq %r13, %rax
btsq $0x3b, %rax
movq %rax, (%rbp)
movq %r15, 0x10(%rbp)
movl $0x20, %esi
xorl %edi, %edi
callq 0x1d7c1
movq %rax, 0x18(%rbp)
movq %rbp, (%rsp)
movq %rbx, 0x20(%rbp)
movq 0x20(%rsp), %r15
movq (%r15), %rdi
addq %rdi, %rdi
movl $0x1, %esi
callq 0x2250
movq %r12, %r8
movq %rax, 0x40(%rsp)
shlq $0x20, %r14
movq (%r12), %rsi
movq 0x8(%r12), %r12
movq %rsi, %rax
shrq $0x3a, %rax
movl $0x1, %edx
movl %eax, %ecx
shlq %cl, %rdx
cmpq %rdx, %r12
movq %r8, 0x10(%rsp)
jne 0x19eb8
leal 0x1(%rax), %ebp
movl $0x1, %ebx
movl %ebp, %ecx
shlq %cl, %rbx
cmpq %r12, %rbx
jae 0x19e36
movq $-0x1, %rbp
movq (%rsp), %r9
incq %rbp
movq %r12, %rdx
movl %ebp, %ecx
shrq %cl, %rdx
cmpq $0x3f, %rbp
ja 0x19e10
testq %rdx, %rdx
jne 0x19dfa
cmpq %rbp, %rax
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
je 0x19f20
movl $0x1, %ebx
movl %ebp, %ecx
shlq %cl, %rbx
cmpq %rax, %rbp
jbe 0x1a5a3
movq 0x18(%r8), %rsi
movq 0x20(%r8), %rdi
movl $0x8, %edx
movl %ebp, %ecx
shlq %cl, %rdx
callq 0x1d8c9
movq 0x10(%rsp), %r8
movq %rax, 0x18(%r8)
movq (%r8), %rsi
movq 0x8(%r8), %rdx
movq (%rsp), %r9
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq %rsi, %rax
andq %r10, %rax
addq %rax, %rdx
cmpq %r12, %rdx
jbe 0x19ecd
movq 0x18(%r8), %rcx
movq %r12, %rdx
subq %rax, %rdx
movq %rbx, %rsi
subq %rdx, %rsi
leaq (%rcx,%rsi,8), %rdi
leaq (%rcx,%rax,8), %rsi
shlq $0x3, %rdx
callq 0x2370
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq (%rsp), %r9
movq 0x10(%rsp), %r8
subq %r12, %rbx
addq (%r8), %rbx
movq %rbx, %rsi
jmp 0x19ef9
movq 0x18(%rsp), %rbx
movq (%rsp), %r9
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
jmp 0x19f25
subq %rbx, %rdx
jbe 0x19ef9
movq 0x18(%r8), %rdi
leaq (%rdi,%rbx,8), %rsi
shlq $0x3, %rdx
callq 0x2370
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq (%rsp), %r9
movq 0x10(%rsp), %r8
movq (%r8), %rsi
movq %rbp, %rax
shlq $0x3a, %rax
andq %r10, %rsi
orq %rax, %rsi
movq $-0x1, %rax
movl %ebp, %ecx
shlq %cl, %rax
movq %rsi, (%r8)
notq %rax
movq %rax, 0x10(%r8)
movq 0x8(%r8), %r12
movq 0x18(%rsp), %rbx
movl $0x1, %edx
movq 0x18(%r8), %rax
leaq 0x1(%r12), %rcx
movq %rcx, 0x8(%r8)
andq %r10, %rsi
addq %r12, %rsi
andq 0x10(%r8), %rsi
movq %r14, (%rax,%rsi,8)
movq (%r9), %rsi
movq 0x8(%r9), %r14
movq %rsi, %rax
shrq $0x3a, %rax
movl %eax, %ecx
shlq %cl, %rdx
cmpq %rdx, %r14
jne 0x1a079
leal 0x1(%rax), %ebp
movl $0x1, %r12d
movl %ebp, %ecx
shlq %cl, %r12
cmpq %r14, %r12
jae 0x19fae
movq $-0x1, %rbp
incq %rbp
movq %r14, %rdx
movl %ebp, %ecx
shrq %cl, %rdx
cmpq $0x3f, %rbp
ja 0x19f91
testq %rdx, %rdx
jne 0x19f7b
cmpq %rbp, %rax
je 0x1a079
movl $0x1, %r12d
movl %ebp, %ecx
shlq %cl, %r12
cmpq %rax, %rbp
jbe 0x1a5ab
movq 0x18(%r9), %rsi
movq 0x20(%r9), %rdi
movl $0x8, %edx
movl %ebp, %ecx
shlq %cl, %rdx
callq 0x1d8c9
movq (%rsp), %r9
movq %rax, 0x18(%r9)
movq (%r9), %rsi
movq 0x8(%r9), %rdx
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq %rsi, %rax
andq %r10, %rax
addq %rax, %rdx
cmpq %r14, %rdx
jbe 0x1a026
movq 0x18(%r9), %rcx
movq %r14, %rdx
subq %rax, %rdx
movq %r12, %rsi
subq %rdx, %rsi
leaq (%rcx,%rsi,8), %rdi
leaq (%rcx,%rax,8), %rsi
shlq $0x3, %rdx
callq 0x2370
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq (%rsp), %r9
subq %r14, %r12
addq (%r9), %r12
movq %r12, %rsi
jmp 0x1a04d
subq %r12, %rdx
jbe 0x1a04d
movq 0x18(%r9), %rdi
leaq (%rdi,%r12,8), %rsi
shlq $0x3, %rdx
callq 0x2370
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq (%rsp), %r9
movq (%r9), %rsi
movq %rbp, %rax
shlq $0x3a, %rax
andq %r10, %rsi
orq %rax, %rsi
movq $-0x1, %rax
movl %ebp, %ecx
shlq %cl, %rax
movq %rsi, (%r9)
notq %rax
movq %rax, 0x10(%r9)
movq 0x8(%r9), %r14
movq 0x10(%rsp), %r8
movq 0x40(%rsp), %r12
movq 0x18(%r9), %rax
leaq 0x1(%r14), %rcx
movq %rcx, 0x8(%r9)
andq %r10, %rsi
addq %r14, %rsi
andq 0x10(%r9), %rsi
movq $0x0, (%rax,%rsi,8)
movq 0x8(%r8), %rax
testq %rax, %rax
je 0x1a506
movl 0xc(%rsp), %ecx
orl %ecx, 0x2c(%rsp)
movq 0x48(%rsp), %rcx
orq %rcx, 0x50(%rsp)
movq (%r8), %rcx
movq 0x18(%r8), %rdx
movq %rcx, %rsi
andq %r10, %rsi
leaq 0x1(%rcx), %rdi
andq %r10, %rdi
movabsq $-0x400000000000000, %r11 # imm = 0xFC00000000000000
andq %r11, %rcx
andq 0x10(%r8), %rdi
orq %rcx, %rdi
movq %rdi, (%r8)
decq %rax
movq %rax, 0x8(%r8)
movq (%rdx,%rsi,8), %rdi
movq (%r9), %rcx
movq 0x18(%r9), %rdx
leaq 0x1(%rcx), %rax
andq %r10, %rax
movq %rcx, %rsi
andq %r11, %rsi
andq 0x10(%r9), %rax
orq %rsi, %rax
movq %rax, (%r9)
decq 0x8(%r9)
movq %rdi, %rax
shrq $0x20, %rax
cmpb $0x0, (%r12,%rax)
je 0x1a12f
movq 0x8(%r8), %rax
testq %rax, %rax
jne 0x1a0bb
jmp 0x1a506
andq %r10, %rcx
movq (%rdx,%rcx,8), %r11
movb $0x1, (%r12,%rax)
cmpl %edi, 0x2c(%rsp)
jbe 0x1a121
cmpq 0x50(%rsp), %r11
jae 0x1a121
movq 0x38(%r15), %rcx
movl (%rcx,%rax,8), %edx
testl %edx, %edx
je 0x1a121
movq 0x30(%r15), %rcx
movq (%rcx,%rax,8), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
addq 0x28(%r15), %rax
movq %rax, 0x48(%rsp)
movl %edi, %eax
incl %eax
movq %rax, 0x60(%rsp)
xorl %r14d, %r14d
movq %rdi, 0x38(%rsp)
movq %r11, 0x30(%rsp)
movl %edx, 0xc(%rsp)
movl %r14d, %eax
leaq (%rax,%rax,2), %rbp
shlq $0x4, %rbp
movq 0x48(%rsp), %rax
movq 0x8(%rax,%rbp), %r13
cmpq %rbx, %r13
je 0x1a531
cmpb $0x0, (%r12,%r13)
jne 0x1a4e5
movq (%r8), %rsi
movq 0x8(%r8), %r12
movq %rsi, %rax
shrq $0x3a, %rax
movl $0x1, %edx
movl %eax, %ecx
shlq %cl, %rdx
cmpq %rdx, %r12
jne 0x1a31b
leal 0x1(%rax), %ebx
movl $0x1, %r15d
movl %ebx, %ecx
shlq %cl, %r15
cmpq %r12, %r15
jae 0x1a228
movq $-0x1, %rbx
incq %rbx
movq %r12, %rdx
movl %ebx, %ecx
shrq %cl, %rdx
cmpq $0x3f, %rbx
ja 0x1a200
testq %rdx, %rdx
jne 0x1a1ea
cmpq %rbx, %rax
jne 0x1a214
movq 0x20(%rsp), %r15
movq 0x18(%rsp), %rbx
jmp 0x1a31b
movl $0x1, %r15d
movl %ebx, %ecx
shlq %cl, %r15
cmpq %rax, %rbx
jbe 0x1a4f6
movq 0x18(%r8), %rsi
movq 0x20(%r8), %rdi
movl $0x8, %edx
movl %ebx, %ecx
shlq %cl, %rdx
callq 0x1d8c9
movq 0x10(%rsp), %r8
movq %rax, 0x18(%r8)
movq (%r8), %rsi
movq 0x8(%r8), %rdx
movq (%rsp), %r9
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq 0x30(%rsp), %r11
movq %rsi, %rax
andq %r10, %rax
addq %rax, %rdx
cmpq %r12, %rdx
jbe 0x1a2b4
movq 0x18(%r8), %rcx
movq %r12, %rdx
subq %rax, %rdx
movq %r15, %rsi
subq %rdx, %rsi
leaq (%rcx,%rsi,8), %rdi
leaq (%rcx,%rax,8), %rsi
shlq $0x3, %rdx
callq 0x2370
movq 0x30(%rsp), %r11
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq (%rsp), %r9
movq 0x10(%rsp), %r8
subq %r12, %r15
addq (%r8), %r15
movq %r15, %rsi
jmp 0x1a2e5
subq %r15, %rdx
jbe 0x1a2e5
movq 0x18(%r8), %rdi
leaq (%rdi,%r15,8), %rsi
shlq $0x3, %rdx
callq 0x2370
movq 0x30(%rsp), %r11
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq (%rsp), %r9
movq 0x10(%rsp), %r8
movq (%r8), %rsi
movq %rbx, %rax
shlq $0x3a, %rax
andq %r10, %rsi
orq %rax, %rsi
movq $-0x1, %rax
movl %ebx, %ecx
shlq %cl, %rax
movq %rsi, (%r8)
notq %rax
movq %rax, 0x10(%r8)
movq 0x8(%r8), %r12
movq 0x20(%rsp), %r15
movq 0x18(%rsp), %rbx
movq 0x38(%rsp), %rdi
addq 0x48(%rsp), %rbp
shlq $0x20, %r13
movq 0x18(%r8), %rax
leaq 0x1(%r12), %rcx
movq %rcx, 0x8(%r8)
andq %r10, %rsi
addq %r12, %rsi
andq 0x10(%r8), %rsi
addq 0x60(%rsp), %r13
movq %r13, (%rax,%rsi,8)
movq 0x10(%r15), %rax
movq 0x8(%rbp), %rcx
shrq %rcx
leaq (%rcx,%rcx,4), %rcx
movq 0x18(%rax,%rcx,8), %r13
addq %r11, %r13
subq 0x18(%rbp), %r13
movq (%r9), %rsi
movq 0x8(%r9), %r12
movq %rsi, %rax
shrq $0x3a, %rax
movl $0x1, %edx
movl %eax, %ecx
shlq %cl, %rdx
cmpq %rdx, %r12
jne 0x1a4c1
leal 0x1(%rax), %ebx
movl $0x1, %r15d
movl %ebx, %ecx
shlq %cl, %r15
cmpq %r12, %r15
jae 0x1a3d8
movq $-0x1, %rbx
incq %rbx
movq %r12, %rdx
movl %ebx, %ecx
shrq %cl, %rdx
cmpq $0x3f, %rbx
ja 0x1a3b0
testq %rdx, %rdx
jne 0x1a39a
cmpq %rbx, %rax
jne 0x1a3c4
movq 0x20(%rsp), %r15
movq 0x18(%rsp), %rbx
jmp 0x1a4c1
movl $0x1, %r15d
movl %ebx, %ecx
shlq %cl, %r15
cmpq %rax, %rbx
jbe 0x1a4fe
movq 0x18(%r9), %rsi
movq 0x20(%r9), %rdi
movl $0x8, %edx
movl %ebx, %ecx
shlq %cl, %rdx
callq 0x1d8c9
movq (%rsp), %r9
movq %rax, 0x18(%r9)
movq (%r9), %rsi
movq 0x8(%r9), %rdx
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq 0x38(%rsp), %rdi
movq %rsi, %rax
andq %r10, %rax
addq %rax, %rdx
cmpq %r12, %rdx
jbe 0x1a45a
movq 0x18(%r9), %rcx
movq %r12, %rdx
subq %rax, %rdx
movq %r15, %rsi
subq %rdx, %rsi
leaq (%rcx,%rsi,8), %rdi
leaq (%rcx,%rax,8), %rsi
shlq $0x3, %rdx
callq 0x2370
movq 0x38(%rsp), %rdi
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq (%rsp), %r9
subq %r12, %r15
addq (%r9), %r15
movq %r15, %rsi
jmp 0x1a486
subq %r15, %rdx
jbe 0x1a486
movq 0x18(%r9), %rdi
leaq (%rdi,%r15,8), %rsi
shlq $0x3, %rdx
callq 0x2370
movq 0x38(%rsp), %rdi
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq (%rsp), %r9
movq (%r9), %rsi
movq %rbx, %rax
shlq $0x3a, %rax
andq %r10, %rsi
orq %rax, %rsi
movq $-0x1, %rax
movl %ebx, %ecx
shlq %cl, %rax
movq %rsi, (%r9)
notq %rax
movq %rax, 0x10(%r9)
movq 0x8(%r9), %r12
movq 0x20(%rsp), %r15
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %r8
movq 0x30(%rsp), %r11
movl 0xc(%rsp), %edx
movq 0x18(%r9), %rax
leaq 0x1(%r12), %rcx
movq %rcx, 0x8(%r9)
andq %r10, %rsi
addq %r12, %rsi
andq 0x10(%r9), %rsi
movq %r13, (%rax,%rsi,8)
movq 0x40(%rsp), %r12
incl %r14d
cmpl %edx, %r14d
jne 0x1a186
jmp 0x1a121
movq %r12, %rdx
jmp 0x1a262
movq %r12, %rdx
jmp 0x1a40d
xorl %ebp, %ebp
cmpq $0x0, 0x8(%r9)
movq %r9, %r14
je 0x1a555
leaq 0x67d7(%rip), %rdi      # 0x20cf0
leaq 0x67e1(%rip), %rsi      # 0x20d01
leaq 0x683f(%rip), %rcx      # 0x20d66
movl $0x502, %edx            # imm = 0x502
callq 0x21d0
movq 0x58(%rsp), %rax
testq %rax, %rax
je 0x1a53d
movl %edi, (%rax)
movl $0x1, %ebp
movq 0xa0(%rsp), %rax
testq %rax, %rax
je 0x1a552
movq %r11, (%rax)
movq %r9, %r14
movq 0x18(%r8), %rsi
movq 0x20(%r8), %rdi
movq %r8, %rbx
callq 0x1d6fb
movq 0x20(%rbx), %rdi
movq %rbx, %rsi
callq 0x1d6fb
movq 0x18(%r14), %rsi
movq 0x20(%r14), %rdi
callq 0x1d6fb
movq 0x20(%r14), %rdi
movq %r14, %rsi
callq 0x1d6fb
movq %r12, %rdi
callq 0x2060
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdx
jmp 0x19e6b
movq %r14, %rdx
jmp 0x19fde