// File: cloudinary[P]fuif/encoding/context_predict.h
// Function: predict_and_compute_properties(std::vector<int, std::allocator<int>>&, Channel const&, int, int, int, int)
pixel_type predict_and_compute_properties(Properties &p, const Channel &ch, int x, int y, int predictor, int offset) {
    pixel_type left = (x ? ch.value_nocheck(y,x-1) : ch.zero);
    pixel_type top = (y ? ch.value_nocheck(y-1,x) : ch.zero);
    pixel_type topleft = (x && y ? ch.value_nocheck(y-1,x-1) : left);
    pixel_type topright = (x+1<ch.w && y ? ch.value_nocheck(y-1,x+1) : top);

//    if (p.size()) {
      pixel_type leftleft = (x>1 ? ch.value_nocheck(y,x-2) : left);
      pixel_type toptop = (y>1 ? ch.value_nocheck(y-2,x) : top);

      // neighbors
      p[offset++] = fooabs(top);
      p[offset++] = fooabs(left);
      p[offset++] = slog(top);
      p[offset++] = slog(left);

      // location
      p[offset++] = y;
      p[offset++] = x;

      // local gradients
      p[offset++] = left+top-topleft;
      p[offset++] = topleft+topright-top;

      // FFV1 context properties
      p[offset++] = slog(left-topleft);
      p[offset++] = slog(topleft-top);
      p[offset++] = slog(top-topright);
      p[offset++] = slog(top-toptop);
      p[offset++] = slog(left-leftleft);
//    }

    switch (predictor) {
        case 0: return ch.zero;
        case 1: return (left+top)/2;
        case 2: return median3((pixel_type) (left+top-topleft), left, top);
        case 3: return left;
        case 4: return top;
        case 5: return (left+topleft+top+topright)/4;
        case 6: return CLAMP(left+top-topleft, ch.minval, ch.maxval);
        default: return median3((pixel_type) (left+top-topleft), left, top);
    }

}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movq %rsi, 0x70(%rsp)
movl %edx, 0x6c(%rsp)
movl %ecx, 0x68(%rsp)
movl %r8d, 0x64(%rsp)
movl %r9d, 0x60(%rsp)
cmpl $0x0, 0x6c(%rsp)
je 0x1da86
movq 0x70(%rsp), %rdi
movl 0x68(%rsp), %esi
movl 0x6c(%rsp), %edx
subl $0x1, %edx
callq 0x131b0
movw %ax, 0x52(%rsp)
jmp 0x1da94
movq 0x70(%rsp), %rax
movw 0x24(%rax), %ax
movw %ax, 0x52(%rsp)
movw 0x52(%rsp), %ax
movw %ax, 0x5e(%rsp)
cmpl $0x0, 0x68(%rsp)
je 0x1dac1
movq 0x70(%rsp), %rdi
movl 0x68(%rsp), %esi
subl $0x1, %esi
movl 0x6c(%rsp), %edx
callq 0x131b0
movw %ax, 0x50(%rsp)
jmp 0x1dacf
movq 0x70(%rsp), %rax
movw 0x24(%rax), %ax
movw %ax, 0x50(%rsp)
movw 0x50(%rsp), %ax
movw %ax, 0x5c(%rsp)
cmpl $0x0, 0x6c(%rsp)
je 0x1db06
cmpl $0x0, 0x68(%rsp)
je 0x1db06
movq 0x70(%rsp), %rdi
movl 0x68(%rsp), %esi
subl $0x1, %esi
movl 0x6c(%rsp), %edx
subl $0x1, %edx
callq 0x131b0
movw %ax, 0x4e(%rsp)
jmp 0x1db10
movw 0x5e(%rsp), %ax
movw %ax, 0x4e(%rsp)
movw 0x4e(%rsp), %ax
movw %ax, 0x5a(%rsp)
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movq 0x70(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x1db51
cmpl $0x0, 0x68(%rsp)
je 0x1db51
movq 0x70(%rsp), %rdi
movl 0x68(%rsp), %esi
subl $0x1, %esi
movl 0x6c(%rsp), %edx
addl $0x1, %edx
callq 0x131b0
movw %ax, 0x4c(%rsp)
jmp 0x1db5b
movw 0x5c(%rsp), %ax
movw %ax, 0x4c(%rsp)
movw 0x4c(%rsp), %ax
movw %ax, 0x58(%rsp)
cmpl $0x1, 0x6c(%rsp)
jle 0x1db88
movq 0x70(%rsp), %rdi
movl 0x68(%rsp), %esi
movl 0x6c(%rsp), %edx
subl $0x2, %edx
callq 0x131b0
movw %ax, 0x4a(%rsp)
jmp 0x1db92
movw 0x5e(%rsp), %ax
movw %ax, 0x4a(%rsp)
movw 0x4a(%rsp), %ax
movw %ax, 0x56(%rsp)
cmpl $0x1, 0x68(%rsp)
jle 0x1dbbf
movq 0x70(%rsp), %rdi
movl 0x68(%rsp), %esi
subl $0x2, %esi
movl 0x6c(%rsp), %edx
callq 0x131b0
movw %ax, 0x48(%rsp)
jmp 0x1dbc9
movw 0x5c(%rsp), %ax
movw %ax, 0x48(%rsp)
movw 0x48(%rsp), %ax
movw %ax, 0x54(%rsp)
movswl 0x5c(%rsp), %edi
callq 0x1cf80
cwtl
movl %eax, 0xc(%rsp)
movq 0x78(%rsp), %rdi
movslq 0x60(%rsp), %rsi
movl %esi, %eax
incl %eax
movl %eax, 0x60(%rsp)
callq 0x12190
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
movswl 0x5e(%rsp), %edi
callq 0x1cf80
cwtl
movl %eax, 0x10(%rsp)
movq 0x78(%rsp), %rdi
movslq 0x60(%rsp), %rsi
movl %esi, %eax
incl %eax
movl %eax, 0x60(%rsp)
callq 0x12190
movl 0x10(%rsp), %ecx
movl %ecx, (%rax)
movswl 0x5c(%rsp), %edi
callq 0x1f6a0
cwtl
movl %eax, 0x14(%rsp)
movq 0x78(%rsp), %rdi
movslq 0x60(%rsp), %rsi
movl %esi, %eax
incl %eax
movl %eax, 0x60(%rsp)
callq 0x12190
movl 0x14(%rsp), %ecx
movl %ecx, (%rax)
movswl 0x5e(%rsp), %edi
callq 0x1f6a0
cwtl
movl %eax, 0x18(%rsp)
movq 0x78(%rsp), %rdi
movslq 0x60(%rsp), %rsi
movl %esi, %eax
incl %eax
movl %eax, 0x60(%rsp)
callq 0x12190
movl 0x18(%rsp), %ecx
movl %ecx, (%rax)
movl 0x68(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x78(%rsp), %rdi
movslq 0x60(%rsp), %rsi
movl %esi, %eax
incl %eax
movl %eax, 0x60(%rsp)
callq 0x12190
movl 0x1c(%rsp), %ecx
movl %ecx, (%rax)
movl 0x6c(%rsp), %eax
movl %eax, 0x20(%rsp)
movq 0x78(%rsp), %rdi
movslq 0x60(%rsp), %rsi
movl %esi, %eax
incl %eax
movl %eax, 0x60(%rsp)
callq 0x12190
movl 0x20(%rsp), %ecx
movl %ecx, (%rax)
movswl 0x5e(%rsp), %eax
movswl 0x5c(%rsp), %ecx
addl %ecx, %eax
movswl 0x5a(%rsp), %ecx
subl %ecx, %eax
movl %eax, 0x24(%rsp)
movq 0x78(%rsp), %rdi
movslq 0x60(%rsp), %rsi
movl %esi, %eax
incl %eax
movl %eax, 0x60(%rsp)
callq 0x12190
movl 0x24(%rsp), %ecx
movl %ecx, (%rax)
movswl 0x5a(%rsp), %eax
movswl 0x58(%rsp), %ecx
addl %ecx, %eax
movswl 0x5c(%rsp), %ecx
subl %ecx, %eax
movl %eax, 0x28(%rsp)
movq 0x78(%rsp), %rdi
movslq 0x60(%rsp), %rsi
movl %esi, %eax
incl %eax
movl %eax, 0x60(%rsp)
callq 0x12190
movl 0x28(%rsp), %ecx
movl %ecx, (%rax)
movzwl 0x5e(%rsp), %eax
movzwl 0x5a(%rsp), %ecx
subl %ecx, %eax
movswl %ax, %edi
callq 0x1f6a0
cwtl
movl %eax, 0x2c(%rsp)
movq 0x78(%rsp), %rdi
movslq 0x60(%rsp), %rsi
movl %esi, %eax
incl %eax
movl %eax, 0x60(%rsp)
callq 0x12190
movl 0x2c(%rsp), %ecx
movl %ecx, (%rax)
movzwl 0x5a(%rsp), %eax
movzwl 0x5c(%rsp), %ecx
subl %ecx, %eax
movswl %ax, %edi
callq 0x1f6a0
cwtl
movl %eax, 0x30(%rsp)
movq 0x78(%rsp), %rdi
movslq 0x60(%rsp), %rsi
movl %esi, %eax
incl %eax
movl %eax, 0x60(%rsp)
callq 0x12190
movl 0x30(%rsp), %ecx
movl %ecx, (%rax)
movzwl 0x5c(%rsp), %eax
movzwl 0x58(%rsp), %ecx
subl %ecx, %eax
movswl %ax, %edi
callq 0x1f6a0
cwtl
movl %eax, 0x34(%rsp)
movq 0x78(%rsp), %rdi
movslq 0x60(%rsp), %rsi
movl %esi, %eax
incl %eax
movl %eax, 0x60(%rsp)
callq 0x12190
movl 0x34(%rsp), %ecx
movl %ecx, (%rax)
movzwl 0x5c(%rsp), %eax
movzwl 0x54(%rsp), %ecx
subl %ecx, %eax
movswl %ax, %edi
callq 0x1f6a0
cwtl
movl %eax, 0x38(%rsp)
movq 0x78(%rsp), %rdi
movslq 0x60(%rsp), %rsi
movl %esi, %eax
incl %eax
movl %eax, 0x60(%rsp)
callq 0x12190
movl 0x38(%rsp), %ecx
movl %ecx, (%rax)
movzwl 0x5e(%rsp), %eax
movzwl 0x56(%rsp), %ecx
subl %ecx, %eax
movswl %ax, %edi
callq 0x1f6a0
cwtl
movl %eax, 0x3c(%rsp)
movq 0x78(%rsp), %rdi
movslq 0x60(%rsp), %rsi
movl %esi, %eax
incl %eax
movl %eax, 0x60(%rsp)
callq 0x12190
movl 0x3c(%rsp), %ecx
movl %ecx, (%rax)
movl 0x64(%rsp), %eax
movq %rax, 0x40(%rsp)
subq $0x6, %rax
ja 0x1dfb8
movq 0x40(%rsp), %rax
leaq 0x2942e(%rip), %rcx     # 0x47290
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x70(%rsp), %rax
movw 0x24(%rax), %ax
movw %ax, 0x86(%rsp)
jmp 0x1dfeb
movswl 0x5e(%rsp), %eax
movswl 0x5c(%rsp), %ecx
addl %ecx, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movw %ax, 0x86(%rsp)
jmp 0x1dfeb
movswl 0x5e(%rsp), %eax
movswl 0x5c(%rsp), %ecx
addl %ecx, %eax
movswl 0x5a(%rsp), %ecx
subl %ecx, %eax
movw %ax, %cx
movw 0x5e(%rsp), %ax
movswl %cx, %edi
movswl %ax, %esi
movswl 0x5c(%rsp), %edx
callq 0x1f770
movw %ax, 0x86(%rsp)
jmp 0x1dfeb
movw 0x5e(%rsp), %ax
movw %ax, 0x86(%rsp)
jmp 0x1dfeb
movw 0x5c(%rsp), %ax
movw %ax, 0x86(%rsp)
jmp 0x1dfeb
movswl 0x5e(%rsp), %eax
movswl 0x5a(%rsp), %ecx
addl %ecx, %eax
movswl 0x5c(%rsp), %ecx
addl %ecx, %eax
movswl 0x58(%rsp), %ecx
addl %ecx, %eax
movl $0x4, %ecx
cltd
idivl %ecx
movw %ax, 0x86(%rsp)
jmp 0x1dfeb
movswl 0x5e(%rsp), %eax
movswl 0x5c(%rsp), %ecx
addl %ecx, %eax
movswl 0x5a(%rsp), %ecx
subl %ecx, %eax
movq 0x70(%rsp), %rcx
movswl 0x20(%rcx), %ecx
cmpl %ecx, %eax
jge 0x1df5c
movq 0x70(%rsp), %rax
movswl 0x20(%rax), %eax
movl %eax, 0x8(%rsp)
jmp 0x1dfaa
movswl 0x5e(%rsp), %eax
movswl 0x5c(%rsp), %ecx
addl %ecx, %eax
movswl 0x5a(%rsp), %ecx
subl %ecx, %eax
movq 0x70(%rsp), %rcx
movswl 0x22(%rcx), %ecx
cmpl %ecx, %eax
jle 0x1df8b
movq 0x70(%rsp), %rax
movswl 0x22(%rax), %eax
movl %eax, 0x4(%rsp)
jmp 0x1dfa2
movswl 0x5e(%rsp), %eax
movswl 0x5c(%rsp), %ecx
addl %ecx, %eax
movswl 0x5a(%rsp), %ecx
subl %ecx, %eax
movl %eax, 0x4(%rsp)
movl 0x4(%rsp), %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %eax
movw %ax, 0x86(%rsp)
jmp 0x1dfeb
movswl 0x5e(%rsp), %eax
movswl 0x5c(%rsp), %ecx
addl %ecx, %eax
movswl 0x5a(%rsp), %ecx
subl %ecx, %eax
movw %ax, %cx
movw 0x5e(%rsp), %ax
movswl %cx, %edi
movswl %ax, %esi
movswl 0x5c(%rsp), %edx
callq 0x1f770
movw %ax, 0x86(%rsp)
movw 0x86(%rsp), %ax
addq $0x88, %rsp
retq
nopl (%rax,%rax)