// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %r9, 0x28(%rsp)
movq %r8, 0x20(%rsp)
movq %rcx, %r8
movq %rdx, %rbp
movq 0xb0(%rsp), %rax
xorl %r13d, %r13d
movq %r13, 0x40(%rsp)
movq %r13, 0x38(%rsp)
movq %r13, 0x30(%rsp)
movl $0x0, 0x8(%rdi)
movl (%rax), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl 0x10(%rsi), %eax
cmpl %eax, %ecx
jne 0x59e29
movq %rsi, %r15
shrl $0x1f, %edx
movl 0x1c(%rsi), %ecx
cmpl %ecx, %edx
jne 0x59c0f
movq %rdi, %r12
movq %r8, 0x50(%rsp)
movq 0xa8(%rsp), %rdx
movq 0xa0(%rsp), %rdi
movq (%rdx), %rdx
movq 0x10(%rdx), %rdx
leaq (%rax,%rax,4), %rax
movl (%rdx,%rax,8), %eax
movq %rax, 0x48(%rsp)
movq 0xb0(%rsp), %rdx
movl 0x4(%rdx), %eax
movl 0x8(%rdx), %edx
movq 0x20(%rsp), %rsi
movl (%rsi,%rdx,4), %ebx
movq %rax, (%rsp)
leaq 0x40(%rsp), %rdx
leaq 0x38(%rsp), %r8
leaq 0x30(%rsp), %r9
movq 0x28(%rsp), %rsi
callq 0x59a6d
testq %rax, %rax
js 0x59e5a
leaq 0x4(%r15), %r14
movl %ebx, 0x4(%r15)
leaq 0x14(%r15), %r13
movl %eax, 0x14(%r15)
movl %ebx, %ecx
subl %eax, %ecx
jbe 0x59c17
movl %ecx, (%r14)
movq %r13, %rax
jmp 0x59c20
xorl %r13d, %r13d
jmp 0x59e29
subl %ebx, %eax
movl %eax, (%r13)
movq %r14, %rax
movl $0x0, (%rax)
cmpq $0x1, %rbp
jne 0x59c3b
movl (%r14), %esi
movq %r12, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3dd21
cmpq $0x0, 0xb8(%rsp)
jle 0x59d34
movq %r13, 0x58(%rsp)
movq %r14, 0x60(%rsp)
movq %rbp, 0x18(%rsp)
movq %r12, 0x10(%rsp)
movq 0xb0(%rsp), %rax
leaq 0x8(%rax), %r12
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %r13d, %r13d
movl -0x8(%r12), %eax
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl 0x10(%r15), %ecx
jne 0x59d28
shrl $0x1f, %eax
movl 0x1c(%r15), %ecx
cmpl %ecx, %eax
jne 0x59d28
movl -0x4(%r12), %eax
movl (%r12), %edx
movq 0x20(%rsp), %rsi
movl (%rsi,%rdx,4), %r14d
movq %rax, (%rsp)
movq 0xa0(%rsp), %rdi
movq 0x28(%rsp), %rsi
leaq 0x40(%rsp), %rdx
leaq 0x38(%rsp), %r8
leaq 0x30(%rsp), %r9
callq 0x59a6d
testq %rax, %rax
js 0x59e3b
movq %rax, %rbx
movq 0x60(%rsp), %rax
movl (%rax), %eax
subq %r14, %rax
movq 0x58(%rsp), %rcx
movl (%rcx), %ecx
subq %rcx, %rbx
addq %rax, %rbx
cmpq %rbp, %rbx
je 0x59d0b
movq 0x10(%rsp), %rdi
movl %r14d, %esi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x3dd21
movq %rbx, %rbp
incq %r13
addq $0x10, %r12
cmpq %r13, 0xb8(%rsp)
jne 0x59c72
movq 0xb8(%rsp), %r13
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %rbp
jmp 0x59d37
xorl %r13d, %r13d
movq %r13, %rax
shlq $0x4, %rax
movq 0xb0(%rsp), %rcx
movl -0xc(%rcx,%rax), %edx
movl -0x8(%rcx,%rax), %eax
movq 0x20(%rsp), %rcx
movl (%rcx,%rax,4), %r14d
movl 0x1c(%r15), %ecx
movq %rdx, (%rsp)
leaq 0x40(%rsp), %rdx
leaq 0x38(%rsp), %r8
leaq 0x30(%rsp), %r9
movq 0xa0(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x59a6d
testq %rax, %rax
js 0x59e79
movq 0x48(%rsp), %r8
shrl %r8d
andl $0x3fffffff, %r8d       # imm = 0x3FFFFFFF
leaq 0x8(%r15), %rbx
movl %r14d, 0x8(%r15)
movl %eax, %edx
notl %edx
movl %eax, 0x18(%r15)
addq $0x18, %r15
movq %r14, %rcx
notq %rcx
movq 0x50(%rsp), %rdi
addq %rdi, %rcx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
orq %rdx, %rsi
addq %r8, %rsi
cmpq %rsi, %rcx
jle 0x59ddd
movq %r15, %rdx
movq %rsi, %rcx
movl %r14d, %eax
movq %rbx, %r15
jmp 0x59de3
movl %edi, %r8d
movq %rbx, %rdx
decl %r8d
addl %eax, %ecx
movl %r8d, (%rdx)
movl %ecx, (%r15)
cmpq $0x1, %rbp
jne 0x59e29
movl 0x8(%r12), %esi
decl %esi
movq %r12, %rdi
callq 0x3dc2f
cltq
movl (%rbx), %ebx
cmpq %rbx, %rax
je 0x59e29
movl 0x8(%r12), %esi
decl %esi
movq %r12, %rdi
callq 0x3dc3a
movq %r12, %rdi
movl %ebx, %esi
movl %eax, %edx
xorl %ecx, %ecx
callq 0x3dd21
movq %r13, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1cc384(%rip), %rdi    # 0x2261c6
leaq 0x1cb7fa(%rip), %rsi    # 0x225643
leaq 0x1cc37e(%rip), %rcx    # 0x2261ce
movl $0x3043, %edx           # imm = 0x3043
callq 0x2110
leaq 0x1cc365(%rip), %rdi    # 0x2261c6
leaq 0x1cb7db(%rip), %rsi    # 0x225643
leaq 0x1cc35f(%rip), %rcx    # 0x2261ce
movl $0x3034, %edx           # imm = 0x3034
callq 0x2110
leaq 0x1cc346(%rip), %rdi    # 0x2261c6
leaq 0x1cb7bc(%rip), %rsi    # 0x225643
leaq 0x1cc340(%rip), %rcx    # 0x2261ce
movl $0x304f, %edx           # imm = 0x304F
callq 0x2110