// File: /workspace/github_cpp_makefile_star2_O3/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 $0x18, %rsp
movq %rdx, %r13
movl $0x0, 0x8(%rdi)
movl (%r9), %eax
movl %eax, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpl 0x10(%rsi), %edx
jne 0x58e23
movq %rsi, %r15
movq %r8, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
shrl $0x1f, %eax
xorl %r14d, %r14d
cmpl 0x1c(%rsi), %eax
jne 0x58e26
movq %r9, %r12
movq %rdi, %rbx
movl 0x4(%r9), %eax
movl 0x8(%r9), %ecx
movl %ecx, %esi
subl %eax, %esi
cmovbl %r14d, %esi
subl %ecx, %eax
cmovbl %r14d, %eax
movq 0x50(%rsp), %rdi
movl %esi, 0x4(%r15)
movl %eax, 0x14(%r15)
cmpq $0x1, %r13
jne 0x58dab
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3d202
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
jle 0x58e38
movq %r13, (%rsp)
leaq 0x8(%r12), %r13
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %r14d, %r14d
movl -0x8(%r13), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpl 0x10(%r15), %edx
jne 0x58e1d
shrl $0x1f, %ecx
cmpl 0x1c(%r15), %ecx
jne 0x58e1d
movl -0x4(%r13), %ebp
movl (%r13), %esi
movl %esi, %ecx
subl 0x4(%r15), %ecx
subl 0x14(%r15), %ebp
subq %rcx, %rbp
cmpq %rax, %rbp
je 0x58e0e
movq %rbx, %rdi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x3d202
movq 0x50(%rsp), %rdi
movq %rbp, %rax
incq %r14
addq $0x10, %r13
cmpq %r14, %rdi
jne 0x58dc5
movq %rdi, %r14
movq (%rsp), %r13
jmp 0x58e3b
xorl %r14d, %r14d
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
movq %r14, %rcx
shlq $0x4, %rcx
movl -0xc(%r12,%rcx), %eax
movl -0x8(%r12,%rcx), %ecx
movq %rax, %rdx
notq %rdx
movq 0x8(%rsp), %r8
addq %r8, %rdx
leal (%rdx,%rcx), %esi
notq %rcx
movq 0x10(%rsp), %rdi
addq %rdi, %rcx
decl %r8d
decl %edi
addl %ecx, %eax
cmpq %rdx, %rcx
cmovgl %r8d, %eax
cmovgl %esi, %edi
movl %eax, 0x18(%r15)
movl %edi, 0x8(%r15)
cmpq $0x1, %r13
jne 0x58e26
movl 0x8(%rbx), %esi
decl %esi
movq %rbx, %rdi
callq 0x3d110
cltq
movl 0x8(%r15), %r15d
cmpq %r15, %rax
je 0x58e26
movl 0x8(%rbx), %esi
decl %esi
movq %rbx, %rdi
callq 0x3d11b
movq %rbx, %rdi
movl %r15d, %esi
movl %eax, %edx
xorl %ecx, %ecx
callq 0x3d202
jmp 0x58e26