// File: /workspace/github_cpp_makefile_star2_O1/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, %ebx
movl %ecx, %ebp
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %r14
movq %rdx, %rdi
movl %ecx, %edx
movq %r9, %rcx
movq %r14, %r8
callq 0xe2f48
testq %rax, %rax
je 0xe43f3
movq 0x18(%r14), %rax
xorl (%rax), %ebx
cmpl $0x1, %ebx
je 0xe460f
leaq 0x14790c(%rip), %rdi    # 0x22bce7
leaq 0x1458bf(%rip), %rsi    # 0x229ca1
leaq 0x14797a(%rip), %rcx    # 0x22bd63
movl $0x634d, %edx           # imm = 0x634D
callq 0x2110
movq %r12, 0x8(%rsp)
movq %r15, %rdi
xorl %esi, %esi
movl %ebp, %edx
movq %r13, %rcx
movq %r14, %r8
callq 0xe2f48
testq %rax, %rax
je 0xe4631
movq 0x18(%r14), %rax
movl (%rax), %eax
xorl $0x1, %ebx
cmpl %ebx, %eax
movq 0x8(%rsp), %r12
jne 0xe463a
movl %ebx, 0x4(%rsp)
movq 0x38(%r14), %rdx
testq %rdx, %rdx
je 0xe446f
movq 0x48(%r14), %rsi
xorl %r10d, %r10d
xorl %ecx, %ecx
movl (%rsi,%r10,4), %r8d
cmpl %ebp, %r8d
je 0xe4462
cmpl %eax, %r8d
je 0xe4462
movq 0x20(%r15), %r9
shrl %r8d
movl (%r9,%r8,8), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
addq %r8, %rcx
incq %r10
movl %r10d, %r8d
cmpq %r8, %rdx
ja 0xe443f
jmp 0xe4471
xorl %ecx, %ecx
movq 0x20(%r15), %rdx
movl %ebp, %esi
shrl %esi
movl (%rdx,%rsi,8), %esi
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andq %r8, %rsi
addq %rcx, %rsi
shrl %eax
movl (%rdx,%rax,8), %r13d
andq %r8, %r13
addq %rsi, %r13
movq %r12, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %r13, %rcx
movq %r14, %r8
callq 0xe2f48
testq %rax, %rax
je 0xe44db
movq 0x18(%r14), %rax
movl 0x4(%rsp), %ecx
cmpl %ecx, (%rax)
je 0xe460f
leaq 0x147824(%rip), %rdi    # 0x22bce7
leaq 0x1457d7(%rip), %rsi    # 0x229ca1
leaq 0x147892(%rip), %rcx    # 0x22bd63
movl $0x6360, %edx           # imm = 0x6360
callq 0x2110
movsd 0x141055(%rip), %xmm0   # 0x225538
movq %r12, %rdi
movq %r15, %rsi
movl %ebp, %edx
movl 0x4(%rsp), %ebx
movl %ebx, %ecx
movl $0x1, %r8d
movq %r14, %r9
callq 0xe3b74
movq %r12, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %r13, %rcx
movq %r14, %r8
callq 0xe2f48
testq %rax, %rax
je 0xe4542
movq 0x18(%r14), %rax
cmpl %ebx, (%rax)
je 0xe460f
leaq 0x1477bd(%rip), %rdi    # 0x22bce7
leaq 0x145770(%rip), %rsi    # 0x229ca1
leaq 0x14782b(%rip), %rcx    # 0x22bd63
movl $0x636a, %edx           # imm = 0x636A
callq 0x2110
movsd 0x140f36(%rip), %xmm1   # 0x225480
movl %ebx, %ecx
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
movsd %xmm1, 0x10(%rsp)
movapd %xmm1, %xmm0
xorl %r8d, %r8d
movq %r14, %r9
callq 0xe3b74
movq %rax, %r12
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %r13, %rcx
movq %r14, %r8
callq 0xe2f48
testq %rax, %rax
jne 0xe4603
movsd 0x10(%rsp), %xmm1
addsd 0x140ee9(%rip), %xmm1   # 0x225480
testl %r12d, %r12d
movl 0x4(%rsp), %ecx
je 0xe45ae
movsd 0x140cc8(%rip), %xmm0   # 0x225270
ucomisd %xmm1, %xmm0
ja 0xe4551
movsd 0x1455e2(%rip), %xmm0   # 0x229b98
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
xorl %r8d, %r8d
movq %r14, %r9
callq 0xe3b74
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %r13, %rcx
movq %r14, %r8
callq 0xe2f48
testq %rax, %rax
movq 0x50(%rsp), %r12
je 0xe4678
movq 0x18(%r14), %rax
movl 0x4(%rsp), %ecx
cmpl %ecx, (%rax)
jne 0xe4681
xorl %eax, %eax
jmp 0xe4619
movq 0x18(%r14), %rax
movl 0x4(%rsp), %ecx
cmpl %ecx, (%rax)
jne 0xe4659
movl $0x1, %eax
movq 0x50(%rsp), %r12
testq %r12, %r12
je 0xe4622
movq %r13, (%r12)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x13ff70(%rip), %rdi    # 0x2245a8
jmp 0xe4641
leaq 0x1476a6(%rip), %rdi    # 0x22bce7
leaq 0x145659(%rip), %rsi    # 0x229ca1
leaq 0x147714(%rip), %rcx    # 0x22bd63
movl $0x6357, %edx           # imm = 0x6357
callq 0x2110
leaq 0x147687(%rip), %rdi    # 0x22bce7
leaq 0x14563a(%rip), %rsi    # 0x229ca1
leaq 0x1476f5(%rip), %rcx    # 0x22bd63
movl $0x6373, %edx           # imm = 0x6373
callq 0x2110
leaq 0x13ff29(%rip), %rdi    # 0x2245a8
jmp 0xe4688
leaq 0x14765f(%rip), %rdi    # 0x22bce7
leaq 0x145612(%rip), %rsi    # 0x229ca1
leaq 0x1476cd(%rip), %rcx    # 0x22bd63
movl $0x637c, %edx           # imm = 0x637C
callq 0x2110