// File: /workspace/github_cpp_makefile_star2_O3/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, 0x8(%rsp)
movq %r8, %r14
movq %rcx, 0x10(%rsp)
movq %rdx, 0x20(%rsp)
movq %rsi, (%rsp)
movq %rdi, %r13
movq (%rdi), %rbx
cmpq 0x8(%rdi), %rbx
jne 0x53132
leaq (%rbx,%rbx), %rax
testq %rbx, %rbx
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x8(%r13)
movq 0x10(%r13), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%r13)
movq (%r13), %rcx
jmp 0x53139
movq 0x10(%r13), %rax
movq %rbx, %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r13)
movq %r14, (%rax,%rcx,8)
movq (%r13), %rcx
cmpq %rbx, %rcx
jbe 0x532b5
movq %rbx, 0x18(%rsp)
movq 0x10(%r13), %rax
leaq -0x1(%rcx), %rdx
movq %rdx, (%r13)
movq -0x8(%rax,%rcx,8), %r12
movq %r12, %rbp
shrq $0x20, %rbp
movl %r12d, %ecx
movq 0x20(%rsp), %rdx
movl $0x1, (%rdx,%rcx,4)
movq 0x10(%rsp), %rdx
movq %rcx, (%rdx,%rbp,8)
testq %rcx, %rcx
je 0x531a2
movq (%rsp), %rsi
movq -0x8(%rsi,%rcx,8), %rdx
movq (%rsi,%rcx,8), %r15
subq %rdx, %r15
leaq (%rax,%rdx,8), %r14
jmp 0x531ac
movq (%rsp), %rcx
movq (%rcx), %r15
movq %rax, %r14
testq %r15, %r15
je 0x5321f
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %r12
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq %rcx, %r12
xorl %ebp, %ebp
movq (%r14,%rbp,8), %rbx
orq %r12, %rbx
movq (%r13), %rcx
cmpq 0x8(%r13), %rcx
jne 0x53206
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r13)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r13)
movq (%r13), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r13)
movq %rbx, (%rax,%rcx,8)
incq %rbp
cmpq %rbp, %r15
jne 0x531cd
jmp 0x532a6
movq 0x8(%rsp), %rax
movq (%rax), %rcx
movq 0x10(%rax), %rax
testq %rcx, %rcx
je 0x53251
movq -0x8(%rax,%rcx,8), %r14
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %r14
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq %rcx, %r14
jmp 0x53254
xorl %r14d, %r14d
movq 0x10(%rsp), %rcx
movl (%rcx,%rbp,8), %r15d
movq 0x8(%rsp), %rbx
movq (%rbx), %rcx
cmpq 0x8(%rbx), %rcx
jne 0x53292
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
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)
addq $-0x1, %rbp
jb 0x53254
movq (%r13), %rcx
cmpq 0x18(%rsp), %rcx
ja 0x53157
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq