// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: rd_hamming_symm_simple0(buf_t*, asg_t*, asg_t*, unsigned int, unsigned int, unsigned long, unsigned long*)
uint32_t rd_hamming_symm_simple0(buf_t *b, asg_t *ref, asg_t *g, uint32_t st, uint32_t ed, uint64_t max_dist, uint64_t *r_max_dist) // callback for kt_for()
{
    double step = 0.2, cuttoff; 
    uint32_t p, k, ncut;
    p = rd_hm_bub(g, ref, st, max_dist, b);
    if(p) {
        assert(b->S.a[0] == (ed^1));
        if(r_max_dist) (*r_max_dist) = max_dist;
        return 1;
    }
    ///recalculate max_dist
    p = rd_hm_bub(ref, NULL, st, max_dist, b);
    // if(!p) {
    //     fprintf(stderr, "[M::%s] st>>1::%u(st&1::%u), ed>>1::%u(ed&1::%u), max_dist::%lu\n", 
    //     __func__, st>>1, st&1, ed>>1, ed&1, max_dist);
    // }
    assert(p); assert(b->S.a[0] == (ed^1));
    for (k = max_dist = 0; k < b->b.n; ++k) {
        if(b->b.a[k]==st || b->b.a[k]==b->S.a[0]) continue;
        max_dist += ref->seq[b->b.a[k]>>1].len;
    }
    max_dist += ref->seq[st>>1].len;
    max_dist += ref->seq[b->S.a[0]>>1].len;
    p = rd_hm_bub(g, ref, st, max_dist, b);
    if(p) {
        assert(b->S.a[0] == (ed^1));
        if(r_max_dist) (*r_max_dist) = max_dist;
        return 1;
    }

    ///drop inexact edges first
    cuttoff = -1;
    ncut = rd_hm_drop(g, ref, st, ed^1, cuttoff, 1, b);
    p = rd_hm_bub(g, ref, st, max_dist, b);
    if(p) {
        assert(b->S.a[0] == (ed^1));
        if(r_max_dist) (*r_max_dist) = max_dist;
        return 1;
    }

    for (cuttoff = step; cuttoff < 1.0; cuttoff += step) {
        ncut = rd_hm_drop(g, ref, st, ed^1, cuttoff, 0, b);
        p = rd_hm_bub(g, ref, st, max_dist, b);
        if(p) {
            assert(b->S.a[0] == (ed^1));
            if(r_max_dist) (*r_max_dist) = max_dist;
            return 1;
        }
        if(!ncut) break;
    }

    rd_hm_drop(g, ref, st, ed^1, 1024, 0, b);   
    p = rd_hm_bub(g, ref, st, max_dist, b); 
    assert(p); assert(b->S.a[0] == (ed^1));
    if(r_max_dist) (*r_max_dist) = max_dist;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r14
movl %r8d, %r15d
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, %r13
movq %rdi, %r12
movq %rdx, %rdi
movl %ecx, %edx
movq %r9, %rcx
movq %r12, %r8
callq 0xe46e8
testq %rax, %rax
je 0xe5b70
movq 0x18(%r12), %rax
xorl (%rax), %r15d
cmpl $0x1, %r15d
jne 0xe5dc0
movl $0x1, %eax
movq 0x60(%rsp), %r13
testq %r13, %r13
je 0xe5b61
movq %r14, (%r13)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, 0x18(%rsp)
movq %r13, %rbx
movq %r13, %rdi
xorl %esi, %esi
movl %ebp, %edx
movq %r14, %rcx
movq %r12, %r8
callq 0xe46e8
testq %rax, %rax
je 0xe5ddf
movq 0x18(%r12), %rax
movl (%rax), %r13d
xorl %r13d, %r15d
cmpl $0x1, %r15d
jne 0xe5de8
movq 0x38(%r12), %rcx
testq %rcx, %rcx
movq 0x18(%rsp), %r15
movq %r12, 0x10(%rsp)
movq %rbx, %r14
je 0xe5bf3
movq 0x48(%r12), %rdx
xorl %esi, %esi
xorl %eax, %eax
movl (%rdx,%rsi,4), %edi
cmpl %ebp, %edi
je 0xe5be7
cmpl %r13d, %edi
je 0xe5be7
movq 0x20(%r14), %r8
shrl %edi
movl (%r8,%rdi,8), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
addq %rdi, %rax
incq %rsi
movl %esi, %edi
cmpq %rdi, %rcx
ja 0xe5bc8
jmp 0xe5bf5
xorl %eax, %eax
movq 0x20(%r14), %rcx
movl %ebp, %edx
shrl %edx
movl (%rcx,%rdx,8), %edx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andq %rsi, %rdx
addq %rax, %rdx
movl %r13d, %eax
shrl %eax
movl (%rcx,%rax,8), %r12d
andq %rsi, %r12
addq %rdx, %r12
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movq %r12, %rcx
movq 0x10(%rsp), %rbx
movq %rbx, %r8
callq 0xe46e8
testq %rax, %rax
je 0xe5c5f
movq 0x18(%rbx), %rax
cmpl %r13d, (%rax)
jne 0xe5e07
movl $0x1, %eax
movq 0x60(%rsp), %r13
testq %r13, %r13
movq %r12, %r14
jne 0xe5b5d
jmp 0xe5b61
movsd 0x14b9d1(%rip), %xmm0   # 0x231638
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %r13d, %ecx
movl $0x1, %r8d
movq %rbx, %r9
callq 0xe52c7
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movq %r12, 0x8(%rsp)
movq %r12, %rcx
movq %rbx, %r8
callq 0xe46e8
testq %rax, %rax
je 0xe5cc9
movq 0x18(%rbx), %rax
cmpl %r13d, (%rax)
je 0xe5da3
leaq 0x152226(%rip), %rdi    # 0x237ed7
leaq 0x1501d9(%rip), %rsi    # 0x235e91
leaq 0x152294(%rip), %rcx    # 0x237f53
movl $0x636a, %edx           # imm = 0x636A
callq 0x2110
movsd 0x14b8af(%rip), %xmm1   # 0x231580
movq 0x10(%rsp), %rbx
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %r13d, %ecx
movsd %xmm1, 0x20(%rsp)
movapd %xmm1, %xmm0
xorl %r8d, %r8d
movq %rbx, %r9
callq 0xe52c7
movq %r15, %rdi
movq %rax, %r15
movq %r14, %rsi
movl %ebp, %edx
movq 0x8(%rsp), %rcx
movq %rbx, %r8
callq 0xe46e8
testq %rax, %rax
jne 0xe5d91
movsd 0x20(%rsp), %xmm1
addsd 0x14b85f(%rip), %xmm1   # 0x231580
testl %r15d, %r15d
movq 0x18(%rsp), %r15
je 0xe5d39
movsd 0x14b5dd(%rip), %xmm0   # 0x231310
ucomisd %xmm1, %xmm0
ja 0xe5cd6
movsd 0x15004f(%rip), %xmm0   # 0x235d90
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %r13d, %ecx
xorl %r8d, %r8d
movq 0x10(%rsp), %rbx
movq %rbx, %r9
callq 0xe52c7
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movq 0x8(%rsp), %r14
movq %r14, %rcx
movq %rbx, %r8
callq 0xe46e8
testq %rax, %rax
je 0xe5e45
movq 0x18(%rbx), %rax
cmpl %r13d, (%rax)
jne 0xe5e4e
xorl %eax, %eax
jmp 0xe5b53
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
cmpl %r13d, (%rax)
jne 0xe5e26
movl $0x1, %eax
movq 0x60(%rsp), %r13
testq %r13, %r13
movq 0x8(%rsp), %r14
jne 0xe5b5d
jmp 0xe5b61
leaq 0x152110(%rip), %rdi    # 0x237ed7
leaq 0x1500c3(%rip), %rsi    # 0x235e91
leaq 0x15217e(%rip), %rcx    # 0x237f53
movl $0x634d, %edx           # imm = 0x634D
callq 0x2110
leaq 0x14a7d2(%rip), %rdi    # 0x2305b8
jmp 0xe5def
leaq 0x1520e8(%rip), %rdi    # 0x237ed7
leaq 0x15009b(%rip), %rsi    # 0x235e91
leaq 0x152156(%rip), %rcx    # 0x237f53
movl $0x6357, %edx           # imm = 0x6357
callq 0x2110
leaq 0x1520c9(%rip), %rdi    # 0x237ed7
leaq 0x15007c(%rip), %rsi    # 0x235e91
leaq 0x152137(%rip), %rcx    # 0x237f53
movl $0x6360, %edx           # imm = 0x6360
callq 0x2110
leaq 0x1520aa(%rip), %rdi    # 0x237ed7
leaq 0x15005d(%rip), %rsi    # 0x235e91
leaq 0x152118(%rip), %rcx    # 0x237f53
movl $0x6373, %edx           # imm = 0x6373
callq 0x2110
leaq 0x14a76c(%rip), %rdi    # 0x2305b8
jmp 0xe5e55
leaq 0x152082(%rip), %rdi    # 0x237ed7
leaq 0x150035(%rip), %rsi    # 0x235e91
leaq 0x1520f0(%rip), %rcx    # 0x237f53
movl $0x637c, %edx           # imm = 0x637C
callq 0x2110