// File: chhylp123[P]hifiasm/ecovlp.cpp
// Function: append_cns_g(cns_gfa*, char*, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, asg32_v*, unsigned long, unsigned int, long)
uint64_t append_cns_g(cns_gfa *cns, char *tstr, uint64_t tl, uint64_t qs, uint64_t qe, uint64_t cp, uint64_t cl, uint64_t pe, asg32_v* b32, uint64_t max_trace, uint32_t rid, int64_t insert_pos)
{
    // fprintf(stderr, ">q::[%lu, %lu)\n", qs, qe);
    uint64_t s0 = pe, plus0 = 1, ns = qs + cns->off, ne = qe + cns->off;
    if(pe == ((uint64_t)-1)) {
        if(qs > 0) {
            s0 = qs - 1 + cns->off;///just before node in backbone
        } else {
            s0 = 0;//beg
        }
        // plus0 = 0;
    }

    // fprintf(stderr, "+n_nodes::%u, tl::%lu, qs::%lu, qe::%lu\n", (uint32_t)cns->n, tl, qs, qe);

    if(cp == 0) {
        if((cl == 0) && (cp == 0) && (qs == qe) && (((int64_t)qe) == insert_pos)) {
            s0 = 0;//beg
            ns = ne = 1;//end
            plus0 = 1;
        }
        // if(cp == 0) {
        //     fprintf(stderr, "cp::%lu, cl::%lu, qs::%lu, qe::%lu, s0::%lu, ns::%lu, ne::%lu, plus0::%lu\n", cp, cl, qs, qe, s0, ns, ne, plus0);
        // }
        return push_cns_c0(cns, s0, ns, ne, plus0, rid);
    } else if(cp == 1 || cp == 2) { ///cp == 2: more y -> insertion
        return push_cns_c1(cns, s0, tstr, tl, plus0, b32, max_trace, rid);
    } else { ///more x -> do nothing
        return s0;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x38(%rbp), %rax
movl 0x30(%rbp), %eax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq 0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq $0x1, -0x48(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x20(%rcx), %ecx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x20(%rcx), %ecx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
cmpq $-0x1, 0x18(%rbp)
jne 0x24d67b
cmpq $0x0, -0x28(%rbp)
jbe 0x24d671
movq -0x28(%rbp), %rax
subq $0x1, %rax
movq -0x10(%rbp), %rcx
movl 0x20(%rcx), %ecx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
jmp 0x24d679
movq $0x0, -0x40(%rbp)
jmp 0x24d67b
cmpq $0x0, -0x38(%rbp)
jne 0x24d6ec
cmpq $0x0, 0x10(%rbp)
jne 0x24d6c4
cmpq $0x0, -0x38(%rbp)
jne 0x24d6c4
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
jne 0x24d6c4
movq -0x30(%rbp), %rax
cmpq 0x38(%rbp), %rax
jne 0x24d6c4
movq $0x0, -0x40(%rbp)
movq $0x1, -0x58(%rbp)
movq $0x1, -0x50(%rbp)
movq $0x1, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x58(%rbp), %rcx
movq -0x48(%rbp), %rax
movl %eax, %r8d
movl 0x30(%rbp), %r9d
callq 0x24cc60
movl %eax, %eax
movq %rax, -0x8(%rbp)
jmp 0x24d739
cmpq $0x1, -0x38(%rbp)
je 0x24d6fa
cmpq $0x2, -0x38(%rbp)
jne 0x24d731
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x48(%rbp), %rax
movl %eax, %r8d
movq 0x20(%rbp), %r9
movq 0x28(%rbp), %r10
movl 0x30(%rbp), %eax
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x24d4f0
movl %eax, %eax
movq %rax, -0x8(%rbp)
jmp 0x24d739
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)