// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: update_ov_track_hpc_0(Fake_Cigar*, overlap_region*, long, long, unsigned int*, long, unsigned char*, hpc_t*, k_mer_hit*, long)
uint64_t update_ov_track_hpc_0(Fake_Cigar* z, overlap_region *o, int64_t apend_be, int64_t xhl,
uint32_t *x_idx, int64_t y_idx_map_l, uint8_t *y_idx_map, hpc_t *hpc_g, k_mer_hit* hit, int64_t n_hit)
{
    int64_t k, dq, dr, dd, pdd = INT32_MAX, xr, yr, yhl, mo = 0, so = 0, ho = 0, x1, y1; 
    z->length = 0;
    if(hit[0].readID != o->y_id || hit[0].strand != o->y_pos_strand) return 0;
    yhl = hpc_len(*hpc_g, o->y_id);

    x1 = x_idx[hit[0].self_offset];
    y1 = iter_hpc(y_idx_map, y_idx_map_l, &mo, o->y_pos_strand, &so, &ho, hit[0].offset); 
    assert(y1 >= 0);
    o->x_pos_s = x1; o->y_pos_s = y1;
    
    ///update o->s
    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++) {
        x1 = x_idx[hit[k].self_offset];
        y1 = iter_hpc(y_idx_map, y_idx_map_l, &mo, o->y_pos_strand, &so, &ho, hit[k].offset); 
        assert(y1 >= 0);
        dq = x1 - o->x_pos_s; 
        dr = y1 - o->y_pos_s; 
        dd = dr - dq;
        if(dd != pdd) {
            pdd = dd;
            add_fake_cigar(z, x1, pdd, NULL);
        }
    }
    ///update o->s
    x1 = x_idx[hit[k-1].self_offset];
    y1 = iter_hpc(y_idx_map, y_idx_map_l, &mo, o->y_pos_strand, &so, &ho, hit[k-1].offset); 
    assert(y1 >= 0);
    o->x_pos_e = x1; o->y_pos_e = y1;
    xr = xhl-o->x_pos_e-1; yr = yhl-o->y_pos_e-1;
    if(xr <= yr) {
        o->x_pos_e = xhl-1; o->y_pos_e += xr;        
    } else {
        o->y_pos_e = yhl-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 $0x58, %rsp
movq %r9, 0x30(%rsp)
movq %r8, 0x28(%rsp)
movq %rcx, %rbp
movq 0xa0(%rsp), %rax
xorl %r13d, %r13d
movq %r13, 0x48(%rsp)
movq %r13, 0x40(%rsp)
movq %r13, 0x38(%rsp)
movl $0x0, 0x8(%rdi)
movl (%rax), %ecx
movl %ecx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl 0x10(%rsi), %eax
jne 0x5923b
movq %rsi, %r14
shrl $0x1f, %ecx
cmpl 0x1c(%rsi), %ecx
jne 0x59160
movq %rdx, %r12
movq %rdi, %r15
movq 0x98(%rsp), %rdx
movq 0x90(%rsp), %rdi
movq (%rdx), %rdx
movq 0x10(%rdx), %rdx
leaq (%rax,%rax,4), %rax
movl (%rdx,%rax,8), %r13d
movq 0xa0(%rsp), %rdx
movl 0x4(%rdx), %eax
movl 0x8(%rdx), %edx
movq 0x28(%rsp), %rsi
movl (%rsi,%rdx,4), %ebx
movq %rax, (%rsp)
leaq 0x48(%rsp), %rdx
leaq 0x40(%rsp), %r8
leaq 0x38(%rsp), %r9
movq 0x30(%rsp), %rsi
callq 0x58ec0
testq %rax, %rax
js 0x5926c
xorl %ecx, %ecx
movl %ebx, %esi
subl %eax, %esi
cmovbl %ecx, %esi
subl %ebx, %eax
cmovbl %ecx, %eax
movl %esi, 0x4(%r14)
movl %eax, 0x14(%r14)
cmpq $0x1, %r12
jne 0x5906f
movq %r15, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3d202
movq %r13, 0x50(%rsp)
cmpq $0x0, 0xa8(%rsp)
jle 0x59168
movq %rbp, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movq %r15, 0x10(%rsp)
movq 0xa0(%rsp), %rax
leaq 0x8(%rax), %rbp
movl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %r13d, %r13d
movl -0x8(%rbp), %ecx
movl %ecx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl 0x10(%r14), %eax
jne 0x5914f
shrl $0x1f, %ecx
cmpl 0x1c(%r14), %ecx
jne 0x5914f
movl -0x4(%rbp), %eax
movl (%rbp), %edx
movq 0x28(%rsp), %rsi
movl (%rsi,%rdx,4), %r12d
movq %rax, (%rsp)
movq 0x90(%rsp), %rdi
movq 0x30(%rsp), %rsi
leaq 0x48(%rsp), %rdx
leaq 0x40(%rsp), %r8
leaq 0x38(%rsp), %r9
callq 0x58ec0
testq %rax, %rax
js 0x5924d
movq %rax, %rbx
movl 0x4(%r14), %eax
movl 0x14(%r14), %ecx
subq %r12, %rax
subq %rcx, %rbx
addq %rax, %rbx
cmpq %r15, %rbx
je 0x59132
movq 0x10(%rsp), %rdi
movl %r12d, %esi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x3d202
movq %rbx, %r15
incq %r13
addq $0x10, %rbp
cmpq %r13, 0xa8(%rsp)
jne 0x590a7
movq 0xa8(%rsp), %r13
movq 0x10(%rsp), %r15
movq 0x20(%rsp), %r12
movq 0x18(%rsp), %rbp
jmp 0x5916b
xorl %r13d, %r13d
jmp 0x5923b
xorl %r13d, %r13d
movq %r13, %rax
shlq $0x4, %rax
movq 0xa0(%rsp), %rcx
movl -0xc(%rcx,%rax), %edx
movl -0x8(%rcx,%rax), %eax
movq 0x28(%rsp), %rcx
movl (%rcx,%rax,4), %ebx
movl 0x1c(%r14), %ecx
movq %rdx, (%rsp)
leaq 0x48(%rsp), %rdx
leaq 0x40(%rsp), %r8
leaq 0x38(%rsp), %r9
movq 0x90(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x58ec0
testq %rax, %rax
js 0x5928b
movq 0x50(%rsp), %rdi
shrl %edi
andl $0x3fffffff, %edi       # imm = 0x3FFFFFFF
movl %eax, %ecx
notl %ecx
movq %rbx, %rdx
notq %rdx
addq %rbp, %rdx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
orq %rcx, %rsi
addq %rdi, %rsi
decl %edi
leal (%rsi,%rbx), %ecx
decl %ebp
addl %edx, %eax
cmpq %rsi, %rdx
cmovgl %edi, %eax
cmovgl %ecx, %ebp
movl %eax, 0x18(%r14)
movl %ebp, 0x8(%r14)
cmpq $0x1, %r12
jne 0x5923b
movl 0x8(%r15), %esi
decl %esi
movq %r15, %rdi
callq 0x3d110
cltq
movl 0x8(%r14), %ebx
cmpq %rbx, %rax
je 0x5923b
movl 0x8(%r15), %esi
decl %esi
movq %r15, %rdi
callq 0x3d11b
movq %r15, %rdi
movl %ebx, %esi
movl %eax, %edx
xorl %ecx, %ecx
callq 0x3d202
movq %r13, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1d9082(%rip), %rdi    # 0x2322d6
leaq 0x1d84f8(%rip), %rsi    # 0x231753
leaq 0x1d907c(%rip), %rcx    # 0x2322de
movl $0x3043, %edx           # imm = 0x3043
callq 0x2110
leaq 0x1d9063(%rip), %rdi    # 0x2322d6
leaq 0x1d84d9(%rip), %rsi    # 0x231753
leaq 0x1d905d(%rip), %rcx    # 0x2322de
movl $0x3034, %edx           # imm = 0x3034
callq 0x2110
leaq 0x1d9044(%rip), %rdi    # 0x2322d6
leaq 0x1d84ba(%rip), %rsi    # 0x231753
leaq 0x1d903e(%rip), %rcx    # 0x2322de
movl $0x304f, %edx           # imm = 0x304F
callq 0x2110