// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: get_win_yoff(overlap_region*, long, long, long, long, long, long, long*, long*, long*, long*)
int64_t get_win_yoff(overlap_region *o, int64_t toff, int64_t k, int64_t qs, int64_t qe, int64_t ts, int64_t te, int64_t *q, int64_t *t,
int64_t *rq, int64_t *rt)
{
    int64_t wn = o->w_list.n<<1, s, qdis, tdis, dis;
    if(k<0) k = 0; if(k>=wn) k = wn-1;
    for (; k < wn; k++) {
        s = ((k&1)?(o->w_list.a[k>>1].x_end):(o->w_list.a[k>>1].x_start));
        if(s >= toff) break;
    }
    for (k=(k>=wn?(wn-1):(k)); k >= 0; k--) {
        s = ((k&1)?(o->w_list.a[k>>1].x_end):(o->w_list.a[k>>1].x_start));
        if(s <= toff) break;
    }

    q[0] = qs; q[1] = qe; t[0] = ts; t[1] = te;
    if(k < 0) {//toff <= t[1]
        q[1] =  o->w_list.a[0].x_start;
        t[1] = o->w_list.a[0].y_start;
        tdis = t[1] - toff; qdis = q[1] - q[0]; dis = MIN(qdis, tdis);
        (*rq) = q[1] - dis; (*rt) = t[1] - dis;
    } else if(k == wn-1) {//toff >= t[0]
        q[0] = o->w_list.a[k>>1].x_end;
        t[0] = o->w_list.a[k>>1].y_end;
        tdis = toff - t[0]; qdis = q[1] - q[0]; dis = MIN(qdis, tdis);
        (*rq) = q[0] + dis; (*rt) = t[0] + dis;
    } else {//toff >= t[0] && toff <= t[1]
        q[0] = ((k&1)?(o->w_list.a[k>>1].x_end):(o->w_list.a[k>>1].x_start));
        t[0] = ((k&1)?(o->w_list.a[k>>1].y_end):(o->w_list.a[k>>1].y_start));
        k++;
        q[1] = ((k&1)?(o->w_list.a[k>>1].x_end):(o->w_list.a[k>>1].x_start));
        t[1] = ((k&1)?(o->w_list.a[k>>1].y_end):(o->w_list.a[k>>1].y_start));
        k--;
        (*rt) = toff;
        (*rq) = q[0] + get_offset_adjust(toff-t[0], t[1]-t[0], q[1]-q[0]);
    }
    return k;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x58(%rsp), %r11
movq 0x50(%rsp), %r10
movq 0x48(%rsp), %rbx
movq 0x40(%rsp), %r14
movq 0x38(%rsp), %r15
movq 0x48(%rdi), %r13
movq 0x58(%rdi), %rdi
leaq (,%r13,2), %r12
xorl %eax, %eax
testq %rdx, %rdx
cmovgq %rdx, %rax
cmpq %r12, %rax
leaq -0x1(%r13,%r13), %rdx
cmovgeq %rdx, %rax
movq %rax, %r13
shlq $0x4, %r13
andq $-0x20, %r13
leaq (%rdi,%r13), %rbp
testb $0x1, %al
leaq 0x4(%rdi,%r13), %r13
cmoveq %rbp, %r13
movslq (%r13), %r13
cmpq %rsi, %r13
jge 0x7c549
incq %rax
cmpq %r12, %rax
jl 0x7c51b
movq %rdx, %rax
testq %rax, %rax
js 0x7c587
movq %rax, %r12
shlq $0x4, %r12
movq %r12, %r13
andq $-0x20, %r13
leaq (%rdi,%r13), %rbp
testb $0x1, %al
leaq 0x4(%rdi,%r13), %r13
cmoveq %rbp, %r13
movslq (%r13), %r13
cmpq %rsi, %r13
jle 0x7c5cb
leaq -0x1(%rax), %r12
testq %rax, %rax
movq %r12, %rax
jg 0x7c54e
movq $-0x1, %rax
movq %rcx, (%r14)
movq %r9, (%rbx)
movslq (%rdi), %rcx
movq %rcx, 0x8(%r14)
movslq 0x8(%rdi), %rcx
movq %rcx, 0x8(%rbx)
subq %rsi, %rcx
movq 0x8(%r14), %rdx
movq %rdx, %rsi
subq (%r14), %rsi
cmpq %rcx, %rsi
cmovgeq %rcx, %rsi
subq %rsi, %rdx
movq %rdx, (%r10)
movq 0x8(%rbx), %rcx
subq %rsi, %rcx
movq %rcx, (%r11)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r8, 0x8(%r14)
movq %r15, 0x8(%rbx)
cmpq %rax, %rdx
jne 0x7c618
movq %rdx, %rax
shlq $0x4, %rax
andq $-0x20, %rax
movslq 0x4(%rdi,%rax), %rcx
movq %rcx, (%r14)
movslq 0xc(%rdi,%rax), %rax
movq %rax, (%rbx)
subq %rax, %rsi
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
cmpq %rsi, %rcx
cmovgeq %rsi, %rcx
addq %rcx, %rax
movq %rax, (%r10)
addq (%rbx), %rcx
movq %rcx, (%r11)
movq %rdx, %rax
jmp 0x7c5c0
movq %rax, %rdx
shrq %rdx
shlq $0x5, %rdx
testb $0x1, %al
jne 0x7c643
leaq (%rdi,%rdx), %rcx
leaq (%rdi,%rdx), %r8
addq $0x8, %r8
leaq (%rdi,%rdx), %r9
addq $0x4, %r9
addq %rdi, %rdx
addq $0xc, %rdx
jmp 0x7c663
leaq (%rdi,%rdx), %rcx
addq $0x4, %rcx
leaq (%rdi,%rdx), %r8
addq $0xc, %r8
leaq (%r12,%rdi), %r9
addq $0x10, %r9
leaq (%r12,%rdi), %rdx
addq $0x18, %rdx
movslq (%r9), %rdi
movslq (%r8), %r8
movslq (%rcx), %rcx
movq %rcx, (%r14)
movq %r8, (%rbx)
movq %rdi, 0x8(%r14)
movslq (%rdx), %rcx
movq %rcx, 0x8(%rbx)
movq %rsi, (%r11)
movq (%r14), %rcx
movl (%rbx), %edx
movl 0x8(%rbx), %edi
subl %edx, %esi
subl %edx, %edi
movl 0x8(%r14), %edx
subl %ecx, %edx
cvtsi2sd %rsi, %xmm0
cvtsi2sd %rdi, %xmm1
cvtsi2sd %rdx, %xmm2
divsd %xmm1, %xmm0
mulsd %xmm0, %xmm2
cvttsd2si %xmm2, %rdx
movl %edx, %edx
addq %rcx, %rdx
movq %rdx, (%r10)
jmp 0x7c5c0