// File: /workspace/github_cpp_makefile_star2_O1/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 $0x50, %rsp
movq %r9, (%rsp)
movl %ecx, %r10d
movb 0x30(%rdi), %cl
shll %cl, %esi
movl %esi, -0x8(%rsp)
testl %r10d, %r10d
jle 0x112e9
cmpl $0x0, 0x10(%r8)
jle 0x112e9
movq (%rdx), %rcx
movl 0x2c(%rdi), %r15d
movslq 0x18(%rdi), %rdx
movq (%rsp), %rax
movslq 0x18(%rax), %r12
movq (%rax), %rsi
movq 0x8(%rax), %rbp
movq %rsi, -0x68(%rsp)
subq %rsi, %rbp
sarq %rbp
leaq 0x24(%rax), %rbx
movl %r10d, %esi
movq %rdx, 0x8(%rsp)
movl %edx, %eax
movq %rax, -0x70(%rsp)
leaq (%r12,%r12), %rax
movq %rax, -0x48(%rsp)
leaq (,%r12,4), %rax
movq %rax, 0x48(%rsp)
xorl %edi, %edi
movq %r8, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rbp, -0x78(%rsp)
movq %rbx, -0x50(%rsp)
leaq -0x1(%rsi), %r9
movq %r9, %r11
shlq $0x6, %r11
movzwl 0x20(%rcx,%r11), %eax
cmpw 0x22(%rcx,%r11), %ax
je 0x112d6
addq %rcx, %r11
movl 0x2c(%r11), %edx
testl %edx, %edx
js 0x112d6
movb 0x30(%r11), %cl
movl -0x8(%rsp), %eax
sarl %cl, %eax
movl 0x1c(%r11), %ecx
leal -0x1(%rcx), %r8d
cmpl %ecx, %eax
cmovll %eax, %r8d
movl %r8d, -0x7c(%rsp)
cmpl %edx, %r15d
movq %rdi, -0x60(%rsp)
movq %rsi, 0x30(%rsp)
movq %r9, 0x28(%rsp)
jne 0x10d8e
movl 0x18(%r11), %ecx
cmpl %ecx, -0x70(%rsp)
jle 0x1101b
cmpl %edx, %r15d
jge 0x10f4f
movl $0x1, %esi
movl %edx, %ecx
shll %cl, %esi
movl %r15d, %ecx
sarl %cl, %esi
movl 0x18(%r11), %eax
movl %esi, -0x58(%rsp)
cmpl $0x2, %esi
jne 0x110d0
cmpl $0x2, %eax
jl 0x1120b
leal -0x1(%rax), %ecx
movq %rcx, -0x10(%rsp)
imull -0x7c(%rsp), %eax
leal 0x1(%rdi), %ecx
movslq %eax, %r8
movslq %edi, %rax
movslq %ecx, %rcx
addq %r8, %r8
movq %r11, -0x40(%rsp)
addq (%r11), %r8
leaq (%r12,%rcx), %rdx
movq %rdx, -0x20(%rsp)
addq %rdx, %rdx
movq %rdx, -0x28(%rsp)
leaq (%r12,%rax), %rdx
movq %rdx, -0x30(%rsp)
addq %rdx, %rdx
movq %rdx, -0x38(%rsp)
movq %rcx, -0x18(%rsp)
addq %rcx, %rcx
movq %rcx, 0x40(%rsp)
movq %rax, -0x58(%rsp)
addq %rax, %rax
movq %rax, 0x38(%rsp)
xorl %r10d, %r10d
movq -0x68(%rsp), %rax
xorl %r11d, %r11d
xorl %edx, %edx
movswl (%r8,%rdx,2), %r13d
movl %r13d, %edi
negw %di
cmovsw %r13w, %di
movq -0x58(%rsp), %rcx
leaq (%rcx,%r11), %r9
movq %rbx, %rcx
movq 0x38(%rsp), %rsi
leaq (%rax,%rsi), %rbx
cmpq %r9, %rbp
cmovbeq %rcx, %rbx
movw %di, (%rbx)
testl %r13d, %r13d
je 0x10e77
testw %r13w, %r13w
jle 0x10e7c
bsrl %r13d, %r9d
xorl $0xffe0, %r9d           # imm = 0xFFE0
addl $0x21, %r9d
jmp 0x10e90
xorl %r9d, %r9d
jmp 0x10e90
movl %r13d, %r9d
negl %r9d
bsrl %r9d, %r9d
notl %r9d
orl $0xffe0, %r9d           # imm = 0xFFE0
movq -0x18(%rsp), %rcx
leaq (%rcx,%r11), %rbx
movq 0x40(%rsp), %rcx
leaq (%rax,%rcx), %rbp
movq -0x78(%rsp), %r14
cmpq %rbx, %r14
movq -0x50(%rsp), %rcx
cmovbeq %rcx, %rbp
movq -0x30(%rsp), %rsi
leaq (%rsi,%r11), %rbx
movq -0x38(%rsp), %rsi
addq %rax, %rsi
cmpq %rbx, %r14
movq %rcx, %rbx
cmovbeq %rcx, %rsi
movw %r9w, (%rbp)
movw %di, (%rsi)
testw %r13w, %r13w
je 0x10ef1
testw %r13w, %r13w
jle 0x10ef5
bsrl %r13d, %edi
xorl $0xffe0, %edi           # imm = 0xFFE0
addl $0x21, %edi
jmp 0x10f04
xorl %edi, %edi
jmp 0x10f04
negl %r13d
bsrl %r13d, %edi
notl %edi
orl $0xffe0, %edi           # imm = 0xFFE0
movq -0x78(%rsp), %rbp
movq -0x20(%rsp), %rcx
leaq (%rcx,%r11), %rsi
movq -0x28(%rsp), %rcx
leaq (%rax,%rcx), %r9
cmpq %rsi, %rbp
cmovbeq %rbx, %r9
movw %di, (%r9)
incq %rdx
addq -0x48(%rsp), %r11
addq 0x48(%rsp), %rax
addl $0x2, %r10d
cmpq %rdx, -0x10(%rsp)
jne 0x10e2c
movq -0x40(%rsp), %r11
movq %r10, %r8
jmp 0x11210
cmpl $0x0, -0x70(%rsp)
jle 0x112ba
movl 0x18(%r11), %eax
leal -0x1(%rax), %esi
movl -0x7c(%rsp), %ecx
imull %eax, %ecx
movl %ecx, -0x7c(%rsp)
movq (%r11), %r8
movq -0x60(%rsp), %rdi
leal 0x1(%rdi), %ecx
movslq %edi, %r9
movslq %ecx, %r10
movq -0x68(%rsp), %rcx
leaq (%rcx,%r10,2), %r11
leaq (%rcx,%r9,2), %r14
xorl %r13d, %r13d
movl %r13d, %edi
movl %r15d, %ecx
shll %cl, %edi
movl %edx, %ecx
sarl %cl, %edi
cmpl %eax, %edi
cmovgel %esi, %edi
addl -0x7c(%rsp), %edi
movslq %edi, %rcx
movswl (%r8,%rcx,2), %ecx
movl %ecx, %edi
negw %di
cmovsw %cx, %di
cmpq %r9, %rbp
cmovaq %r14, %rbx
movw %di, (%rbx)
testl %ecx, %ecx
je 0x10fd4
testw %cx, %cx
jle 0x10fd8
bsrl %ecx, %ecx
xorl $0xffe0, %ecx           # imm = 0xFFE0
addl $0x21, %ecx
jmp 0x10fe5
xorl %ecx, %ecx
jmp 0x10fe5
negl %ecx
bsrl %ecx, %ecx
notl %ecx
orl $0xffe0, %ecx           # imm = 0xFFE0
movq -0x50(%rsp), %rbx
cmpq %r10, %rbp
movq %rbx, %rdi
cmovaq %r11, %rdi
movw %cx, (%rdi)
incq %r13
addq %r12, %r10
movq -0x48(%rsp), %rcx
addq %rcx, %r11
addq %r12, %r9
addq %rcx, %r14
cmpq %r13, -0x70(%rsp)
jne 0x10f8d
jmp 0x112ba
cmpl $0x0, -0x70(%rsp)
jle 0x112ba
imull -0x7c(%rsp), %ecx
movq -0x60(%rsp), %rax
leal 0x1(%rax), %edx
cltq
movslq %ecx, %rcx
addq %rcx, %rcx
addq (%r11), %rcx
movslq %edx, %rdx
movq -0x68(%rsp), %rdi
leaq (%rdi,%rdx,2), %rsi
leaq (%rdi,%rax,2), %rdi
xorl %r8d, %r8d
movswl (%rcx,%r8,2), %r9d
movl %r9d, %r10d
negw %r10w
cmovsw %r9w, %r10w
cmpq %rax, %rbp
movq %rbx, %r11
cmovaq %rdi, %r11
movw %r10w, (%r11)
testl %r9d, %r9d
je 0x1108c
testw %r9w, %r9w
jle 0x11091
bsrl %r9d, %r9d
xorl $0xffe0, %r9d           # imm = 0xFFE0
addl $0x21, %r9d
jmp 0x110a2
xorl %r9d, %r9d
jmp 0x110a2
negl %r9d
bsrl %r9d, %r9d
notl %r9d
orl $0xffe0, %r9d           # imm = 0xFFE0
cmpq %rdx, %rbp
movq %rbx, %r10
cmovaq %rsi, %r10
movw %r9w, (%r10)
incq %r8
addq %r12, %rdx
movq -0x48(%rsp), %r9
addq %r9, %rsi
addq %r12, %rax
addq %r9, %rdi
cmpq %r8, -0x70(%rsp)
jne 0x11051
jmp 0x112ba
cmpl $0x2, %eax
jl 0x1120b
leal -0x1(%rax), %ecx
movq %rcx, -0x18(%rsp)
imull -0x7c(%rsp), %eax
movq (%rsp), %rcx
movslq 0x18(%rcx), %rsi
movq (%rcx), %rdx
movq 0x8(%rcx), %r10
movq %rdx, -0x20(%rsp)
subq %rdx, %r10
sarq %r10
leal 0x1(%rdi), %ecx
movslq %edi, %rdx
movq %rdx, -0x28(%rsp)
movslq %ecx, %rcx
movq %rcx, -0x30(%rsp)
cltq
addq %rax, %rax
movq %r11, -0x40(%rsp)
addq (%r11), %rax
movq %rax, -0x38(%rsp)
leaq (%rsi,%rsi), %r11
movl -0x58(%rsp), %r14d
negl %r14d
xorl %edx, %edx
xorl %r8d, %r8d
movl %r15d, -0x4(%rsp)
movq %r12, 0x20(%rsp)
cmpl $0x0, -0x58(%rsp)
jle 0x111f6
movq -0x38(%rsp), %rax
movswl (%rax,%rdx,2), %eax
movl %eax, %r13d
negw %r13w
cmovsw %ax, %r13w
movl %eax, %edi
negl %edi
bsrl %edi, %r9d
notl %r9d
orl $-0x20, %r9d
bsrl %eax, %edi
xorl $-0x20, %edi
addl $0x21, %edi
testl %eax, %eax
movq %r8, -0x10(%rsp)
movslq %r8d, %r8
cmovlel %r9d, %edi
cmovel %eax, %edi
imulq %rsi, %r8
movq -0x30(%rsp), %rax
addq %r8, %rax
movq %rbx, %rcx
movq -0x20(%rsp), %r9
leaq (%r9,%rax,2), %rbx
addq -0x28(%rsp), %r8
leaq (%r9,%r8,2), %r9
xorl %ebp, %ebp
cmpq %r8, %r10
movq %rcx, %r12
cmovaq %r9, %r12
cmpq %rax, %r10
movq %rcx, %r15
cmovaq %rbx, %r15
movw %r13w, (%r12)
movw %di, (%r15)
addq %rsi, %rax
addq %r11, %rbx
addq %rsi, %r8
addq %r11, %r9
decl %ebp
cmpl %ebp, %r14d
jne 0x111ac
movq -0x10(%rsp), %r8
subl %ebp, %r8d
movl -0x4(%rsp), %r15d
movq 0x20(%rsp), %r12
movq -0x78(%rsp), %rbp
movq %rcx, %rbx
incq %rdx
cmpq -0x18(%rsp), %rdx
jne 0x11140
movq -0x40(%rsp), %r11
jmp 0x11210
xorl %r8d, %r8d
xorl %edx, %edx
cmpl 0x8(%rsp), %r8d
jge 0x112ba
movl -0x7c(%rsp), %ecx
imull 0x18(%r11), %ecx
movq (%r11), %rax
addl %edx, %ecx
movslq %ecx, %rdx
movswl (%rax,%rdx,2), %esi
movl %esi, %eax
negw %ax
cmovsw %si, %ax
movl %esi, %edx
negl %edx
bsrl %edx, %edi
notl %edi
orl $-0x20, %edi
bsrl %esi, %edx
xorl $-0x20, %edx
addl $0x21, %edx
testl %esi, %esi
movslq %r8d, %r10
movslq -0x60(%rsp), %r8
cmovlel %edi, %edx
cmovel %esi, %edx
movq %r12, %rcx
imulq %r10, %rcx
leaq (%rcx,%r8), %rsi
incq %rsi
addq %r8, %rcx
movq -0x68(%rsp), %r8
leaq (%r8,%rcx,2), %rdi
addq $0x2, %rdi
leaq (%r8,%rcx,2), %r8
movq 0x8(%rsp), %r9
subq %r10, %r9
cmpq %rcx, %rbp
movq %rbx, %r10
cmovaq %r8, %r10
cmpq %rsi, %rbp
movq %rbx, %r11
cmovaq %rdi, %r11
movw %ax, (%r10)
movw %dx, (%r11)
addq %r12, %rsi
movq -0x48(%rsp), %r10
addq %r10, %rdi
addq %r12, %rcx
addq %r10, %r8
decq %r9
jne 0x11288
movq -0x60(%rsp), %rdi
addl $0x2, %edi
movq 0x18(%rsp), %r8
movq 0x10(%rsp), %rcx
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %r9
cmpq $0x2, %rsi
jl 0x112e9
movq %r9, %rsi
cmpl 0x10(%r8), %edi
jl 0x10d23
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq