// File: 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
movq %rsp, %rbp
subq $0xc0, %rsp
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq $0x7fffffff, -0x60(%rbp) # imm = 0x7FFFFFFF
movq $0x0, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x90(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, 0x8(%rax)
movq 0x20(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x18(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jne 0x4d78a
movq 0x20(%rbp), %rax
movl (%rax), %eax
shrl $0x1f, %eax
movq -0x18(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
je 0x4d797
movq $0x0, -0x8(%rbp)
jmp 0x4dbe7
movq 0x18(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
sarl %eax
cltq
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rax
movq 0x20(%rbp), %rcx
movl 0x8(%rcx), %ecx
movl (%rax,%rcx,4), %eax
movq %rax, -0x98(%rbp)
movq 0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, %ecx
movq 0x20(%rbp), %rax
movl 0x4(%rax), %eax
leaq -0x80(%rbp), %rdx
leaq -0x88(%rbp), %r8
leaq -0x90(%rbp), %r9
movq %rax, (%rsp)
callq 0x4d4d0
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
jl 0x4d81a
jmp 0x4d839
leaq 0x33567d(%rip), %rdi    # 0x382e9e
leaq 0x334af3(%rip), %rsi    # 0x38231b
movl $0x3034, %edx           # imm = 0x3034
leaq 0x335672(%rip), %rcx    # 0x382ea6
callq 0x2130
movq -0x98(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0xa0(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x14(%rcx), %eax
ja 0x4d889
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x18(%rbp), %rax
movl 0x14(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x14(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x4(%rax)
jmp 0x4d8a7
movq -0x18(%rbp), %rax
movl 0x14(%rax), %edx
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x14(%rax)
cmpq $0x1, -0x20(%rbp)
jne 0x4d8c4
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %esi
xorl %edx, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x1e500
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rcx
xorl %eax, %eax
cmpq 0x28(%rbp), %rcx
movb %al, -0xa1(%rbp)
jge 0x4d92a
movq 0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq -0x18(%rbp), %rdx
xorl %eax, %eax
cmpl 0x10(%rdx), %ecx
movb %al, -0xa1(%rbp)
jne 0x4d92a
movq 0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0x1f, %eax
movq -0x18(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
sete %al
movb %al, -0xa1(%rbp)
movb -0xa1(%rbp), %al
testb $0x1, %al
jne 0x4d939
jmp 0x4da40
movq -0x30(%rbp), %rax
movq 0x20(%rbp), %rcx
movq -0x40(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
movl (%rax,%rcx,4), %eax
movq %rax, -0x98(%rbp)
movq 0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, %ecx
movq 0x20(%rbp), %rax
movq -0x40(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl 0x4(%rax), %eax
leaq -0x80(%rbp), %rdx
leaq -0x88(%rbp), %r8
leaq -0x90(%rbp), %r9
movq %rax, (%rsp)
callq 0x4d4d0
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
jl 0x4d9aa
jmp 0x4d9c9
leaq 0x3354ed(%rip), %rdi    # 0x382e9e
leaq 0x334963(%rip), %rsi    # 0x38231b
movl $0x3043, %edx           # imm = 0x3043
leaq 0x3354e2(%rip), %rcx    # 0x382ea6
callq 0x2130
movq -0x98(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x4(%rcx), %ecx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0xa0(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x14(%rcx), %ecx
subq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
subq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
je 0x4da2d
movq -0x58(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x98(%rbp), %rax
movl %eax, %esi
movq -0x60(%rbp), %rax
movl %eax, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x1e500
jmp 0x4da2f
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x4d8cc
movq -0x30(%rbp), %rax
movq 0x20(%rbp), %rcx
movq -0x40(%rbp), %rdx
subq $0x1, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
movl (%rax,%rcx,4), %eax
movq %rax, -0x98(%rbp)
movq 0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, %ecx
movq 0x20(%rbp), %rax
movq -0x40(%rbp), %rdx
subq $0x1, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl 0x4(%rax), %eax
leaq -0x80(%rbp), %rdx
leaq -0x88(%rbp), %r8
leaq -0x90(%rbp), %r9
movq %rax, (%rsp)
callq 0x4d4d0
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
jl 0x4dab9
jmp 0x4dad8
leaq 0x3353de(%rip), %rdi    # 0x382e9e
leaq 0x334854(%rip), %rsi    # 0x38231b
movl $0x304f, %edx           # imm = 0x304F
leaq 0x3353d3(%rip), %rcx    # 0x382ea6
callq 0x2130
movq -0x98(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0xa0(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x8(%rcx), %ecx
subq %rcx, %rax
subq $0x1, %rax
movq %rax, -0x68(%rbp)
movq -0x78(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x18(%rcx), %ecx
subq %rcx, %rax
subq $0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x70(%rbp), %rax
jg 0x4db52
movq -0x28(%rbp), %rax
subq $0x1, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x68(%rbp), %rdx
movq -0x18(%rbp), %rax
movl 0x18(%rax), %ecx
addq %rdx, %rcx
movl %ecx, 0x18(%rax)
jmp 0x4db74
movq -0x78(%rbp), %rax
subq $0x1, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x70(%rbp), %rdx
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
addq %rdx, %rcx
movl %ecx, 0x8(%rax)
cmpq $0x1, -0x20(%rbp)
jne 0x4dbdf
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %esi
subl $0x1, %esi
callq 0x1e320
cltq
movq -0x18(%rbp), %rcx
movl 0x8(%rcx), %ecx
cmpq %rcx, %rax
je 0x4dbdf
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %esi
subl $0x1, %esi
callq 0x1e340
movq -0xb0(%rbp), %rdi
movl -0xa8(%rbp), %esi
movl %eax, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x1e500
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)