// File: /workspace/github_cpp_makefile_star2_O3/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:
testl %edx, %edx
je 0x5031
movl 0x18(%rsi), %eax
imull %ecx, %eax
addl %edx, %eax
decl %eax
cltq
addq %rax, %rax
addq (%rsi), %rax
jmp 0x5035
leaq 0x24(%rsi), %rax
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %r8d, -0xc(%rsp)
movzwl (%rax), %r10d
testl %ecx, %ecx
je 0x508f
leal -0x1(%rcx), %r8d
movl 0x18(%rsi), %eax
imull %eax, %r8d
leal (%r8,%rdx), %r11d
movslq %r11d, %r11
movq (%rsi), %rbx
movl %r10d, %r15d
testl %edx, %edx
je 0x5076
leal (%rdx,%r8), %ebp
decl %ebp
movslq %ebp, %r14
movzwl (%rbx,%r14,2), %r15d
movzwl (%rbx,%r11,2), %r11d
leal 0x1(%rdx), %ebp
cmpl %eax, %ebp
jge 0x509a
addl %ebp, %r8d
movslq %r8d, %r8
movzwl (%rbx,%r8,2), %ebp
jmp 0x509d
movzwl 0x24(%rsi), %r11d
movl 0x18(%rsi), %eax
movl %r10d, %r15d
movl %r11d, %ebp
movl %r10d, %r8d
cmpl $0x2, %edx
jl 0x50be
movl %eax, %r8d
imull %ecx, %r8d
addl %edx, %r8d
addl $-0x2, %r8d
movslq %r8d, %r8
movq (%rsi), %rbx
movzwl (%rbx,%r8,2), %r8d
movw %r8w, -0x12(%rsp)
movl %r11d, %r12d
cmpl $0x2, %ecx
jl 0x50e0
leal -0x2(%rcx), %r8d
imull %r8d, %eax
addl %edx, %eax
cltq
movq (%rsi), %r8
movzwl (%r8,%rax,2), %r12d
movd %r11d, %xmm0
pinsrw $0x1, %r10d, %xmm0
pxor %xmm1, %xmm1
xorps %xmm2, %xmm2
movss %xmm0, %xmm2            # xmm2 = xmm0[0],xmm2[1,2,3]
movslq %r9d, %r9
movq (%rdi), %rdi
pshuflw $0x60, %xmm2, %xmm0     # xmm0 = xmm2[0,0,2,1,4,5,6,7]
psubw %xmm0, %xmm1
pmaxsw %xmm0, %xmm1
psrad $0x10, %xmm1
movq %xmm1, (%rdi,%r9,4)
movswl %r11w, %eax
movl %eax, %r14d
negl %r14d
xorl %r8d, %r8d
movl $0x0, %ebx
testw %ax, %ax
je 0x5141
jle 0x5138
bsrl %eax, %ebx
xorl $-0x20, %ebx
addl $0x21, %ebx
jmp 0x5141
bsrl %r14d, %ebx
notl %ebx
orl $-0x20, %ebx
movswl %r10w, %r14d
movl %ebx, 0x8(%rdi,%r9,4)
testw %r10w, %r10w
je 0x5171
jle 0x5160
bsrl %r14d, %r8d
xorl $-0x20, %r8d
addl $0x21, %r8d
jmp 0x5171
movl %r14d, %r8d
negl %r8d
bsrl %r8d, %r8d
notl %r8d
orl $-0x20, %r8d
movl %r8d, 0xc(%rdi,%r9,4)
movl %ecx, 0x10(%rdi,%r9,4)
movl %edx, 0x14(%rdi,%r9,4)
leal (%rax,%r14), %ecx
movswl %r15w, %edx
movl %ecx, -0x10(%rsp)
subl %edx, %ecx
movl %ecx, 0x18(%rdi,%r9,4)
movswl %bp, %ebx
movl %edx, %r8d
subl %eax, %r8d
movq %rbx, -0x8(%rsp)
addl %ebx, %r8d
movl %r8d, 0x1c(%rdi,%r9,4)
xorl %r8d, %r8d
movl %r10d, %r13d
movl $0x0, %ebx
subw %dx, %r13w
je 0x51d8
movswl %r13w, %ebx
testw %bx, %bx
jle 0x51ce
bsrl %ebx, %ebx
xorl $-0x20, %ebx
addl $0x21, %ebx
jmp 0x51d8
negl %ebx
bsrl %ebx, %ebx
notl %ebx
orl $-0x20, %ebx
movl %ebx, 0x20(%rdi,%r9,4)
subw %r11w, %r15w
je 0x5209
movswl %r15w, %r8d
testw %r8w, %r8w
jle 0x51fb
bsrl %r8d, %r8d
xorl $-0x20, %r8d
addl $0x21, %r8d
jmp 0x5209
negl %r8d
bsrl %r8d, %r8d
notl %r8d
orl $-0x20, %r8d
movl %r8d, 0x24(%rdi,%r9,4)
xorl %r8d, %r8d
movl %r11d, %r15d
movl $0x0, %ebx
subw %bp, %r15w
je 0x523d
movswl %r15w, %ebx
testw %bx, %bx
jle 0x5233
bsrl %ebx, %ebx
xorl $-0x20, %ebx
addl $0x21, %ebx
jmp 0x523d
negl %ebx
bsrl %ebx, %ebx
notl %ebx
orl $-0x20, %ebx
movl %ebx, 0x28(%rdi,%r9,4)
movl %r11d, %ebx
subw %r12w, %bx
je 0x5271
movswl %bx, %r8d
testw %r8w, %r8w
jle 0x5263
bsrl %r8d, %r8d
xorl $-0x20, %r8d
addl $0x21, %r8d
jmp 0x5271
negl %r8d
bsrl %r8d, %r8d
notl %r8d
orl $-0x20, %r8d
movl %r8d, 0x2c(%rdi,%r9,4)
xorl %r8d, %r8d
movl %r10d, %ebx
subw -0x12(%rsp), %bx
je 0x52a9
movswl %bx, %r8d
testw %r8w, %r8w
jle 0x529b
bsrl %r8d, %r8d
xorl $-0x20, %r8d
addl $0x21, %r8d
jmp 0x52a9
negl %r8d
bsrl %r8d, %r8d
notl %r8d
orl $-0x20, %r8d
movl %r8d, 0x30(%rdi,%r9,4)
movl -0xc(%rsp), %edi
cmpl $0x6, %edi
ja 0x52cf
movl %edi, %edi
leaq 0x210a0(%rip), %r8      # 0x26360
movslq (%r8,%rdi,4), %rdi
addq %r8, %rdi
jmpq *%rdi
movzwl 0x24(%rsi), %eax
jmp 0x533e
cmpw %cx, %r10w
jle 0x52fc
movl %r10d, %eax
cmpw %r11w, %r10w
jl 0x533e
cmpw %r11w, %cx
cmovgl %ecx, %r11d
jmp 0x530c
movl %r10d, %eax
jmp 0x533e
movl -0x10(%rsp), %ecx
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
shrl %eax
jmp 0x533e
movl %ecx, %eax
cmpw %cx, %r11w
jg 0x533e
cmpw %r11w, %r10w
cmovgl %r10d, %r11d
movl %r11d, %eax
jmp 0x533e
addl %r14d, %edx
addl %eax, %edx
movl %edx, %ecx
movq -0x8(%rsp), %rax
addl %eax, %ecx
leal 0x3(%rax,%rdx), %eax
cmovnsl %ecx, %eax
shrl $0x2, %eax
jmp 0x533e
movswl 0x20(%rsi), %eax
cmpl %eax, %ecx
jl 0x533e
movswl 0x22(%rsi), %eax
cmpl %eax, %ecx
cmovgl %eax, %ecx
movl %ecx, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq