// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r12
testl %edx, %edx
movl %r8d, 0x2c(%rsp)
je 0x4419
movl 0x18(%rsi), %eax
imull %ecx, %eax
addl %edx, %eax
decl %eax
cltq
addq %rax, %rax
addq (%rsi), %rax
jmp 0x441d
leaq 0x24(%rsi), %rax
movzwl (%rax), %r8d
testl %ecx, %ecx
je 0x447d
leal -0x1(%rcx), %r14d
movl 0x18(%rsi), %eax
imull %eax, %r14d
leal (%r14,%rdx), %r10d
movslq %r10d, %rbx
movq (%rsi), %r10
movl %r8d, %r11d
testl %edx, %edx
je 0x4450
leal (%rdx,%r14), %r11d
decl %r11d
movslq %r11d, %r11
movzwl (%r10,%r11,2), %r11d
movl %r11d, 0x1c(%rsp)
movzwl (%r10,%rbx,2), %r10d
testl %ecx, %ecx
sete %r11b
leal 0x1(%rdx), %ebp
cmpl %eax, %ebp
setge %bl
orb %r11b, %bl
jne 0x448d
addl %ebp, %r14d
movslq %r14d, %r11
movq (%rsi), %rbx
movzwl (%rbx,%r11,2), %r11d
jmp 0x4490
movzwl 0x24(%rsi), %r10d
movl 0x18(%rsi), %eax
movl %r8d, %r11d
movl %r11d, 0x1c(%rsp)
movl %r10d, %r11d
movl %r11d, 0xc(%rsp)
movl %r8d, %r11d
cmpl $0x2, %edx
jl 0x44b6
movl %eax, %r11d
imull %ecx, %r11d
addl %edx, %r11d
addl $-0x2, %r11d
movslq %r11d, %r11
movq (%rsi), %rbx
movzwl (%rbx,%r11,2), %r11d
movl %r11d, 0x28(%rsp)
movl %r8d, 0x8(%rsp)
movswl %r8w, %r13d
movl %r10d, %r8d
cmpl $0x2, %ecx
jl 0x44e0
leal -0x2(%rcx), %r8d
imull %r8d, %eax
addl %edx, %eax
cltq
movq (%rsi), %r8
movzwl (%r8,%rax,2), %r8d
movl %r8d, 0x24(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdx, %r15
movl %r13d, %eax
movl %eax, 0x20(%rsp)
movd %r10d, %xmm0
pinsrw $0x1, %eax, %xmm0
pxor %xmm1, %xmm1
xorps %xmm2, %xmm2
movss %xmm0, %xmm2            # xmm2 = xmm0[0],xmm2[1,2,3]
movq %rcx, 0x10(%rsp)
movslq %r9d, %r14
movq (%r12), %rax
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, (%rax,%r14,4)
movl %r10d, %ebx
movswl %bx, %ebp
movl %ebp, %edi
callq 0x43c8
cwtl
movq (%r12), %rcx
movl %eax, 0x8(%rcx,%r14,4)
movl %r13d, %edi
callq 0x43c8
cwtl
movq (%r12), %rcx
movl %eax, 0xc(%rcx,%r14,4)
movq 0x10(%rsp), %rax
movl %eax, 0x10(%rcx,%r14,4)
movl %r15d, 0x14(%rcx,%r14,4)
addl %ebp, %r13d
movl 0x1c(%rsp), %r15d
movswl %r15w, %eax
movl %r13d, 0x18(%rsp)
subl %eax, %r13d
movl %r13d, 0x10(%rsp)
movl %r13d, 0x18(%rcx,%r14,4)
movl 0xc(%rsp), %r13d
movswl %r13w, %edx
movq %rax, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
addl %edx, %eax
subl %ebp, %eax
movl %ebx, %ebp
movl %eax, 0x1c(%rcx,%r14,4)
movl 0x20(%rsp), %ebx
movl %ebx, %eax
subl %r15d, %eax
movswl %ax, %edi
callq 0x43c8
cwtl
movq (%r12), %rcx
movl %eax, 0x20(%rcx,%r14,4)
subl %ebp, %r15d
movswl %r15w, %edi
callq 0x43c8
cwtl
movq (%r12), %rcx
movl %eax, 0x24(%rcx,%r14,4)
movl %ebp, %eax
subl %r13d, %eax
movswl %ax, %edi
callq 0x43c8
cwtl
movq (%r12), %rcx
movl %eax, 0x28(%rcx,%r14,4)
movl %ebp, %eax
subl 0x24(%rsp), %eax
movswl %ax, %edi
callq 0x43c8
cwtl
movq (%r12), %rcx
movl %eax, 0x2c(%rcx,%r14,4)
movl %ebx, %eax
subl 0x28(%rsp), %eax
movswl %ax, %edi
callq 0x43c8
cwtl
movq (%r12), %rcx
movl %eax, 0x30(%rcx,%r14,4)
movl 0x2c(%rsp), %eax
cmpl $0x6, %eax
ja 0x463f
movl %eax, %eax
leaq 0x19cb5(%rip), %rcx     # 0x1e2e0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x30(%rsp), %rax
movzwl 0x24(%rax), %eax
jmp 0x468d
movl 0x8(%rsp), %ecx
movl 0x10(%rsp), %edx
cmpw %dx, %cx
jle 0x466a
movl %ecx, %eax
cmpw %bp, %cx
jl 0x468d
cmpw %bp, %dx
cmovgl %edx, %ebp
jmp 0x4677
movl 0x8(%rsp), %eax
jmp 0x468d
pushq $0x2
popq %rcx
movl 0x18(%rsp), %eax
jmp 0x468a
movl %edx, %eax
cmpw %dx, %bp
jg 0x468d
cmpw %bp, %cx
cmovgl %ecx, %ebp
movl %ebp, %eax
jmp 0x468d
movl 0x18(%rsp), %eax
addl 0x40(%rsp), %eax
addl 0x38(%rsp), %eax
pushq $0x4
popq %rcx
cltd
idivl %ecx
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%rsp), %rcx
movswl 0x20(%rcx), %eax
movl 0x10(%rsp), %edx
cmpl %eax, %edx
jl 0x468d
movswl 0x22(%rcx), %eax
cmpl %eax, %edx
cmovgl %eax, %edx
movl %edx, %eax
jmp 0x468d