// File: /workspace/github_cpp_makefile_star2_O2/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 $0x18, %rsp
movq %r9, %r13
movl %r8d, %r15d
movl %ecx, %ebp
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
movq %rdx, %rdi
movl %ecx, %edx
movq %r9, %rcx
movq %rbx, %r8
callq 0xa6c6c
testq %rax, %rax
je 0xa7cd3
movq 0x18(%rbx), %rax
xorl (%rax), %r15d
cmpl $0x1, %r15d
jne 0xa7eed
pushq $0x1
popq %rax
movq 0x50(%rsp), %rcx
testq %rcx, %rcx
movq %r13, %r12
je 0xa7cc4
movq %r12, (%rcx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, 0x8(%rsp)
movq %r14, %rdi
xorl %esi, %esi
movl %ebp, %edx
movq %r13, %rcx
movq %rbx, %r8
callq 0xa6c6c
testq %rax, %rax
je 0xa7f0c
movq 0x18(%rbx), %rax
movl (%rax), %r13d
xorl %r13d, %r15d
cmpl $0x1, %r15d
jne 0xa7f15
movq 0x38(%rbx), %rcx
xorl %eax, %eax
xorl %edx, %edx
movq 0x8(%rsp), %r15
movl %edx, %edx
cmpq %rdx, %rcx
jbe 0xa7d41
movq 0x48(%rbx), %rsi
movl (%rsi,%rdx,4), %esi
cmpl %ebp, %esi
je 0xa7d3d
cmpl %r13d, %esi
je 0xa7d3d
movq 0x20(%r14), %rdi
shrl %esi
movl (%rdi,%rsi,8), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
addq %rsi, %rax
incl %edx
jmp 0xa7d14
movq 0x20(%r14), %rcx
movl %ebp, %edx
shrl %edx
movl (%rcx,%rdx,8), %edx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andq %rsi, %rdx
addq %rdx, %rax
movl %r13d, %edx
shrl %edx
movl (%rcx,%rdx,8), %r12d
andq %rsi, %r12
addq %rax, %r12
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movq %r12, %rcx
movq %rbx, %r8
callq 0xa6c6c
testq %rax, %rax
je 0xa7da1
movq 0x18(%rbx), %rax
cmpl %r13d, (%rax)
jne 0xa7f34
pushq $0x1
popq %rax
movq 0x50(%rsp), %rcx
testq %rcx, %rcx
jne 0xa7cc1
jmp 0xa7cc4
movsd 0x13b7d7(%rip), %xmm0   # 0x1e3580
pushq $0x1
popq %r8
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %r13d, %ecx
movq %rbx, %r9
callq 0xa74b1
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movq %r12, (%rsp)
movq %r12, %rcx
movq %rbx, %r8
callq 0xa6c6c
testq %rax, %rax
je 0xa7e03
movq 0x18(%rbx), %rax
cmpl %r13d, (%rax)
jne 0xa7f53
movq 0x50(%rsp), %rcx
testq %rcx, %rcx
movq (%rsp), %r12
pushq $0x1
popq %rax
jne 0xa7cc1
jmp 0xa7cc4
movsd 0x13b6c5(%rip), %xmm1   # 0x1e34d0
movsd 0x13b48d(%rip), %xmm0   # 0x1e32a0
ucomisd %xmm1, %xmm0
jbe 0xa7e6f
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %r13d, %ecx
movsd %xmm1, 0x10(%rsp)
movapd %xmm1, %xmm0
xorl %r8d, %r8d
movq %rbx, %r9
callq 0xa74b1
movq %r15, %rdi
movq %rax, %r15
movq %r14, %rsi
movl %ebp, %edx
movq (%rsp), %rcx
movq %rbx, %r8
callq 0xa6c6c
testq %rax, %rax
jne 0xa7ec1
testl %r15d, %r15d
movq 0x8(%rsp), %r15
movsd 0x10(%rsp), %xmm1
je 0xa7e6f
addsd 0x13b663(%rip), %xmm1   # 0x1e34d0
jmp 0xa7e0b
movsd 0x13fe19(%rip), %xmm0   # 0x1e7c90
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %r13d, %ecx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0xa74b1
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movq (%rsp), %r12
movq %r12, %rcx
movq %rbx, %r8
callq 0xa6c6c
testq %rax, %rax
je 0xa7f72
movq 0x18(%rbx), %rax
cmpl %r13d, (%rax)
jne 0xa7f7b
xorl %eax, %eax
jmp 0xa7d8e
movq 0x18(%rbx), %rax
cmpl %r13d, (%rax)
je 0xa7de9
leaq 0x141f02(%rip), %rdi    # 0x1e9dd7
leaq 0x13feb5(%rip), %rsi    # 0x1e7d91
leaq 0x141f70(%rip), %rcx    # 0x1e9e53
movl $0x6373, %edx           # imm = 0x6373
callq 0x2110
leaq 0x141ee3(%rip), %rdi    # 0x1e9dd7
leaq 0x13fe96(%rip), %rsi    # 0x1e7d91
leaq 0x141f51(%rip), %rcx    # 0x1e9e53
movl $0x634d, %edx           # imm = 0x634D
callq 0x2110
leaq 0x13a6a5(%rip), %rdi    # 0x1e25b8
jmp 0xa7f1c
leaq 0x141ebb(%rip), %rdi    # 0x1e9dd7
leaq 0x13fe6e(%rip), %rsi    # 0x1e7d91
leaq 0x141f29(%rip), %rcx    # 0x1e9e53
movl $0x6357, %edx           # imm = 0x6357
callq 0x2110
leaq 0x141e9c(%rip), %rdi    # 0x1e9dd7
leaq 0x13fe4f(%rip), %rsi    # 0x1e7d91
leaq 0x141f0a(%rip), %rcx    # 0x1e9e53
movl $0x6360, %edx           # imm = 0x6360
callq 0x2110
leaq 0x141e7d(%rip), %rdi    # 0x1e9dd7
leaq 0x13fe30(%rip), %rsi    # 0x1e7d91
leaq 0x141eeb(%rip), %rcx    # 0x1e9e53
movl $0x636a, %edx           # imm = 0x636A
callq 0x2110
leaq 0x13a63f(%rip), %rdi    # 0x1e25b8
jmp 0xa7f82
leaq 0x141e55(%rip), %rdi    # 0x1e9dd7
leaq 0x13fe08(%rip), %rsi    # 0x1e7d91
leaq 0x141ec3(%rip), %rcx    # 0x1e9e53
movl $0x637c, %edx           # imm = 0x637C
callq 0x2110