// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: update_ov_track_0(Fake_Cigar*, overlap_region*, long, long, long, k_mer_hit*, long)
uint64_t update_ov_track_0(Fake_Cigar* z, overlap_region *o, int64_t apend_be, int64_t xl, int64_t yl,
k_mer_hit* hit, int64_t n_hit)
{
    int64_t k, dq, dr, dd, pdd = INT32_MAX, xr, yr; 
    z->length = 0;
    if(hit[0].readID != o->y_id || hit[0].strand != o->y_pos_strand) return 0;
    ///update o->s
    o->x_pos_s = hit[0].self_offset; o->y_pos_s = hit[0].offset;
    if(o->x_pos_s <= o->y_pos_s) {
        o->y_pos_s -= o->x_pos_s; o->x_pos_s = 0;
    } else {
        o->x_pos_s -= o->y_pos_s; o->y_pos_s = 0;
    }

    if(apend_be == 1) add_fake_cigar(z, o->x_pos_s, 0, NULL);
    for (k = 0; (k < n_hit) && (hit[k].readID == o->y_id) && (hit[k].strand == o->y_pos_strand); k++) {
        dq = hit[k].self_offset - o->x_pos_s; 
        dr = hit[k].offset - o->y_pos_s; 
        dd = dr - dq;
        if(dd != pdd) {
            pdd = dd;
            add_fake_cigar(z, hit[k].self_offset, pdd, NULL);
        }
    }
    ///update o->s
    o->x_pos_e = hit[k-1].self_offset; o->y_pos_e = hit[k-1].offset;
    xr = xl-o->x_pos_e-1; yr = yl-o->y_pos_e-1;
    if(xr <= yr) {
        o->x_pos_e = xl-1; o->y_pos_e += xr;        
    } else {
        o->y_pos_e = yl-1; o->x_pos_e += yr; 
    }

    if((apend_be == 1) && (get_fake_gap_pos(z, z->length-1)!=((int64_t)o->x_pos_e))) {
        add_fake_cigar(z, o->x_pos_e, get_fake_gap_shift(z, z->length-1), NULL);
    }

    return k;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r15
andl $0x0, 0x8(%rdi)
movl (%r9), %esi
movl %esi, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl 0x10(%r15), %eax
jne 0x29aa9
shrl $0x1f, %esi
xorl %eax, %eax
cmpl 0x1c(%r15), %esi
jne 0x29aa9
movq %r9, %rbx
movq %r8, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movl 0x4(%r9), %ecx
movl 0x8(%r9), %r8d
movl %r8d, %esi
subl %ecx, %esi
cmovbl %eax, %esi
subl %r8d, %ecx
cmovbl %eax, %ecx
movq 0x60(%rsp), %r13
movl %esi, 0x4(%r15)
movl %ecx, 0x14(%r15)
movq %rdx, 0x20(%rsp)
cmpq $0x1, %rdx
movq %rdi, %r12
jne 0x29a40
movq %r12, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x11af6
movq %r12, %rdi
xorl %r14d, %r14d
testq %r13, %r13
cmovleq %r14, %r13
movq %rbx, 0x8(%rsp)
addq $0x8, %rbx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %r14, %r13
je 0x29ac1
movl -0x8(%rbx), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpl 0x10(%r15), %edx
jne 0x29abe
shrl $0x1f, %ecx
cmpl 0x1c(%r15), %ecx
jne 0x29abe
movl -0x4(%rbx), %ebp
movl (%rbx), %esi
movl %esi, %ecx
subl 0x4(%r15), %ecx
subl 0x14(%r15), %ebp
subq %rcx, %rbp
cmpq %rax, %rbp
je 0x29aa0
movq %r12, %rdi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x11af6
movq %r12, %rdi
movq %rbp, %rax
incq %r14
addq $0x10, %rbx
jmp 0x29a58
xorl %r13d, %r13d
movq %r13, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %r13
movq %r13, %rcx
shlq $0x4, %rcx
movq 0x8(%rsp), %rdx
movl -0xc(%rdx,%rcx), %eax
movl -0x8(%rdx,%rcx), %ecx
movq %rax, %rdx
notq %rdx
movq 0x10(%rsp), %r9
addq %r9, %rdx
leal (%rdx,%rcx), %esi
notq %rcx
movq 0x18(%rsp), %r8
addq %r8, %rcx
decl %r9d
decl %r8d
addl %ecx, %eax
cmpq %rdx, %rcx
cmovgl %r9d, %eax
cmovgl %esi, %r8d
movl %eax, 0x18(%r15)
movl %r8d, 0x8(%r15)
cmpq $0x1, 0x20(%rsp)
jne 0x29aac
movl 0x8(%rdi), %esi
decl %esi
movq %rdi, %rbx
callq 0x11a00
cltq
movl 0x8(%r15), %r15d
cmpq %r15, %rax
je 0x29aac
movl 0x8(%rbx), %esi
decl %esi
movq %rbx, %rdi
callq 0x11a0b
movq %rbx, %rdi
movl %r15d, %esi
movl %eax, %edx
xorl %ecx, %ecx
callq 0x11af6
jmp 0x29aac