// File: /workspace/github_c_makefile_star2_O3/c-zhou[P]oatk/levdist.c
// Function: wf_step_basic
static int wf_step_basic(wf_tb_t *tb, int32_t is_ext, int32_t bw, int32_t tl, const char *ts, int32_t ql, const char *qs, int32_t n, wf_diag1_t *a, int32_t *t_end, int32_t *q_end)
{
    int32_t j, st = 0, en = n + 2;
    wf_diag1_t *b = a + n + 2; // temporary array

    // wfa_extend
    *t_end = *q_end = -1;
    for (j = 0; j < n; ++j) {
        wf_diag1_t *p = &a[j];
        int32_t k = p->k;
        if (k >= tl || k + p->d >= ql) continue;
        k = wf_extend(tl, ts, ql, qs, p);
        if (k + p->d == ql - 1 || k == tl - 1) {
            if (is_ext || (k + p->d == ql - 1 && k == tl - 1)) {
                *t_end = k, *q_end = k + p->d;
                return -1;
            }
        }
        p->k = k;
    }

    // wfa_next
    b[0].d = a[0].d - 1;
    b[0].p = 1;
    b[0].k = a[0].k + 1;
    b[1].d = a[0].d;
    b[1].p =  n == 1 || a[0].k > a[1].k? 0 : 1;
    b[1].k = (n == 1 || a[0].k > a[1].k? a[0].k : a[1].k) + 1;
    if (tb) { // with traceback
        for (j = 1; j < n - 1; ++j) {
            int32_t k = a[j-1].k, p = -1;
            p = k > a[j].k + 1? p : 0;
            k = k > a[j].k + 1? k : a[j].k + 1;
            p = k > a[j+1].k + 1? p : 1;
            k = k > a[j+1].k + 1? k : a[j+1].k + 1;
            b[j+1].d = a[j].d, b[j+1].k = k, b[j+1].p = p;
        }
    } else { // simpler without traceback
        for (j = 1; j < n - 1; ++j) {
            int32_t k = a[j-1].k;
            k = k > a[j].k + 1? k : a[j].k + 1;
            k = k > a[j+1].k + 1? k : a[j+1].k + 1;
            b[j+1].d = a[j].d, b[j+1].k = k;
        }
    }
    if (n >= 2) {
        b[n].d = a[n-1].d;
        b[n].p = a[n-2].k > a[n-1].k + 1? -1 : 0;
        b[n].k = a[n-2].k > a[n-1].k + 1? a[n-2].k : a[n-1].k + 1;
    }
    b[n+1].d = a[n-1].d + 1;
    b[n+1].p = -1;
    b[n+1].k = a[n-1].k;

    if (bw < 0 || n < bw + bw + 1) {
        if (b[0].d < -tl) ++st;
        if (b[n+1].d > ql) --en;
    } else wf_prune_bw(tl, ql, is_ext, bw, &st, &en, b);
    if (tb) { // keep traceback information
        wf_tb1_t *q;
        wf_tb_add(tb, n + 2);
        q = &tb->a[tb->n - 1];
        q->d0 = b[st].d;
        for (j = 0; j < en - st; ++j)
            q->a[j>>5] |= (uint64_t)(b[j+st].p + 1) << (j&0x1f)*2;
    }
    memcpy(a, &b[st], (en - st) * sizeof(*a));
    return en - st;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, 0x20(%rsp)
movq %rdx, 0x30(%rsp)
movq %rdi, 0x18(%rsp)
movslq 0x88(%rsp), %rdx
movq 0xa0(%rsp), %r8
movq 0x98(%rsp), %r10
movq 0x90(%rsp), %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, (%r8)
movl %eax, (%r10)
movq %rdx, 0x10(%rsp)
testq %rdx, %rdx
movl %esi, 0xc(%rsp)
jle 0x14779
movq 0x80(%rsp), %rax
leal -0x1(%r9), %ebp
leal -0x1(%rcx), %edx
movl %edx, 0x3c(%rsp)
movl 0x10(%rsp), %r15d
incq %rax
movq %rax, 0x40(%rsp)
incq 0x20(%rsp)
xorl %r13d, %r13d
movl %ebp, 0x2c(%rsp)
leaq (,%r13,2), %rax
addq %r13, %rax
movl 0x4(%rdi,%rax,4), %r11d
cmpl %ecx, %r11d
jge 0x1476d
leaq (%rdi,%rax,4), %rax
movslq (%rax), %r14
leal (%r14,%r11), %edx
cmpl %r9d, %edx
jge 0x1476d
movl %r9d, %edi
subl %r14d, %edi
cmpl %ecx, %edi
cmovgel %ecx, %edi
leal -0x1(%rdi), %r12d
leal 0x7(%r11), %edx
cmpl %r12d, %edx
jge 0x146d9
movslq %r11d, %rdx
movslq %edi, %rsi
addq $-0x10, %rsi
leaq (%rdx,%r14), %rbp
addq 0x40(%rsp), %rbp
movq 0x20(%rsp), %rdi
leaq (%rdi,%rdx), %r10
xorl %edi, %edi
movq (%r10,%rdi), %r8
movq (%rbp,%rdi), %rbx
cmpq %rbx, %r8
jne 0x14714
leaq (%rdx,%rdi), %r8
addq $0x8, %r8
addq $0x8, %rdi
addq $-0x8, %r8
cmpq %rsi, %r8
jl 0x146a0
leal (%r11,%rdi), %edx
addl $0x7, %edx
leal (%r11,%rdi), %esi
movl %esi, %r11d
movl 0xc(%rsp), %esi
movl 0x2c(%rsp), %ebp
cmpl %r12d, %r11d
jge 0x14733
cmpl %r12d, %edx
jl 0x14733
movslq %r11d, %rdx
movslq %r12d, %rbx
subq %rdx, %rbx
leaq (%rdx,%r14), %rdi
addq 0x40(%rsp), %rdi
addq 0x20(%rsp), %rdx
xorl %r10d, %r10d
movb (%rdx,%r10), %r8b
cmpb (%rdi,%r10), %r8b
jne 0x14730
incq %r10
cmpq %r10, %rbx
jne 0x146fd
movl %r12d, %r11d
jmp 0x14733
xorq %r8, %rbx
bsfq %rbx, %rdx
shrl $0x3, %edx
addl %r11d, %edi
addl %edx, %edi
movl %edi, %r11d
movl 0xc(%rsp), %esi
movl 0x2c(%rsp), %ebp
jmp 0x14733
addl %r10d, %r11d
testl %esi, %esi
setne %dl
addl %r11d, %r14d
cmpl %ebp, %r14d
sete %bl
cmpl 0x3c(%rsp), %r11d
sete %r10b
movl %ebx, %r8d
orb %r10b, %r8b
cmpb $0x1, %r8b
movq 0x90(%rsp), %rdi
jne 0x14769
andb %r10b, %bl
orb %bl, %dl
jne 0x14b12
movl %r11d, 0x4(%rax)
incq %r13
cmpq %r15, %r13
jne 0x1463d
movq 0x10(%rsp), %rbx
leaq (%rbx,%rbx,2), %rax
leaq (%rdi,%rax,4), %r8
leaq (%rdi,%rax,4), %r13
addq $0x18, %r13
movl $0x1, 0x20(%r8)
movq (%rdi), %xmm0
paddd 0xc2be(%rip), %xmm0     # 0x20a60
movq %xmm0, 0x18(%r8)
movl (%rdi), %edx
movl %edx, 0x24(%r8)
cmpl $0x1, %ebx
jne 0x147d8
movl $0x0, 0x2c(%r8)
movl 0x4(%rdi), %edx
incl %edx
movl %edx, 0x28(%r8)
cmpq $0x0, 0x18(%rsp)
sete %r12b
movq 0x30(%rsp), %r15
jmp 0x1491e
movl 0x4(%rdi), %edx
movl 0x10(%rdi), %esi
xorl %r10d, %r10d
cmpl %esi, %edx
setle %r10b
movl %r10d, 0x2c(%r8)
cmovgl %edx, %esi
incl %esi
movl %esi, 0x28(%r8)
cmpq $0x0, 0x18(%rsp)
sete %r12b
je 0x14875
cmpl $0x3, %ebx
jl 0x148cd
movq 0x10(%rsp), %rdx
decl %edx
leaq (%rdx,%rdx,2), %rdx
leaq -0xc(,%rdx,4), %rdx
leaq (%rdi,%rax,4), %r10
addq $0x38, %r10
xorl %r11d, %r11d
movl $0x1, %ebp
movl 0x10(%rdi,%r11), %esi
incl %esi
movl 0x4(%rdi,%r11), %ebx
xorl %r14d, %r14d
cmpl %esi, %ebx
setg %r14b
cmovgl %ebx, %esi
negl %r14d
movl 0x1c(%rdi,%r11), %ebx
incl %ebx
cmpl %ebx, %esi
cmovlel %ebp, %r14d
movl 0xc(%rdi,%r11), %r15d
cmovgl %esi, %ebx
movl %r15d, -0x8(%r10,%r11)
movl %ebx, -0x4(%r10,%r11)
movl %r14d, (%r10,%r11)
addq $0xc, %r11
cmpq %r11, %rdx
jne 0x1482c
jmp 0x148cd
cmpl $0x3, %ebx
jl 0x148cd
movq 0x10(%rsp), %rdx
decl %edx
leaq (%rdx,%rdx,2), %rdx
leaq -0xc(,%rdx,4), %rdx
leaq (%rdi,%rax,4), %r10
addq $0x34, %r10
xorl %esi, %esi
movl 0x10(%rdi,%rsi), %r11d
incl %r11d
movl 0x4(%rdi,%rsi), %ebx
movl 0xc(%rdi,%rsi), %ebp
cmpl %r11d, %ebx
cmovgl %ebx, %r11d
movl 0x1c(%rdi,%rsi), %ebx
incl %ebx
cmpl %ebx, %r11d
cmovgl %r11d, %ebx
movl %ebp, -0x4(%r10,%rsi)
movl %ebx, (%r10,%rsi)
addq $0xc, %rsi
cmpq %rsi, %rdx
jne 0x14897
movq 0x10(%rsp), %rbx
cmpl $0x1, %ebx
jle 0x14915
movl %ebx, %edx
leaq (%rdx,%rdx,2), %rdx
movl -0xc(%rdi,%rdx,4), %r11d
movl %r11d, (%r13,%rax,4)
movl -0x14(%rdi,%rdx,4), %esi
movl -0x8(%rdi,%rdx,4), %edx
incl %edx
xorl %r10d, %r10d
cmpl %edx, %esi
cmovgl %esi, %edx
setg %r10b
negl %r10d
movl %r10d, 0x8(%r13,%rax,4)
movl %edx, 0x4(%r13,%rax,4)
movq 0x30(%rsp), %r15
movl 0xc(%rsp), %esi
jmp 0x14922
movq 0x30(%rsp), %r15
movl 0xc(%rsp), %esi
movl -0xc(%r8), %r11d
movl %ecx, %r10d
negl %r10d
leal 0x2(%rbx), %ebp
leal 0x1(%r11), %edx
movl %edx, 0xc(%r13,%rax,4)
movl $0xffffffff, 0x14(%r13,%rax,4) # imm = 0xFFFFFFFF
movl -0x8(%r8), %edx
movl %edx, 0x10(%r13,%rax,4)
testl %r15d, %r15d
setns %dl
leal (%r15,%r15), %r8d
cmpl %ebx, %r8d
setl %r8b
testb %r8b, %dl
movl %ebp, 0x20(%rsp)
je 0x1496b
testl %esi, %esi
je 0x14983
movl %r15d, %edx
negl %edx
jmp 0x149ab
xorl %r14d, %r14d
cmpl %r10d, (%r13)
setl %r14b
movl %ebp, %eax
leal 0x1(%rbx), %ebp
cmpl %r9d, %r11d
cmovll %eax, %ebp
jmp 0x149f8
movl %r9d, %esi
subl %ecx, %esi
subl %r15d, %esi
movl %ecx, %edx
subl %r15d, %edx
subl %r9d, %edx
movl %r9d, %r8d
subl %ecx, %r8d
cmovll %esi, %edx
movl %r8d, %ecx
negl %ecx
cmovsl %r8d, %ecx
addl %r15d, %ecx
movl %ecx, %r15d
cmpl %r10d, %edx
cmovgl %edx, %r10d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq %r13, %rcx
incl %r14d
leaq 0xc(%rcx), %rdx
cmpl %r10d, (%rcx)
movq %rdx, %rcx
jl 0x149bb
cmpl %r9d, %r15d
cmovgl %r15d, %r9d
movslq %ebp, %rcx
leal 0x3(%rbx), %ebp
leaq (%rcx,%rcx,2), %rcx
shlq $0x2, %rcx
leaq (%rcx,%rax,4), %rax
addq %rdi, %rax
addq $0xc, %rax
decl %ebp
leaq -0xc(%rax), %rcx
cmpl %r9d, (%rax)
movq %rcx, %rax
jg 0x149ea
testb %r12b, %r12b
je 0x14a08
movslq %r14d, %rdx
subl %r14d, %ebp
jmp 0x14ae2
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %r12
cmpq (%rcx), %r12
jne 0x14a4b
movq %r12, %rax
shrq %rax
leaq (%r12,%rax), %rsi
addq $0x4, %rsi
movq %rsi, (%rcx)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rdi
shlq $0x4, %rsi
callq 0x2350
movq 0x18(%rsp), %rcx
movq %rax, %r15
movq %rax, 0x10(%rcx)
movq 0x8(%rcx), %r12
jmp 0x14a4f
movq 0x10(%rcx), %r15
leaq 0x1(%r12), %rbx
movq %rbx, 0x8(%rcx)
shlq $0x4, %r12
movl 0x20(%rsp), %eax
movl %eax, (%r15,%r12)
movq 0x10(%rsp), %rcx
leal 0x21(%rcx), %eax
addl $0x40, %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x5, %ecx
movslq %ecx, %rdi
movl $0x8, %esi
callq 0x2250
movq %rax, 0x8(%r15,%r12)
shlq $0x4, %rbx
movslq %r14d, %rdx
leaq (%rdx,%rdx,2), %rcx
movl (%r13,%rcx,4), %ecx
movl %ecx, -0xc(%r15,%rbx)
subl %edx, %ebp
jle 0x14ada
movl %ebp, %esi
xorl %r9d, %r9d
movq 0x90(%rsp), %rdi
leaq (%r9,%rdx), %rcx
leaq (%rcx,%rcx,2), %rcx
movslq 0x8(%r13,%rcx,4), %r8
incq %r8
leal (%r9,%r9), %ecx
shlq %cl, %r8
movl %r9d, %ecx
shrl $0x5, %ecx
orq %r8, (%rax,%rcx,8)
incq %r9
cmpq %rsi, %r9
jne 0x14aaf
jmp 0x14ae2
movq 0x90(%rsp), %rdi
leaq (%rdx,%rdx,2), %rax
leaq (,%rax,4), %rsi
addq %r13, %rsi
movslq %ebp, %rax
shlq $0x2, %rax
leaq (%rax,%rax,2), %rdx
callq 0x22b0
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x98(%rsp), %rcx
movl %r11d, (%rcx)
addl (%rax), %r11d
movq 0xa0(%rsp), %rax
movl %r11d, (%rax)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x14b01