// File: occivink[P]pyct/monocypher.cpp
// Function: slide_step(slide_ctx*, int, int, unsigned char const*)
static int slide_step(slide_ctx *ctx, int width, int i, const u8 scalar[32])
{
    if (i == ctx->next_check) {
        if (scalar_bit(scalar, i) == scalar_bit(scalar, i - 1)) {
            ctx->next_check--;
        } else {
            // compute digit of next window
            int w = MIN(width, i + 1);
            int v = -(scalar_bit(scalar, i) << (w-1));
            FOR_T (int, j, 0, w-1) {
                v += scalar_bit(scalar, i-(w-1)+j) << j;
            }
            v += scalar_bit(scalar, i-w);
            int lsb = v & (~v + 1);            // smallest bit of v
            int s   = (   ((lsb & 0xAA) != 0)  // log2(lsb)
                       | (((lsb & 0xCC) != 0) << 1)
                       | (((lsb & 0xF0) != 0) << 2));
            ctx->next_index  = (i16)(i-(w-1)+s);
            ctx->next_digit  = (i8) (v >> s   );
            ctx->next_check -= (u8) w;
        }
    }
    return i == ctx->next_index ? ctx->next_digit: 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
movzbl 0x3(%rcx), %ecx
cmpl %ecx, %eax
jne 0x13151
movq -0x18(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x122a0
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
movl -0x10(%rbp), %esi
subl $0x1, %esi
callq 0x122a0
movl %eax, %ecx
movl -0x30(%rbp), %eax
cmpl %ecx, %eax
jne 0x13022
movq -0x8(%rbp), %rax
movb 0x3(%rax), %cl
addb $-0x1, %cl
movb %cl, 0x3(%rax)
jmp 0x1314f
movl -0xc(%rbp), %eax
movl -0x10(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jg 0x13037
movl -0xc(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x13040
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x122a0
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
shll %cl, %eax
movl %eax, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x130a4
movq -0x18(%rbp), %rdi
movl -0x10(%rbp), %esi
movl -0x1c(%rbp), %eax
subl $0x1, %eax
subl %eax, %esi
addl -0x24(%rbp), %esi
callq 0x122a0
movl -0x24(%rbp), %ecx
shll %cl, %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1306a
movq -0x18(%rbp), %rdi
movl -0x10(%rbp), %esi
subl -0x1c(%rbp), %esi
callq 0x122a0
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl -0x20(%rbp), %ecx
xorl $-0x1, %ecx
addl $0x1, %ecx
andl %ecx, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
andl $0xaa, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl -0x28(%rbp), %ecx
andl $0xcc, %ecx
cmpl $0x0, %ecx
setne %cl
andb $0x1, %cl
movzbl %cl, %ecx
shll %ecx
orl %ecx, %eax
movl -0x28(%rbp), %ecx
andl $0xf0, %ecx
cmpl $0x0, %ecx
setne %cl
andb $0x1, %cl
movzbl %cl, %ecx
shll $0x2, %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x10(%rbp), %eax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
subl %ecx, %eax
addl -0x2c(%rbp), %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, (%rax)
movl -0x20(%rbp), %eax
movl -0x2c(%rbp), %ecx
sarl %cl, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x2(%rax)
movl -0x1c(%rbp), %eax
movzbl %al, %edx
movq -0x8(%rbp), %rax
movzbl 0x3(%rax), %ecx
subl %edx, %ecx
movb %cl, 0x3(%rax)
jmp 0x13151
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
movswl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x1316c
movq -0x8(%rbp), %rax
movsbl 0x2(%rax), %eax
movl %eax, -0x38(%rbp)
jmp 0x13173
xorl %eax, %eax
movl %eax, -0x38(%rbp)
jmp 0x13173
movl -0x38(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)