// File: /workspace/github_cpp_makefile_star2_O2/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, 0x10(%rsp)
movq %r8, 0x8(%rsp)
movq %rcx, %r13
movq %rsi, %r14
andq $0x0, 0x28(%rsp)
andq $0x0, 0x20(%rsp)
movq 0xa0(%rsp), %rsi
andq $0x0, 0x18(%rsp)
andl $0x0, 0x8(%rdi)
movl (%rsi), %ecx
movl %ecx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl 0x10(%r14), %eax
jne 0x29dd1
shrl $0x1f, %ecx
cmpl 0x1c(%r14), %ecx
jne 0x29dd1
movq %rdx, %r12
movq %rdi, %r15
movq 0x98(%rsp), %rdx
movq 0x90(%rsp), %rdi
movq (%rdx), %rdx
movq 0x10(%rdx), %rdx
imulq $0x28, %rax, %rax
movl (%rdx,%rax), %ebp
movl 0x4(%rsi), %eax
movl 0x8(%rsi), %edx
movq 0x8(%rsp), %rsi
movl (%rsi,%rdx,4), %ebx
movq %rax, (%rsp)
leaq 0x28(%rsp), %rdx
leaq 0x20(%rsp), %r8
leaq 0x18(%rsp), %r9
movq 0x10(%rsp), %rsi
callq 0x29b4d
testq %rax, %rax
js 0x29eeb
movq %r13, 0x48(%rsp)
shrl %ebp
andl $0x3fffffff, %ebp       # imm = 0x3FFFFFFF
movq %rbp, 0x40(%rsp)
xorl %ecx, %ecx
movl %ebx, %esi
subl %eax, %esi
cmovbl %ecx, %esi
subl %ebx, %eax
cmovbl %ecx, %eax
movq 0xa8(%rsp), %rbp
movl %esi, 0x4(%r14)
movl %eax, 0x14(%r14)
movq %r12, 0x50(%rsp)
cmpq $0x1, %r12
jne 0x29d04
movq %r15, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x11af6
movq %r15, 0x30(%rsp)
xorl %r13d, %r13d
testq %rbp, %rbp
cmovleq %r13, %rbp
movq 0xa0(%rsp), %rax
leaq 0x8(%rax), %r15
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x38(%rsp)
cmpq %r13, %rbp
je 0x29dd8
movl -0x8(%r15), %eax
movl %eax, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl 0x1c(%r14), %ecx
cmpl 0x10(%r14), %edx
jne 0x29dde
shrl $0x1f, %eax
cmpl %ecx, %eax
jne 0x29dde
movl -0x4(%r15), %eax
movl (%r15), %edx
movq 0x8(%rsp), %rsi
movl (%rsi,%rdx,4), %ebx
movq %rax, (%rsp)
movq 0x90(%rsp), %rdi
movq 0x10(%rsp), %rsi
leaq 0x28(%rsp), %rdx
leaq 0x20(%rsp), %r8
leaq 0x18(%rsp), %r9
callq 0x29b4d
testq %rax, %rax
js 0x29ecc
movq %rax, %r12
movl 0x4(%r14), %eax
movl 0x14(%r14), %ecx
subq %rbx, %rax
subq %rcx, %r12
addq %rax, %r12
cmpq 0x38(%rsp), %r12
je 0x29dc5
movq 0x30(%rsp), %rdi
movl %ebx, %esi
movl %r12d, %edx
xorl %ecx, %ecx
callq 0x11af6
movq %r12, 0x38(%rsp)
incq %r13
addq $0x10, %r15
jmp 0x29d29
xorl %eax, %eax
jmp 0x29ebd
movl 0x1c(%r14), %ecx
jmp 0x29de1
movq %r13, %rbp
movq %rbp, %r12
shlq $0x4, %rbp
movq 0xa0(%rsp), %rsi
movl -0xc(%rsi,%rbp), %edx
movl -0x8(%rsi,%rbp), %eax
movq 0x8(%rsp), %rsi
movl (%rsi,%rax,4), %ebx
movl %ecx, %ecx
movq %rdx, (%rsp)
leaq 0x28(%rsp), %rdx
leaq 0x20(%rsp), %r8
leaq 0x18(%rsp), %r9
movq 0x90(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x29b4d
testq %rax, %rax
movq 0x30(%rsp), %r15
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %r8
movq 0x40(%rsp), %r9
js 0x29f0a
movl %eax, %ecx
notl %ecx
movq %rbx, %rdx
notq %rdx
addq %r8, %rdx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
orq %rcx, %rsi
addq %r9, %rsi
decl %r9d
leal (%rsi,%rbx), %ecx
decl %r8d
addl %edx, %eax
cmpq %rsi, %rdx
cmovgl %r9d, %eax
cmovgl %ecx, %r8d
movl %eax, 0x18(%r14)
movl %r8d, 0x8(%r14)
cmpq $0x1, %rdi
jne 0x29eba
movl 0x8(%r15), %esi
decl %esi
movq %r15, %rdi
callq 0x11a00
cltq
movl 0x8(%r14), %ebx
cmpq %rbx, %rax
je 0x29eba
movl 0x8(%r15), %esi
decl %esi
movq %r15, %rdi
callq 0x11a0b
movq %r15, %rdi
movl %ebx, %esi
movl %eax, %edx
xorl %ecx, %ecx
callq 0x11af6
movq %r12, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1ba353(%rip), %rdi    # 0x1e4226
leaq 0x1b97c9(%rip), %rsi    # 0x1e36a3
leaq 0x1ba34d(%rip), %rcx    # 0x1e422e
movl $0x3043, %edx           # imm = 0x3043
callq 0x2110
leaq 0x1ba334(%rip), %rdi    # 0x1e4226
leaq 0x1b97aa(%rip), %rsi    # 0x1e36a3
leaq 0x1ba32e(%rip), %rcx    # 0x1e422e
movl $0x3034, %edx           # imm = 0x3034
callq 0x2110
leaq 0x1ba315(%rip), %rdi    # 0x1e4226
leaq 0x1b978b(%rip), %rsi    # 0x1e36a3
leaq 0x1ba30f(%rip), %rcx    # 0x1e422e
movl $0x304f, %edx           # imm = 0x304F
callq 0x2110