// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: gen_rphase_path(asg64_v*, long*, int*, long*, unsigned long, asg64_v*)
void gen_rphase_path(asg64_v *idx, int64_t *cn, int32_t *f, int64_t *p, uint64_t v0, asg64_v *res)
{
    uint64_t n0 = idx->n, pn = 0, v, w, ct, *ca, k, gi;
    kv_push(uint64_t, *idx, v0); 
    while (idx->n > n0) {
        v = idx->a[--idx->n];
        pn = v>>32; v = (uint32_t)v;
        f[v] = 1; p[pn++] = v;
        ct = ((v>0)?(cn[v]-cn[v-1]):(cn[v]));
        ca = ((v>0)?(idx->a+cn[v-1]):(idx->a));
        if(ct) {
            for (k = 0; k < ct; k++) {
                w = ((pn<<32)|ca[k]);
                kv_push(uint64_t, *idx, w); 
            }
        } else {
            gi = ((res->n)?((res->a[res->n-1]>>32)+1):(0));
            for (k = 0; k < pn; k++) {
                w = (gi<<32)|((uint32_t)p[pn-k-1]);
                kv_push(uint64_t, *res, w);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %rbx
movq %r8, %r14
movq %rcx, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, (%rsp)
movq %rdi, %r12
movq (%rdi), %rcx
pushq $0x2
popq %rax
cmpq 0x8(%rdi), %rcx
movq %rcx, 0x18(%rsp)
jne 0x24f54
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %rax, %rsi
movq %rsi, 0x8(%r12)
movq 0x10(%r12), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rcx
jmp 0x24f59
movq 0x10(%r12), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, (%r12)
movq %r14, (%rax,%rcx,8)
movq (%r12), %rcx
cmpq 0x18(%rsp), %rcx
jbe 0x250e2
movq 0x10(%r12), %rax
leaq -0x1(%rcx), %rdx
movq %rdx, (%r12)
movq -0x8(%rax,%rcx,8), %r15
movq %r15, %rbp
shrq $0x20, %rbp
movl %r15d, %ecx
movq 0x10(%rsp), %rdx
movl $0x1, (%rdx,%rcx,4)
movq 0x8(%rsp), %rdx
movq %rcx, (%rdx,%rbp,8)
testq %rcx, %rcx
je 0x24fc0
movq (%rsp), %rsi
movq -0x8(%rsi,%rcx,8), %rdx
movq (%rsi,%rcx,8), %r8
subq %rdx, %r8
leaq (%rax,%rdx,8), %rsi
jmp 0x24fca
movq (%rsp), %rcx
movq (%rcx), %r8
movq %rax, %rsi
testq %r8, %r8
je 0x25059
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %r15
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq %rcx, %r15
xorl %ebp, %ebp
movq %rsi, 0x20(%rsp)
cmpq %rbp, %r8
je 0x24f65
movq (%rsi,%rbp,8), %r14
orq %r15, %r14
movq (%r12), %rcx
cmpq 0x8(%r12), %rcx
jne 0x25048
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r12)
shlq $0x3, %rsi
movq %rax, %rdi
movq %rbx, %r13
movq %r8, %rbx
callq 0x2370
movq %rbx, %r8
movq %r13, %rbx
movq 0x20(%rsp), %rsi
movq %rax, 0x10(%r12)
movq (%r12), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r12)
movq %r14, (%rax,%rcx,8)
incq %rbp
jmp 0x24ff4
movq (%rbx), %rax
testq %rax, %rax
je 0x25086
movq 0x10(%rbx), %rcx
movq -0x8(%rcx,%rax,8), %r14
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
andq %rax, %r14
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r14
jmp 0x250d7
xorl %r14d, %r14d
jmp 0x250d7
movq 0x8(%rsp), %rax
movl (%rax,%rbp,8), %r15d
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x250c6
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
orq %r14, %r15
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
movq %r15, (%rax,%rcx,8)
decq %rbp
cmpq $-0x1, %rbp
jne 0x2508b
jmp 0x24f65
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq