// File: /workspace/github_c_makefile_star2_O2/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 $0x58, %rsp
movl %esi, 0xc(%rsp)
movq %r9, %rsi
movq %rdi, 0x18(%rsp)
movq 0xb0(%rsp), %rdi
movq 0xa8(%rsp), %r9
movl 0x98(%rsp), %r10d
movq 0x90(%rsp), %r11
movq %rdx, 0x38(%rsp)
movl %edx, %eax
negl %eax
movl %eax, 0x2c(%rsp)
movl %ecx, %eax
negl %eax
movl %eax, 0x8(%rsp)
movslq %r10d, %rax
orl $-0x1, (%rdi)
imulq $0xc, %rax, %rdx
orl $-0x1, (%r9)
incq %r11
movq %r11, 0x50(%rsp)
xorl %ebp, %ebp
testl %eax, %eax
movl $0x0, %r9d
cmovgl %r10d, %r9d
movq 0xa0(%rsp), %rdi
leal 0x2(%r10), %eax
movl %eax, 0x4(%rsp)
leaq (%rdi,%rdx), %rax
movq %rax, 0x40(%rsp)
movq %rdx, 0x10(%rsp)
leaq 0x18(%rdi,%rdx), %r13
leal -0x1(%rsi), %eax
movl %eax, 0x34(%rsp)
leal -0x1(%rcx), %eax
movl %eax, 0x30(%rsp)
movq %r13, 0x20(%rsp)
movq %rsi, 0x48(%rsp)
cmpq %r9, %rbp
je 0x110aa
imulq $0xc, %rbp, %rdx
movslq 0x4(%rdi,%rdx), %r14
cmpl %ecx, %r14d
jge 0x1108d
addq %rdi, %rdx
movslq (%rdx), %r15
leal (%r15,%r14), %eax
cmpl %esi, %eax
jge 0x1108d
movl %esi, %eax
subl %r15d, %eax
cmpl %ecx, %eax
cmovgel %ecx, %eax
movslq %eax, %r10
leaq -0x1(%r10), %rsi
movq 0x50(%rsp), %rax
leaq (%rax,%r15), %rbx
addq $-0x8, %r10
xorl %r11d, %r11d
movq %r14, %rax
cmpq %r10, %r14
jge 0x1102c
movq 0x1(%r8,%rax), %r13
movq (%rbx,%rax), %r12
movq %r12, %r11
xorq %r13, %r11
leaq 0x8(%rax), %r14
cmpq %r12, %r13
je 0x1100c
testq %r11, %r11
je 0x11043
bsfq %r11, %rsi
shrl $0x3, %esi
addl %eax, %esi
movl %esi, %eax
movq 0x20(%rsp), %r13
jmp 0x11051
leal 0x7(%rax), %r10d
cmpl %esi, %r10d
movq 0x20(%rsp), %r13
jge 0x11095
cmpl $0x0, 0xc(%rsp)
setne %sil
addl %eax, %r15d
cmpl 0x34(%rsp), %r15d
sete %r10b
cmpl 0x30(%rsp), %eax
sete %r11b
movl %r10d, %ebx
orb %r11b, %bl
cmpb $0x1, %bl
jne 0x11085
andb %r11b, %r10b
orb %r10b, %sil
jne 0x11250
movl %eax, 0x4(%rdx)
movq 0x48(%rsp), %rsi
incq %rbp
jmp 0x10fbe
cmpq %rsi, %rax
jge 0x11051
movb 0x1(%r8,%rax), %r10b
cmpb (%rbx,%rax), %r10b
jne 0x11051
incq %rax
jmp 0x11095
movq 0x40(%rsp), %rbp
movl $0x1, 0x20(%rbp)
movq (%rdi), %xmm0
paddd 0x995e(%rip), %xmm0     # 0x1aa20
movq %xmm0, 0x18(%rbp)
movl (%rdi), %eax
movl %eax, 0x24(%rbp)
movl 0x98(%rsp), %r14d
movq %rsi, %r15
cmpl $0x1, %r14d
jne 0x110e6
andl $0x0, 0x2c(%rbp)
movl 0x4(%rdi), %eax
jmp 0x110fa
movl 0x4(%rdi), %edx
movl 0x10(%rdi), %eax
xorl %esi, %esi
cmpl %eax, %edx
setle %sil
movl %esi, 0x2c(%rbp)
cmovgl %edx, %eax
movq 0x10(%rsp), %r12
incl %eax
movl %eax, 0x28(%rbp)
leal -0x1(%r14), %eax
cltq
cmpq $0x0, 0x18(%rsp)
je 0x1116e
pushq $0x1
popq %rdx
pushq $0x1
popq %rsi
movq %rdi, %r8
cmpq %rax, %rdx
jge 0x111b0
movl 0x10(%r8), %r9d
incl %r9d
movl 0x4(%r8), %r10d
xorl %r11d, %r11d
cmpl %r9d, %r10d
cmovgl %r10d, %r9d
setg %r11b
negl %r11d
incq %rdx
movl 0x1c(%r8), %r10d
incl %r10d
cmpl %r10d, %r9d
cmovlel %esi, %r11d
movl 0xc(%r8), %ebx
cmovgl %r9d, %r10d
movl %ebx, 0x30(%r8,%r12)
movl %r10d, 0x34(%r8,%r12)
movl %r11d, 0x38(%r8,%r12)
addq $0xc, %r8
jmp 0x1111b
pushq $0x1
popq %rdx
movq %rdi, %rsi
cmpq %rax, %rdx
jge 0x111b0
movl 0x10(%rsi), %r8d
incl %r8d
movl 0x4(%rsi), %r9d
movl 0xc(%rsi), %r10d
cmpl %r8d, %r9d
cmovgl %r9d, %r8d
incq %rdx
movl 0x1c(%rsi), %r9d
incl %r9d
cmpl %r9d, %r8d
cmovgl %r8d, %r9d
movl %r10d, 0x30(%rsi,%r12)
movl %r9d, 0x34(%rsi,%r12)
addq $0xc, %rsi
jmp 0x11174
cmpl $0x1, %r14d
jle 0x111eb
movl %r14d, %eax
imulq $0xc, %rax, %rdx
movl -0xc(%rdi,%rdx), %eax
movl %eax, (%r13,%r12)
movl -0x14(%rdi,%rdx), %esi
movl -0x8(%rdi,%rdx), %edx
incl %edx
xorl %r8d, %r8d
cmpl %edx, %esi
cmovgl %esi, %edx
setg %r8b
negl %r8d
movl %r8d, 0x8(%r13,%r12)
movl %edx, 0x4(%r13,%r12)
jmp 0x111ee
movl -0xc(%rbp), %eax
movq 0x38(%rsp), %r8
leal 0x1(%rax), %edx
movl %edx, 0xc(%r13,%r12)
orl $-0x1, 0x14(%r13,%r12)
movl -0x8(%rbp), %edx
movl %edx, 0x10(%r13,%r12)
testl %r8d, %r8d
setns %dl
leal (%r8,%r8), %esi
cmpl %r14d, %esi
setl %sil
testb %sil, %dl
je 0x11230
cmpl $0x0, 0xc(%rsp)
movl 0x8(%rsp), %esi
je 0x1126e
movl 0x2c(%rsp), %edx
jmp 0x11298
xorl %r12d, %r12d
movl 0x8(%rsp), %ecx
cmpl %ecx, (%r13)
setl %r12b
leal 0x1(%r14), %ebp
cmpl %r15d, %eax
cmovll 0x4(%rsp), %ebp
jmp 0x112e4
movq 0xa8(%rsp), %rcx
movl %eax, (%rcx)
addl (%rdx), %eax
movq 0xb0(%rsp), %rcx
movl %eax, (%rcx)
pushq $-0x1
popq %rbp
jmp 0x11346
movl %r15d, %edx
subl %ecx, %edx
subl %r8d, %edx
movl %ecx, %r9d
subl %r8d, %r9d
subl %r15d, %r9d
movl %r15d, %eax
subl %ecx, %eax
cmovll %edx, %r9d
movl %r9d, %edx
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
addl %r8d, %ecx
movl %ecx, %r8d
cmpl %esi, %edx
cmovgl %edx, %esi
pushq $-0x1
popq %r12
movq %r13, %rax
incl %r12d
leaq 0xc(%rax), %rcx
cmpl %esi, (%rax)
movq %rcx, %rax
jl 0x112a4
cmpl %r15d, %r8d
cmovgl %r8d, %r15d
movslq 0x4(%rsp), %rax
leal 0x3(%r14), %ebp
imulq $0xc, %rax, %rax
movq 0x10(%rsp), %rcx
addq %rax, %rcx
leaq (%rdi,%rcx), %rax
addq $0xc, %rax
decl %ebp
leaq -0xc(%rax), %rcx
cmpl %r15d, (%rax)
movq %rcx, %rax
jg 0x112d6
movq 0x18(%rsp), %rcx
testq %rcx, %rcx
je 0x1132a
movq %rdi, %r15
movq 0x8(%rcx), %rbx
cmpq (%rcx), %rbx
jne 0x11357
movq %rbx, %rax
shrq %rax
leaq (%rbx,%rax), %rsi
addq $0x4, %rsi
movq %rsi, (%rcx)
movq 0x10(%rcx), %rdi
shlq $0x4, %rsi
callq 0x2350
movq 0x18(%rsp), %rcx
movq %rax, %r13
movq %rax, 0x10(%rcx)
movq 0x8(%rcx), %rbx
jmp 0x1135b
movslq %r12d, %rdx
subl %r12d, %ebp
imulq $0xc, %rdx, %rax
addq %rax, %r13
movslq %ebp, %rax
imulq $0xc, %rax, %rdx
movq %r13, %rsi
callq 0x22b0
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rcx), %r13
leaq 0x1(%rbx), %r14
movq %r14, 0x8(%rcx)
shlq $0x4, %rbx
movl 0x4(%rsp), %eax
movl %eax, (%r13,%rbx)
movl 0x98(%rsp), %eax
addl $0x21, %eax
pushq $0x20
popq %rcx
cltd
idivl %ecx
movslq %eax, %rdi
pushq $0x8
popq %rsi
callq 0x2250
movq %rax, 0x8(%r13,%rbx)
shlq $0x4, %r14
movslq %r12d, %rdx
imulq $0xc, %rdx, %rcx
movq 0x20(%rsp), %rsi
movl (%rsi,%rcx), %ecx
movl %ecx, -0xc(%r13,%r14)
movq %rsi, %r13
subl %edx, %ebp
xorl %esi, %esi
testl %ebp, %ebp
movl $0x0, %r9d
cmovgl %ebp, %r9d
movq %r15, %rdi
cmpq %r9, %rsi
je 0x11330
leaq (%rsi,%rdx), %rcx
imulq $0xc, %rcx, %rcx
movslq 0x8(%r13,%rcx), %r8
incq %r8
leal (%rsi,%rsi), %ecx
shlq %cl, %r8
movl %esi, %ecx
shrl $0x5, %ecx
orq %r8, (%rax,%rcx,8)
incq %rsi
jmp 0x113be