// File: /workspace/github_cpp_makefile_star2_O1/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 0x513b
movl 0x18(%rsi), %eax
imull %ecx, %eax
addl %edx, %eax
decl %eax
movslq %eax, %r10
addq %r10, %r10
addq (%rsi), %r10
jmp 0x513f
leaq 0x24(%rsi), %r10
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
testl %ecx, %ecx
movl %r8d, -0x4(%rsp)
je 0x5165
leal -0x1(%rcx), %eax
imull 0x18(%rsi), %eax
addl %edx, %eax
cltq
addq %rax, %rax
addq (%rsi), %rax
jmp 0x5169
leaq 0x24(%rsi), %rax
movzwl (%r10), %r10d
testl %ecx, %ecx
sete %r8b
testl %edx, %edx
sete %r11b
orb %r8b, %r11b
movl %r10d, %r14d
jne 0x519b
leal -0x1(%rcx), %r8d
imull 0x18(%rsi), %r8d
addl %edx, %r8d
decl %r8d
movslq %r8d, %r8
movq (%rsi), %r11
movzwl (%r11,%r8,2), %r14d
movzwl (%rax), %r11d
testl %ecx, %ecx
sete %r8b
leal 0x1(%rdx), %eax
movl 0x18(%rsi), %ebx
cmpl %ebx, %eax
setge %bpl
orb %r8b, %bpl
movl %r11d, %ebp
jne 0x51cf
leal -0x1(%rcx), %r8d
imull %ebx, %r8d
addl %eax, %r8d
movslq %r8d, %rax
movq (%rsi), %r8
movzwl (%r8,%rax,2), %ebp
movl %r10d, %eax
cmpl $0x2, %edx
jl 0x51eb
movl %ebx, %eax
imull %ecx, %eax
addl %edx, %eax
addl $-0x2, %eax
cltq
movq (%rsi), %r8
movzwl (%r8,%rax,2), %eax
movw %ax, -0x6(%rsp)
movswl %r11w, %r13d
movl %r11d, %r15d
cmpl $0x2, %ecx
jl 0x520f
leal -0x2(%rcx), %eax
imull %eax, %ebx
addl %edx, %ebx
movslq %ebx, %rax
movq (%rsi), %r8
movzwl (%r8,%rax,2), %r15d
movd %r13d, %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)
movl %r13d, %ebx
negl %ebx
xorl %r12d, %r12d
movl $0x0, %eax
testw %r13w, %r13w
je 0x526c
jle 0x5264
bsrl %r13d, %eax
xorl $-0x20, %eax
addl $0x21, %eax
jmp 0x526c
bsrl %ebx, %eax
notl %eax
orl $-0x20, %eax
movswl %r10w, %ebx
movl %eax, 0x8(%rdi,%r9,4)
testw %r10w, %r10w
je 0x529a
jle 0x528b
bsrl %ebx, %r12d
xorl $-0x20, %r12d
addl $0x21, %r12d
jmp 0x529a
movl %ebx, %eax
negl %eax
bsrl %eax, %r12d
notl %r12d
orl $-0x20, %r12d
movl %r12d, 0xc(%rdi,%r9,4)
movl %ecx, 0x10(%rdi,%r9,4)
movl %edx, 0x14(%rdi,%r9,4)
addl %r13d, %ebx
movswl %r14w, %r12d
movl %ebx, %ecx
subl %r12d, %ecx
movl %ecx, 0x18(%rdi,%r9,4)
movswl %bp, %edx
leal (%rdx,%r12), %eax
subl %r13d, %eax
movl %eax, 0x1c(%rdi,%r9,4)
xorl %r13d, %r13d
movl %r10d, %r8d
movl $0x0, %eax
subw %r12w, %r8w
je 0x52f8
movswl %r8w, %eax
testw %ax, %ax
jle 0x52ee
bsrl %eax, %eax
xorl $-0x20, %eax
addl $0x21, %eax
jmp 0x52f8
negl %eax
bsrl %eax, %eax
notl %eax
orl $-0x20, %eax
movl %eax, 0x20(%rdi,%r9,4)
subw %r11w, %r14w
je 0x5327
movswl %r14w, %eax
testw %ax, %ax
jle 0x531a
bsrl %eax, %r13d
xorl $-0x20, %r13d
addl $0x21, %r13d
jmp 0x5327
negl %eax
bsrl %eax, %r13d
notl %r13d
orl $-0x20, %r13d
movl %r13d, 0x24(%rdi,%r9,4)
xorl %r14d, %r14d
movl %r11d, %r8d
movl $0x0, %eax
subw %bp, %r8w
je 0x535b
movswl %r8w, %eax
testw %ax, %ax
jle 0x5351
bsrl %eax, %eax
xorl $-0x20, %eax
addl $0x21, %eax
jmp 0x535b
negl %eax
bsrl %eax, %eax
notl %eax
orl $-0x20, %eax
movl %eax, 0x28(%rdi,%r9,4)
movl %r11d, %eax
subw %r15w, %ax
movl -0x4(%rsp), %r8d
je 0x538f
cwtl
testw %ax, %ax
jle 0x5382
bsrl %eax, %r14d
xorl $-0x20, %r14d
addl $0x21, %r14d
jmp 0x538f
negl %eax
bsrl %eax, %r14d
notl %r14d
orl $-0x20, %r14d
movl %r14d, 0x2c(%rdi,%r9,4)
xorl %ebp, %ebp
movl %r10d, %eax
subw -0x6(%rsp), %ax
je 0x53bb
cwtl
testw %ax, %ax
jle 0x53b1
bsrl %eax, %ebp
xorl $-0x20, %ebp
addl $0x21, %ebp
jmp 0x53bb
negl %eax
bsrl %eax, %ebp
notl %ebp
orl $-0x20, %ebp
movl %ebp, 0x30(%rdi,%r9,4)
cmpl $0x6, %r8d
ja 0x53df
movl %r8d, %eax
leaq 0x20f90(%rip), %rdi     # 0x26360
movslq (%rdi,%rax,4), %rax
addq %rdi, %rax
jmpq *%rax
movzwl 0x24(%rsi), %eax
jmp 0x5443
cmpw %cx, %r10w
jle 0x5408
movl %r10d, %eax
cmpw %r11w, %r10w
jl 0x5443
cmpw %r11w, %cx
cmovgl %ecx, %r11d
jmp 0x5418
movl %r10d, %eax
jmp 0x5443
movl %ebx, %eax
shrl $0x1f, %eax
addl %ebx, %eax
shrl %eax
jmp 0x5443
movl %ecx, %eax
cmpw %cx, %r11w
jg 0x5443
cmpw %r11w, %r10w
cmovgl %r10d, %r11d
movl %r11d, %eax
jmp 0x5443
addl %r12d, %ebx
movl %ebx, %ecx
addl %edx, %ecx
leal 0x3(%rdx,%rbx), %eax
cmovnsl %ecx, %eax
shrl $0x2, %eax
jmp 0x5443
movswl 0x20(%rsi), %eax
cmpl %eax, %ecx
jl 0x5443
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