// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rdx, (%rsp)
movl %esi, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movslq 0x78(%rsp), %rdx
movq 0x90(%rsp), %rsi
movq 0x88(%rsp), %rdi
movq 0x80(%rsp), %rbx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, (%rsi)
movl %eax, (%rdi)
movl %edx, %eax
movq %rdx, 0x20(%rsp)
testq %rdx, %rdx
jle 0x13ca3
movq 0x70(%rsp), %rdx
incq %rdx
movq %rdx, 0x30(%rsp)
leal -0x1(%r9), %edx
movl %edx, 0x1c(%rsp)
leal -0x1(%rcx), %edx
movl %edx, 0x18(%rsp)
leaq 0x1(%r8), %rdx
movq %rdx, 0x28(%rsp)
xorl %r13d, %r13d
leaq (,%r13,2), %rsi
addq %r13, %rsi
movl 0x4(%rbx,%rsi,4), %edi
movl $0x4, %edx
cmpl %ecx, %edi
jge 0x13c48
leaq (%rbx,%rsi,4), %r10
movslq (%r10), %r14
leal (%r14,%rdi), %esi
cmpl %r9d, %esi
jge 0x13c48
movl %r9d, %r15d
subl %r14d, %r15d
cmpl %ecx, %r15d
cmovgel %ecx, %r15d
decl %r15d
movq 0x30(%rsp), %rdx
leaq (%rdx,%r14), %rbp
leal 0x7(%rdi), %edx
cmpl %r15d, %edx
jge 0x13be2
movslq %edi, %rdx
movq 0x1(%r8,%rdx), %rsi
movq (%rbp,%rdx), %rdx
cmpq %rdx, %rsi
jne 0x13bcf
addl $0x8, %edi
cmpq %rdx, %rsi
jne 0x13bdd
leal 0x7(%rdi), %r12d
cmpl %r15d, %r12d
jl 0x13bba
xorq %rsi, %rdx
jmp 0x13be4
xorl %edx, %edx
testq %rdx, %rdx
je 0x13c5f
bsfq %rdx, %rdx
shrl $0x3, %edx
addl %edi, %edx
movl %edx, %edi
cmpl $0x0, 0x10(%rsp)
setne %dl
addl %edi, %r14d
cmpl 0x1c(%rsp), %r14d
sete %sil
cmpl 0x18(%rsp), %edi
sete %bpl
movl %esi, %r11d
orb %bpl, %r11b
cmpb $0x1, %r11b
jne 0x13c42
andb %bpl, %sil
orb %sil, %dl
je 0x13c42
movq 0x88(%rsp), %rdx
movl %edi, (%rdx)
addl (%r10), %edi
movq 0x90(%rsp), %rdx
movl %edi, (%rdx)
movl $0x1, %edx
jmp 0x13c48
movl %edi, 0x4(%r10)
xorl %edx, %edx
testb $0x3, %dl
jne 0x13e80
incq %r13
cmpq %rax, %r13
jne 0x13b69
jmp 0x13ca3
cmpl %r15d, %edi
jge 0x13bf4
leal 0x7(%rdi), %edx
cmpl %r15d, %edx
jl 0x13bf4
movslq %edi, %rdx
movslq %r15d, %rsi
subq %rdx, %rsi
addq %rdx, %rbp
addq 0x28(%rsp), %rdx
xorl %r12d, %r12d
movb (%rdx,%r12), %r11b
cmpb (%rbp,%r12), %r11b
jne 0x13c9b
incq %r12
cmpq %r12, %rsi
jne 0x13c80
movl %r15d, %edi
jmp 0x13bf4
addl %r12d, %edi
jmp 0x13bf4
movq 0x20(%rsp), %r13
leaq (,%r13,2), %rdi
addq %r13, %rdi
leaq (%rbx,%rdi,4), %r8
movl (%rbx), %edx
decl %edx
movl %edx, 0x18(%r8)
movl $0x1, 0x20(%r8)
movl 0x4(%rbx), %edx
incl %edx
movl %edx, 0x1c(%r8)
movl (%rbx), %edx
movl %edx, 0x24(%r8)
cmpl $0x1, %r13d
jne 0x13ce6
movl $0x0, 0x2c(%r8)
jmp 0x13cf8
movl 0x10(%rbx), %edx
xorl %esi, %esi
cmpl %edx, 0x4(%rbx)
setle %sil
movl %esi, 0x2c(%r8)
jle 0x13cfb
movl 0x4(%rbx), %edx
incl %edx
movl %edx, 0x28(%r8)
cmpq $0x0, 0x8(%rsp)
je 0x13d81
cmpl $0x3, %r13d
jl 0x13ddb
leal -0x1(%r13), %edx
leaq (%rdx,%rdx,2), %rdx
leaq -0xc(,%rdx,4), %rdx
leaq (%rbx,%rdi,4), %r10
addq $0x38, %r10
xorl %r11d, %r11d
movl $0x1, %ebp
movl 0x10(%rbx,%r11), %esi
incl %esi
movl 0x4(%rbx,%r11), %r14d
xorl %r15d, %r15d
cmpl %esi, %r14d
setg %r15b
cmovgl %r14d, %esi
negl %r15d
movl 0x1c(%rbx,%r11), %r14d
incl %r14d
cmpl %r14d, %esi
cmovlel %ebp, %r15d
movl 0xc(%rbx,%r11), %r12d
cmovgl %esi, %r14d
movl %r12d, -0x8(%r10,%r11)
movl %r14d, -0x4(%r10,%r11)
movl %r15d, (%r10,%r11)
addq $0xc, %r11
cmpq %r11, %rdx
jne 0x13d33
jmp 0x13ddb
cmpl $0x3, %r13d
jl 0x13ddb
leal -0x1(%r13), %edx
leaq (%rdx,%rdx,2), %rdx
leaq -0xc(,%rdx,4), %rdx
leaq (%rbx,%rdi,4), %rsi
addq $0x34, %rsi
xorl %r10d, %r10d
movl 0x10(%rbx,%r10), %r11d
incl %r11d
movl 0x4(%rbx,%r10), %ebp
movl 0xc(%rbx,%r10), %r14d
cmpl %r11d, %ebp
cmovgl %ebp, %r11d
movl 0x1c(%rbx,%r10), %ebp
incl %ebp
cmpl %ebp, %r11d
cmovgl %r11d, %ebp
movl %r14d, -0x4(%rsi,%r10)
movl %ebp, (%rsi,%r10)
addq $0xc, %r10
cmpq %r10, %rdx
jne 0x13da2
leaq (%rbx,%rdi,4), %r12
addq $0x18, %r12
cmpl $0x2, %r13d
jl 0x13e16
leaq (%rax,%rax,2), %rax
movl -0xc(%rbx,%rax,4), %edx
movl %edx, (%r12,%rdi,4)
movl -0x14(%rbx,%rax,4), %edx
movl -0x8(%rbx,%rax,4), %eax
incl %eax
xorl %esi, %esi
cmpl %eax, %edx
cmovgl %edx, %eax
setg %sil
negl %esi
movl %esi, 0x8(%r12,%rdi,4)
movl %eax, 0x4(%r12,%rdi,4)
movl %ecx, %eax
negl %eax
leal 0x2(%r13), %r11d
movl -0xc(%r8), %edx
leal 0x1(%rdx), %esi
movl %esi, 0xc(%r12,%rdi,4)
movl $0xffffffff, 0x14(%r12,%rdi,4) # imm = 0xFFFFFFFF
movl -0x8(%r8), %esi
movl %esi, 0x10(%r12,%rdi,4)
movq (%rsp), %r8
testl %r8d, %r8d
setns %sil
addl %r8d, %r8d
cmpl %r13d, %r8d
setl %r8b
testb %r8b, %sil
je 0x13e67
cmpl $0x0, 0x10(%rsp)
je 0x13e8a
movq (%rsp), %rcx
movl %ecx, %edx
negl %edx
jmp 0x13eb7
xorl %ecx, %ecx
cmpl %eax, (%r12)
setl %cl
leal 0x1(%r13), %ebp
cmpl %r9d, %edx
cmovll %r11d, %ebp
jmp 0x13f04
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x13fff
movq (%rsp), %r10
movl %r9d, %esi
subl %ecx, %esi
subl %r10d, %esi
movl %ecx, %edx
subl %r10d, %edx
subl %r9d, %edx
movl %r9d, %r8d
subl %ecx, %r8d
cmovll %esi, %edx
movl %r8d, %ecx
negl %ecx
cmovsl %r8d, %ecx
addl %r10d, %ecx
movq %rcx, (%rsp)
cmpl %eax, %edx
cmovgl %edx, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %r12, %rdx
incl %ecx
leaq 0xc(%rdx), %rsi
cmpl %eax, (%rdx)
movq %rsi, %rdx
jl 0x13ec4
movq (%rsp), %rax
cmpl %r9d, %eax
cmovgl %eax, %r9d
movslq %r11d, %rax
leal 0x3(%r13), %ebp
leaq (%rax,%rax,2), %rax
shlq $0x2, %rax
leaq (%rax,%rdi,4), %rax
addq %rbx, %rax
addq $0xc, %rax
decl %ebp
leaq -0xc(%rax), %rdx
cmpl %r9d, (%rax)
movq %rdx, %rax
jg 0x13ef6
movq 0x8(%rsp), %rdx
movslq %ecx, %r14
testq %rdx, %rdx
je 0x13fe1
movq (%rdx), %rax
cmpq %rax, 0x8(%rdx)
jne 0x13f50
movq %rax, %rcx
shrq %rcx
leaq (%rax,%rcx), %rsi
addq $0x4, %rsi
movq %rsi, (%rdx)
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdi
shlq $0x4, %rsi
movl %r11d, %r15d
callq 0x2360
movl %r15d, %r11d
movq 0x8(%rsp), %rdx
movq %rax, 0x10(%rdx)
movq 0x8(%rdx), %r13
movq 0x10(%rdx), %rax
movq %rax, 0x10(%rsp)
leaq 0x1(%r13), %r15
movq %r15, 0x8(%rdx)
shlq $0x4, %r13
movl %r11d, (%rax,%r13)
movq 0x20(%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 0x10(%rsp), %rdx
movq %rax, 0x8(%rdx,%r13)
shlq $0x4, %r15
leaq (%r14,%r14,2), %rax
movl (%r12,%rax,4), %eax
movl %eax, -0xc(%rdx,%r15)
movl %ebp, %ecx
subl %r14d, %ecx
jle 0x13fe1
addq %r15, %rdx
movq -0x8(%rdx), %rax
movl %ecx, %edx
xorl %esi, %esi
leaq (%rsi,%r14), %rcx
leaq (%rcx,%rcx,2), %rcx
movslq 0x8(%r12,%rcx,4), %rdi
incq %rdi
leal (%rsi,%rsi), %ecx
shlq %cl, %rdi
movl %esi, %ecx
shrl $0x5, %ecx
orq %rdi, (%rax,%rcx,8)
incq %rsi
cmpq %rdx, %rsi
jne 0x13fba
leaq (%r14,%r14,2), %rax
leaq (%r12,%rax,4), %rsi
subl %r14d, %ebp
movslq %ebp, %rax
shlq $0x2, %rax
leaq (%rax,%rax,2), %rdx
movq %rbx, %rdi
callq 0x22c0
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq