// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
movq %rdx, %r13
movl $0x0, 0x8(%rdi)
movl (%r9), %eax
movl %eax, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpl 0x10(%rsi), %edx
jne 0x598e0
movq %rsi, %r14
shrl $0x1f, %eax
cmpl 0x1c(%rsi), %eax
jne 0x598e0
movq %rdi, %rbx
movq %r8, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
movl 0x8(%r9), %eax
leaq 0x4(%r14), %r12
movl %eax, 0x4(%r14)
movq %r9, 0x10(%rsp)
movl 0x4(%r9), %ecx
leaq 0x14(%r14), %rdi
movl %ecx, 0x14(%r14)
movl %eax, %edx
subl %ecx, %edx
jbe 0x598f5
movl %edx, (%r12)
movq %rdi, %rax
jmp 0x598fc
xorl %r13d, %r13d
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subl %eax, %ecx
movl %ecx, (%rdi)
movq %r12, %rax
movq 0x70(%rsp), %r15
movl $0x0, (%rax)
cmpq $0x1, %r13
jne 0x59923
movl (%r12), %esi
movq %rdi, %rbp
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3dd21
movq %rbp, %rdi
movq %r13, 0x28(%rsp)
testq %r15, %r15
jle 0x599b9
movq %rbx, 0x8(%rsp)
movq 0x10(%rsp), %rax
leaq 0x8(%rax), %rbx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %r13d, %r13d
movq %r14, 0x30(%rsp)
movl -0x8(%rbx), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpl 0x10(%r14), %edx
jne 0x599b2
shrl $0x1f, %ecx
cmpl 0x1c(%r14), %ecx
jne 0x599b2
movl -0x4(%rbx), %ebp
movl (%rbx), %esi
movl %esi, %ecx
subl (%r12), %ecx
subl (%rdi), %ebp
subq %rcx, %rbp
cmpq %rax, %rbp
je 0x599a3
movq %r15, %r14
movq %r12, %r15
movq %rdi, %r12
movq 0x8(%rsp), %rdi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x3dd21
movq %r12, %rdi
movq %r15, %r12
movq %r14, %r15
movq 0x30(%rsp), %r14
movq %rbp, %rax
incq %r13
addq $0x10, %rbx
cmpq %r13, %r15
jne 0x5994c
movq %r15, %r13
movq 0x8(%rsp), %rbx
jmp 0x599bc
xorl %r13d, %r13d
movq %r13, %rcx
shlq $0x4, %rcx
movq 0x10(%rsp), %rdx
movl -0x8(%rdx,%rcx), %eax
movl %eax, 0x8(%r14)
movl -0xc(%rdx,%rcx), %edx
movq %rax, %rcx
notq %rcx
movq 0x20(%rsp), %r9
addq %r9, %rcx
movl %edx, %esi
movl %edx, 0x18(%r14)
notq %rdx
movq 0x18(%rsp), %r10
addq %r10, %rdx
xorl %edi, %edi
xorl %r8d, %r8d
cmpq %rdx, %rcx
setle %dil
cmovlq %rcx, %rdx
cmovgl %eax, %esi
cmovgl %r10d, %r9d
setg %r8b
shll $0x4, %r8d
shll $0x4, %edi
decl %r9d
addl %esi, %edx
movl %r9d, 0x8(%r14,%r8)
movl %edx, 0x8(%r14,%rdi)
cmpq $0x1, 0x28(%rsp)
jne 0x598e3
movl 0x8(%rbx), %esi
decl %esi
movq %rbx, %rdi
callq 0x3dc2f
cltq
movl 0x8(%r14), %r14d
cmpq %r14, %rax
je 0x598e3
movl 0x8(%rbx), %esi
decl %esi
movq %rbx, %rdi
callq 0x3dc3a
movq %rbx, %rdi
movl %r14d, %esi
movl %eax, %edx
xorl %ecx, %ecx
callq 0x3dd21
jmp 0x598e3