// File: 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:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
movl %esi, 0xac(%rsp)
movq %rdx, 0xa0(%rsp)
movl %ecx, 0x9c(%rsp)
movq %r8, 0x90(%rsp)
movq %r9, 0x88(%rsp)
movl $0x0, 0x84(%rsp)
movl 0xac(%rsp), %eax
movq 0xb0(%rsp), %rcx
movl 0x30(%rcx), %ecx
shll %cl, %eax
movl %eax, 0x80(%rsp)
movl 0x9c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x7c(%rsp)
xorl %eax, %eax
cmpl $0x0, 0x7c(%rsp)
movb %al, 0x4d(%rsp)
jl 0x1e3ff
movl 0x84(%rsp), %eax
movq 0x90(%rsp), %rcx
cmpl 0x10(%rcx), %eax
setl %al
movb %al, 0x4d(%rsp)
movb 0x4d(%rsp), %al
testb $0x1, %al
jne 0x1e40c
jmp 0x1eab2
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movswl 0x20(%rax), %eax
movl %eax, 0x48(%rsp)
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movq %rax, %rcx
movl 0x48(%rsp), %eax
movswl 0x22(%rcx), %ecx
cmpl %ecx, %eax
jne 0x1e44c
jmp 0x1eaa2
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
cmpl $0x0, 0x2c(%rax)
jge 0x1e469
jmp 0x1eaa2
movl 0x80(%rsp), %eax
movl %eax, 0x40(%rsp)
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movq %rax, %rcx
movl 0x40(%rsp), %eax
movl 0x30(%rcx), %ecx
sarl %cl, %eax
movl %eax, 0x78(%rsp)
movl 0x78(%rsp), %eax
movl %eax, 0x44(%rsp)
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movq %rax, %rcx
movl 0x44(%rsp), %eax
cmpl 0x1c(%rcx), %eax
jl 0x1e4d8
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movl 0x1c(%rax), %eax
subl $0x1, %eax
movl %eax, 0x78(%rsp)
movq 0xb0(%rsp), %rax
movl 0x2c(%rax), %eax
movl %eax, 0x3c(%rsp)
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movq %rax, %rcx
movl 0x3c(%rsp), %eax
cmpl 0x2c(%rcx), %eax
jne 0x1e5f4
movq 0xb0(%rsp), %rax
movl 0x18(%rax), %eax
movl %eax, 0x38(%rsp)
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movq %rax, %rcx
movl 0x38(%rsp), %eax
cmpl 0x18(%rcx), %eax
jg 0x1e5f4
movl $0x0, 0x74(%rsp)
movl 0x74(%rsp), %eax
movq 0xb0(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x1e5ef
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movq %rax, %rdi
movl 0x78(%rsp), %esi
movl 0x74(%rsp), %edx
callq 0x131b0
movw %ax, 0x72(%rsp)
movswl 0x72(%rsp), %edi
callq 0x1cf80
movw %ax, 0x34(%rsp)
movq 0x88(%rsp), %rdi
movl 0x74(%rsp), %esi
movl 0x84(%rsp), %edx
callq 0x12110
movw 0x34(%rsp), %cx
movw %cx, (%rax)
movswl 0x72(%rsp), %edi
callq 0x1f6a0
movw %ax, 0x36(%rsp)
movq 0x88(%rsp), %rdi
movl 0x74(%rsp), %esi
movl 0x84(%rsp), %edx
addl $0x1, %edx
callq 0x12110
movw 0x36(%rsp), %cx
movw %cx, (%rax)
movl 0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x74(%rsp)
jmp 0x1e542
jmp 0x1ea91
movq 0xb0(%rsp), %rax
movl 0x2c(%rax), %eax
movl %eax, 0x30(%rsp)
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movq %rax, %rcx
movl 0x30(%rsp), %eax
cmpl 0x2c(%rcx), %eax
jge 0x1e957
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movl 0x2c(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movq 0xb0(%rsp), %rcx
movl 0x2c(%rcx), %ecx
sarl %cl, %eax
movl %eax, 0x6c(%rsp)
movl $0x0, 0x68(%rsp)
movl $0x0, 0x64(%rsp)
cmpl $0x2, 0x6c(%rsp)
jne 0x1e7b2
jmp 0x1e66f
movl 0x64(%rsp), %eax
movl %eax, 0x2c(%rsp)
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movq %rax, %rcx
movl 0x2c(%rsp), %eax
movl 0x18(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1e7ad
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movq %rax, %rdi
movl 0x78(%rsp), %esi
movl 0x64(%rsp), %edx
callq 0x131b0
movw %ax, 0x62(%rsp)
movswl 0x62(%rsp), %edi
callq 0x1cf80
movw %ax, 0x24(%rsp)
movq 0x88(%rsp), %rdi
movl 0x68(%rsp), %esi
movl 0x84(%rsp), %edx
callq 0x12110
movw 0x24(%rsp), %cx
movw %cx, (%rax)
movswl 0x62(%rsp), %edi
callq 0x1f6a0
movw %ax, 0x26(%rsp)
movq 0x88(%rsp), %rdi
movl 0x68(%rsp), %esi
movl 0x84(%rsp), %edx
addl $0x1, %edx
callq 0x12110
movw 0x26(%rsp), %cx
movw %cx, (%rax)
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
movswl 0x62(%rsp), %edi
callq 0x1cf80
movw %ax, 0x28(%rsp)
movq 0x88(%rsp), %rdi
movl 0x68(%rsp), %esi
movl 0x84(%rsp), %edx
callq 0x12110
movw 0x28(%rsp), %cx
movw %cx, (%rax)
movswl 0x62(%rsp), %edi
callq 0x1f6a0
movw %ax, 0x2a(%rsp)
movq 0x88(%rsp), %rdi
movl 0x68(%rsp), %esi
movl 0x84(%rsp), %edx
addl $0x1, %edx
callq 0x12110
movw 0x2a(%rsp), %cx
movw %cx, (%rax)
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x1e66f
jmp 0x1e8ac
jmp 0x1e7b4
movl 0x64(%rsp), %eax
movl %eax, 0x20(%rsp)
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movq %rax, %rcx
movl 0x20(%rsp), %eax
movl 0x18(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1e8aa
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movq %rax, %rdi
movl 0x78(%rsp), %esi
movl 0x64(%rsp), %edx
callq 0x131b0
movw %ax, 0x62(%rsp)
movl $0x0, 0x5c(%rsp)
movl 0x5c(%rsp), %eax
cmpl 0x6c(%rsp), %eax
jge 0x1e898
movswl 0x62(%rsp), %edi
callq 0x1cf80
movw %ax, 0x1c(%rsp)
movq 0x88(%rsp), %rdi
movl 0x68(%rsp), %esi
movl 0x84(%rsp), %edx
callq 0x12110
movw 0x1c(%rsp), %cx
movw %cx, (%rax)
movswl 0x62(%rsp), %edi
callq 0x1f6a0
movw %ax, 0x1e(%rsp)
movq 0x88(%rsp), %rdi
movl 0x68(%rsp), %esi
movl 0x84(%rsp), %edx
addl $0x1, %edx
callq 0x12110
movw 0x1e(%rsp), %cx
movw %cx, (%rax)
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x1e812
jmp 0x1e89a
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x1e7b4
jmp 0x1e8ac
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movq %rax, %rdi
movl 0x78(%rsp), %esi
movl 0x64(%rsp), %edx
callq 0x131b0
movw %ax, 0x62(%rsp)
movl 0x68(%rsp), %eax
movq 0xb0(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x1e952
movswl 0x62(%rsp), %edi
callq 0x1cf80
movw %ax, 0x18(%rsp)
movq 0x88(%rsp), %rdi
movl 0x68(%rsp), %esi
movl 0x84(%rsp), %edx
callq 0x12110
movw 0x18(%rsp), %cx
movw %cx, (%rax)
movswl 0x62(%rsp), %edi
callq 0x1f6a0
movw %ax, 0x1a(%rsp)
movq 0x88(%rsp), %rdi
movl 0x68(%rsp), %esi
movl 0x84(%rsp), %edx
addl $0x1, %edx
callq 0x12110
movw 0x1a(%rsp), %cx
movw %cx, (%rax)
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x1e8d3
jmp 0x1ea8f
movl $0x0, 0x58(%rsp)
movl 0x58(%rsp), %eax
movq 0xb0(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x1ea8d
movl 0x58(%rsp), %eax
movq 0xb0(%rsp), %rcx
movl 0x2c(%rcx), %ecx
shll %cl, %eax
movl %eax, 0x54(%rsp)
movl 0x54(%rsp), %eax
movl %eax, 0x10(%rsp)
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movq %rax, %rcx
movl 0x10(%rsp), %eax
movl 0x2c(%rcx), %ecx
sarl %cl, %eax
movl %eax, 0x50(%rsp)
movl 0x50(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movq %rax, %rcx
movl 0x14(%rsp), %eax
cmpl 0x18(%rcx), %eax
jl 0x1e9f5
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movl 0x18(%rax), %eax
subl $0x1, %eax
movl %eax, 0x50(%rsp)
movq 0xa0(%rsp), %rdi
movslq 0x7c(%rsp), %rsi
callq 0x13390
movq %rax, %rdi
movl 0x78(%rsp), %esi
movl 0x50(%rsp), %edx
callq 0x131b0
movw %ax, 0x4e(%rsp)
movswl 0x4e(%rsp), %edi
callq 0x1cf80
movw %ax, 0xc(%rsp)
movq 0x88(%rsp), %rdi
movl 0x58(%rsp), %esi
movl 0x84(%rsp), %edx
callq 0x12110
movw 0xc(%rsp), %cx
movw %cx, (%rax)
movswl 0x4e(%rsp), %edi
callq 0x1f6a0
movw %ax, 0xe(%rsp)
movq 0x88(%rsp), %rdi
movl 0x58(%rsp), %esi
movl 0x84(%rsp), %edx
addl $0x1, %edx
callq 0x12110
movw 0xe(%rsp), %cx
movw %cx, (%rax)
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x1e95f
jmp 0x1ea8f
jmp 0x1ea91
movl 0x84(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x84(%rsp)
movl 0x7c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x1e3d9
addq $0xb8, %rsp
retq
nopw (%rax,%rax)