// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movsd 0x245625(%rip), %xmm0   # 0x37f010
movsd %xmm0, -0x38(%rbp)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %r8
callq 0x137ce0
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x139a64
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
movl -0x28(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x139a27
jmp 0x139a46
leaq 0x24f0d4(%rip), %rdi    # 0x388b02
leaq 0x24ce88(%rip), %rsi    # 0x3868bd
movl $0x634d, %edx           # imm = 0x634D
leaq 0x24f13d(%rip), %rcx    # 0x388b7e
callq 0x2130
cmpq $0x0, 0x10(%rbp)
je 0x139a58
movq -0x30(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x139e4c
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %edx
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %r8
xorl %eax, %eax
movl %eax, %esi
callq 0x137ce0
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x139a87
jmp 0x139aa6
leaq 0x247936(%rip), %rdi    # 0x3813c4
leaq 0x24ce28(%rip), %rsi    # 0x3868bd
movl $0x6357, %edx           # imm = 0x6357
leaq 0x24f0dd(%rip), %rcx    # 0x388b7e
callq 0x2130
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
movl -0x28(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x139abc
jmp 0x139adb
leaq 0x24f03f(%rip), %rdi    # 0x388b02
leaq 0x24cdf3(%rip), %rsi    # 0x3868bd
movl $0x6357, %edx           # imm = 0x6357
leaq 0x24f0a8(%rip), %rcx    # 0x388b7e
callq 0x2130
movq $0x0, -0x30(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x139b5d
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x24(%rbp), %eax
je 0x139b24
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpl (%rcx), %eax
jne 0x139b26
jmp 0x139b52
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl -0x48(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x139aea
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x24(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl (%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %r8
callq 0x137ce0
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x139c1a
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
movl -0x28(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x139bdd
jmp 0x139bfc
leaq 0x24ef1e(%rip), %rdi    # 0x388b02
leaq 0x24ccd2(%rip), %rsi    # 0x3868bd
movl $0x6360, %edx           # imm = 0x6360
leaq 0x24ef87(%rip), %rcx    # 0x388b7e
callq 0x2130
cmpq $0x0, 0x10(%rbp)
je 0x139c0e
movq -0x30(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x139e4c
movsd 0x248656(%rip), %xmm0   # 0x382278
movsd %xmm0, -0x40(%rbp)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
xorl $0x1, %ecx
movsd -0x40(%rbp), %xmm0
movq -0x10(%rbp), %r9
movl $0x1, %r8d
callq 0x138d20
movl %eax, -0x4c(%rbp)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %r8
callq 0x137ce0
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x139cc3
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
movl -0x28(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x139c86
jmp 0x139ca5
leaq 0x24ee75(%rip), %rdi    # 0x388b02
leaq 0x24cc29(%rip), %rsi    # 0x3868bd
movl $0x636a, %edx           # imm = 0x636A
leaq 0x24eede(%rip), %rcx    # 0x388b7e
callq 0x2130
cmpq $0x0, 0x10(%rbp)
je 0x139cb7
movq -0x30(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x139e4c
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd 0x24832b(%rip), %xmm0   # 0x382000
ucomisd -0x40(%rbp), %xmm0
jbe 0x139d97
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
xorl $0x1, %ecx
movsd -0x40(%rbp), %xmm0
movq -0x10(%rbp), %r9
xorl %r8d, %r8d
callq 0x138d20
movl %eax, -0x4c(%rbp)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %r8
callq 0x137ce0
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x139d79
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
movl -0x28(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x139d3c
jmp 0x139d5b
leaq 0x24edbf(%rip), %rdi    # 0x388b02
leaq 0x24cb73(%rip), %rsi    # 0x3868bd
movl $0x6373, %edx           # imm = 0x6373
leaq 0x24ee28(%rip), %rcx    # 0x388b7e
callq 0x2130
cmpq $0x0, 0x10(%rbp)
je 0x139d6d
movq -0x30(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x139e4c
cmpl $0x0, -0x4c(%rbp)
jne 0x139d81
jmp 0x139d97
jmp 0x139d83
movsd -0x38(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x139ccd
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
xorl $0x1, %ecx
movq -0x10(%rbp), %r9
movsd 0x24cac4(%rip), %xmm0   # 0x386878
xorl %r8d, %r8d
callq 0x138d20
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %r8
callq 0x137ce0
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x139ddf
jmp 0x139dfe
leaq 0x2475de(%rip), %rdi    # 0x3813c4
leaq 0x24cad0(%rip), %rsi    # 0x3868bd
movl $0x637c, %edx           # imm = 0x637C
leaq 0x24ed85(%rip), %rcx    # 0x388b7e
callq 0x2130
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
movl -0x28(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x139e14
jmp 0x139e33
leaq 0x24ece7(%rip), %rdi    # 0x388b02
leaq 0x24ca9b(%rip), %rsi    # 0x3868bd
movl $0x637c, %edx           # imm = 0x637C
leaq 0x24ed50(%rip), %rcx    # 0x388b7e
callq 0x2130
cmpq $0x0, 0x10(%rbp)
je 0x139e45
movq -0x30(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)