// File: /workspace/github_cpp_makefile_star2_O2/cloudinary[P]fuif/encoding/context_predict.h
// Function: precompute_references(Channel const&, int, Image const&, int, fuif_options&, Channel&)
void precompute_references(const Channel &ch, int y, const Image &image, int i, fuif_options &options, Channel &references) {
    int offset=0;
    int oy = y << ch.vshift;
//    for (int j=i-1; j>=image.nb_meta_channels && offset < options.max_properties; j--) {
    for (int j=i-1; j>=0 && offset < options.max_properties; j--) {
        if (image.channel[j].minval == image.channel[j].maxval) continue;
        if (image.channel[j].hshift < 0) continue;
        int ry = oy >> image.channel[j].vshift;
        if (ry >= image.channel[j].h) ry = image.channel[j].h-1;
        if (ch.hshift == image.channel[j].hshift && ch.w <= image.channel[j].w)
        for (int x=0; x<ch.w; x++) {
            pixel_type v = image.channel[j].value_nocheck(ry,x);
            references.value(x,offset) = fooabs(v);
            references.value(x,offset+1) = slog(v);
        }
        else if (ch.hshift < image.channel[j].hshift) {
          int stepsize = (1 << image.channel[j].hshift) >> ch.hshift;
          int x=0, rx=0;
          pixel_type v;
          if (stepsize == 2)
            for (; rx<image.channel[j].w-1; rx++) {
              v = image.channel[j].value_nocheck(ry,rx);
              references.value(x,offset) = fooabs(v);
              references.value(x,offset+1) = slog(v);
              x++;
              references.value(x,offset) = fooabs(v);
              references.value(x,offset+1) = slog(v);
              x++;
            }
          else
            for (; rx<image.channel[j].w-1; rx++) {
              v = image.channel[j].value_nocheck(ry,rx);
              for (int s=0; s<stepsize; s++, x++) {
                references.value(x,offset) = fooabs(v);
                references.value(x,offset+1) = slog(v);
              }
            }
          assert (x-1 < ch.w);
          v = image.channel[j].value_nocheck(ry,rx);
          while (x<ch.w) {
              references.value(x,offset) = fooabs(v);
              references.value(x,offset+1) = slog(v);
              x++;
          }
        } else
        for (int x=0; x<ch.w; x++) {
            int ox = x << ch.hshift;
            int rx = ox >> image.channel[j].hshift;
            if (rx >= image.channel[j].w) rx = image.channel[j].w-1;
            pixel_type v = image.channel[j].value_nocheck(ry,rx);
            references.value(x,offset) = fooabs(v);
            references.value(x,offset+1) = slog(v);
        }

        offset += 2;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x28(%rsp)
movl %ecx, %eax
movq %rdi, 0x18(%rsp)
movb 0x30(%rdi), %cl
shll %cl, %esi
movl %eax, %r10d
movq $0x0, (%rsp)
movq %rdx, 0x20(%rsp)
movl 0x10(%r8), %ecx
movq (%rdx), %r9
movl %r10d, %r11d
leaq -0x1(%r10), %rax
shlq $0x6, %r10
leaq -0x10(%r9), %rdi
movq %r10, %rbx
movq %rax, %r10
testl %r11d, %r11d
jle 0xccc1
cmpl %ecx, (%rsp)
jge 0xccc1
movzwl -0x10(%rdi,%rbx), %eax
cmpw -0xe(%rdi,%rbx), %ax
je 0xc90b
movl -0x4(%rdi,%rbx), %eax
testl %eax, %eax
jns 0xc917
decl %r11d
decq %r10
addq $-0x40, %rbx
jmp 0xc8e5
movb -0x10(%r9,%rbx), %cl
movl %esi, %r11d
sarl %cl, %r11d
movl -0x24(%r9,%rbx), %ecx
leal -0x1(%rcx), %edi
cmpl %ecx, %r11d
cmovll %r11d, %edi
movl %edi, 0x8(%rsp)
movq 0x18(%rsp), %rcx
movl 0x2c(%rcx), %edi
cmpl %eax, %edi
movq %rbx, 0x30(%rsp)
movq %r8, 0x48(%rsp)
movl %esi, 0x38(%rsp)
movq %r10, 0x40(%rsp)
jne 0xc967
movq 0x18(%rsp), %rcx
movl 0x18(%rcx), %ecx
cmpl -0x28(%r9,%rbx), %ecx
jle 0xcaf6
cmpl %eax, %edi
jge 0xca55
pushq $0x1
popq %rcx
movl %ecx, %esi
movl %eax, %ecx
shll %cl, %esi
movl %edi, %ecx
sarl %cl, %esi
movq (%rsp), %rax
orl $0x1, %eax
movl %eax, 0xc(%rsp)
xorl %ebp, %ebp
cmpl $0x2, %esi
jne 0xcb7e
xorl %r13d, %r13d
movl -0x28(%r9,%rbx), %eax
leal -0x1(%rax), %ecx
cmpl %ecx, %r13d
jge 0xcc3d
imull 0x8(%rsp), %eax
addl %r13d, %eax
cltq
movq -0x40(%r9,%rbx), %rcx
movswl (%rcx,%rax,2), %r12d
movl %r12d, %ebx
negw %bx
cmovsw %r12w, %bx
movq 0x28(%rsp), %r14
movq %r14, %rdi
movl %ebp, %esi
movl %r13d, 0x10(%rsp)
movq %rbp, %r13
movq (%rsp), %rbp
movl %ebp, %edx
callq 0xa44a
movw %bx, (%rax)
movl %r12d, %edi
callq 0x43c8
movl %eax, %r15d
movq %r14, %rdi
movl %r13d, %esi
movl 0xc(%rsp), %edx
callq 0xa44a
movw %r15w, (%rax)
leal 0x1(%r13), %r15d
movq %r14, %rdi
movl %r15d, %esi
movl %ebp, %edx
movq %r13, %rbp
movl 0x10(%rsp), %r13d
callq 0xa44a
movw %bx, (%rax)
movq 0x30(%rsp), %rbx
movl %r12d, %edi
callq 0x43c8
movl %eax, %r12d
movq %r14, %rdi
movl %r15d, %esi
movl 0xc(%rsp), %edx
callq 0xa44a
movw %r12w, (%rax)
addl $0x2, %ebp
incl %r13d
movq 0x20(%rsp), %rax
movq (%rax), %r9
jmp 0xc995
movq (%rsp), %rax
movl %eax, %ebp
orl $0x1, %ebp
xorl %r14d, %r14d
movq 0x18(%rsp), %rax
cmpl 0x18(%rax), %r14d
jge 0xcc9e
movq 0x18(%rsp), %rax
movb 0x2c(%rax), %cl
movl %r14d, %eax
shll %cl, %eax
movq 0x20(%rsp), %rcx
movq (%rcx), %rdx
movb -0x14(%rdx,%rbx), %cl
sarl %cl, %eax
movl -0x28(%rdx,%rbx), %ecx
leal -0x1(%rcx), %esi
cmpl %ecx, %eax
cmovll %eax, %esi
imull 0x8(%rsp), %ecx
addl %esi, %ecx
movslq %ecx, %rax
movq -0x40(%rdx,%rbx), %rcx
movswl (%rcx,%rax,2), %r15d
movl %r15d, %ebx
negw %bx
cmovsw %r15w, %bx
movq 0x28(%rsp), %r12
movq %r12, %rdi
movl %r14d, %esi
movq (%rsp), %rdx
callq 0xa44a
movw %bx, (%rax)
movq 0x30(%rsp), %rbx
movl %r15d, %edi
callq 0x43c8
movl %eax, %r15d
movq %r12, %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0xa44a
movw %r15w, (%rax)
incl %r14d
jmp 0xca61
movq (%rsp), %rax
movl %eax, %ebp
orl $0x1, %ebp
xorl %r14d, %r14d
cmpl %ecx, %r14d
jge 0xcc9e
movq 0x20(%rsp), %rax
movq (%rax), %rax
movslq -0x28(%rax,%rbx), %rcx
movslq 0x8(%rsp), %rdx
imulq %rcx, %rdx
addq %r14, %rdx
movq -0x40(%rax,%rbx), %rax
movswl (%rax,%rdx,2), %r12d
movl %r12d, %ebx
negw %bx
cmovsw %r12w, %bx
movq 0x28(%rsp), %r15
movq %r15, %rdi
movl %r14d, %esi
movq (%rsp), %rdx
callq 0xa44a
movw %bx, (%rax)
movq 0x30(%rsp), %rbx
movl %r12d, %edi
callq 0x43c8
movl %eax, %r12d
movq %r15, %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0xa44a
movw %r12w, (%rax)
movq 0x18(%rsp), %rax
movl 0x18(%rax), %ecx
incq %r14
jmp 0xcb02
testl %esi, %esi
cmovlel %ebp, %esi
xorl %r13d, %r13d
movl -0x28(%r9,%rbx), %eax
leal -0x1(%rax), %ecx
cmpl %ecx, %r13d
jge 0xcc3d
imull 0x8(%rsp), %eax
movl %r13d, 0x10(%rsp)
addl %r13d, %eax
cltq
movq -0x40(%r9,%rbx), %rcx
movzwl (%rcx,%rax,2), %eax
movl %eax, %r13d
negw %r13w
movw %ax, 0x16(%rsp)
cmovsw %ax, %r13w
movq %rbp, 0x50(%rsp)
leal (%rsi,%rbp), %eax
movl %eax, 0x3c(%rsp)
xorl %ebp, %ebp
cmpl %ebp, %esi
je 0xcc1d
movq 0x50(%rsp), %rax
leal (%rax,%rbp), %r15d
movq 0x28(%rsp), %r14
movq %r14, %rdi
movq %rsi, %rbx
movl %r15d, %esi
movq (%rsp), %rdx
callq 0xa44a
movw %r13w, (%rax)
movswl 0x16(%rsp), %edi
callq 0x43c8
movl %eax, %r12d
movq %r14, %rdi
movl %r15d, %esi
movl 0xc(%rsp), %edx
callq 0xa44a
movq %rbx, %rsi
movw %r12w, (%rax)
incl %ebp
jmp 0xcbce
movl 0x10(%rsp), %r13d
incl %r13d
movq 0x20(%rsp), %rax
movq (%rax), %r9
movl 0x3c(%rsp), %eax
movl %eax, %ebp
movq 0x30(%rsp), %rbx
jmp 0xcb86
imull 0x8(%rsp), %eax
addl %r13d, %eax
cltq
movq -0x40(%r9,%rbx), %rcx
movzwl (%rcx,%rax,2), %ebx
movl %ebx, %r14d
negw %r14w
cmovsw %bx, %r14w
movq 0x18(%rsp), %rax
cmpl 0x18(%rax), %ebp
jge 0xcc9e
movq 0x28(%rsp), %r12
movq %r12, %rdi
movl %ebp, %esi
movq (%rsp), %rdx
callq 0xa44a
movw %r14w, (%rax)
movswl %bx, %edi
callq 0x43c8
movl %eax, %r15d
movq %r12, %rdi
movl %ebp, %esi
movl 0xc(%rsp), %edx
callq 0xa44a
movw %r15w, (%rax)
incl %ebp
jmp 0xcc5c
movq (%rsp), %rax
addl $0x2, %eax
movq %rax, (%rsp)
movq 0x48(%rsp), %r8
movl 0x38(%rsp), %esi
movq 0x20(%rsp), %rdx
movq 0x40(%rsp), %r10
jmp 0xc8c9
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq