// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, (%rsp)
movq %rdi, %r13
movq (%rdi), %rcx
movq 0x8(%rdi), %rax
movq %rcx, 0x8(%rsp)
cmpq %rax, %rcx
jne 0x53fd0
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x8(%r13)
movq 0x10(%r13), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%r13)
movq (%r13), %rax
movq 0x10(%r13), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r13)
movq %r14, (%rcx,%rax,8)
movq (%r13), %rax
cmpq 0x8(%rsp), %rax
jbe 0x54169
movq 0x10(%r13), %rsi
leaq -0x1(%rax), %rcx
movq %rcx, (%r13)
movq -0x8(%rsi,%rax,8), %r14
movq %r14, %rbp
shrq $0x20, %rbp
movl %r14d, %eax
movq 0x18(%rsp), %rcx
movl $0x1, (%rcx,%rax,4)
movq 0x10(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
testq %rax, %rax
je 0x54037
movq (%rsp), %rcx
movq (%rcx,%rax,8), %r8
subq -0x8(%rcx,%rax,8), %r8
jmp 0x5403e
movq (%rsp), %rcx
movq (%rcx), %r8
testq %rax, %rax
je 0x54050
movq (%rsp), %rcx
movq -0x8(%rcx,%rax,8), %rax
leaq (%rsi,%rax,8), %rsi
testq %r8, %r8
je 0x540e2
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
andq %rax, %r14
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r14
xorl %ebp, %ebp
movq %rsi, 0x20(%rsp)
movq (%rsi,%rbp,8), %r12
orq %r14, %r12
movq 0x8(%r13), %rax
cmpq %rax, (%r13)
jne 0x540c1
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r13)
movq 0x10(%r13), %rdi
shlq $0x3, %rsi
movq %rbx, %r15
movq %r8, %rbx
callq 0x2370
movq %rbx, %r8
movq %r15, %rbx
movq 0x20(%rsp), %rsi
movq %rax, 0x10(%r13)
movq (%r13), %rax
movq 0x10(%r13), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r13)
movq %r12, (%rcx,%rax,8)
incq %rbp
cmpq %rbp, %r8
jne 0x5407a
jmp 0x53fe4
movq (%rbx), %rax
testq %rax, %rax
je 0x5410f
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 0x54112
xorl %r14d, %r14d
movq 0x10(%rsp), %rax
movl (%rax,%rbp,8), %r15d
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x54149
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
orq %r14, %r15
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movq %r15, (%rcx,%rax,8)
addq $-0x1, %rbp
jb 0x54112
jmp 0x53fe4
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq