// File: /workspace/github_cpp_makefile_star2_O3/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, 0x20(%rsp)
movl %ecx, %r10d
movb 0x30(%rdi), %cl
shll %cl, %esi
movl %esi, 0x1c(%rsp)
testl %r10d, %r10d
setg %cl
movq %r8, 0x30(%rsp)
movl 0x10(%r8), %eax
testl %eax, %eax
setg %sil
andb %cl, %sil
cmpb $0x1, %sil
jne 0x11264
movq (%rdx), %rsi
movl 0x2c(%rdi), %r15d
movslq 0x18(%rdi), %rdx
movq 0x20(%rsp), %rcx
movslq 0x18(%rcx), %r12
movq (%rcx), %rdi
movq 0x8(%rcx), %r13
movq %rdi, -0x58(%rsp)
subq %rdi, %r13
sarq %r13
leaq 0x24(%rcx), %rbx
movl %r10d, %edi
movq %rdx, -0x20(%rsp)
movl %edx, %ecx
movq %rcx, -0x40(%rsp)
leaq (%r12,%r12), %rcx
movq %rcx, -0x38(%rsp)
leaq (,%r12,4), %rcx
movq %rcx, 0x50(%rsp)
xorl %r8d, %r8d
movq %rsi, 0x28(%rsp)
movq %r13, -0x68(%rsp)
movq %rbx, -0x78(%rsp)
movl %r15d, -0x5c(%rsp)
leaq -0x1(%rdi), %r9
movq %r9, %r10
shlq $0x6, %r10
movzwl 0x20(%rsi,%r10), %ecx
cmpw 0x22(%rsi,%r10), %cx
je 0x11252
addq %rsi, %r10
movl 0x2c(%r10), %edx
testl %edx, %edx
js 0x11252
movb 0x30(%r10), %cl
movl 0x1c(%rsp), %eax
sarl %cl, %eax
movl 0x1c(%r10), %ecx
leal -0x1(%rcx), %esi
cmpl %ecx, %eax
cmovll %eax, %esi
movl %esi, -0x7c(%rsp)
cmpl %edx, %r15d
movq %r8, -0x50(%rsp)
movq %rdi, 0x48(%rsp)
movq %r9, 0x40(%rsp)
jne 0x10ce5
movl 0x18(%r10), %ecx
cmpl %ecx, -0x20(%rsp)
jle 0x10f88
cmpl %edx, %r15d
jge 0x10eb3
movl $0x1, %eax
movl %edx, %ecx
shll %cl, %eax
movl %r15d, %ecx
sarl %cl, %eax
movl 0x18(%r10), %ecx
leal -0x1(%rcx), %edi
movl %eax, -0x48(%rsp)
cmpl $0x2, %eax
jne 0x1103d
cmpl $0x2, %ecx
jl 0x11187
movq %rcx, -0x30(%rsp)
movl %ecx, %eax
imull -0x7c(%rsp), %eax
leal 0x1(%r8), %ecx
movslq %eax, %rsi
movslq %r8d, %rax
movslq %ecx, %rcx
movl %edi, -0x6c(%rsp)
movl %edi, %r15d
addq %rsi, %rsi
movq %r10, -0x28(%rsp)
addq (%r10), %rsi
leaq (%r12,%rcx), %rdx
movq %rdx, 0x8(%rsp)
addq %rdx, %rdx
movq %rdx, (%rsp)
leaq (%r12,%rax), %r10
leaq (%r10,%r10), %rdx
movq %rdx, -0x8(%rsp)
movq %rcx, -0x48(%rsp)
addq %rcx, %rcx
movq %rcx, -0x10(%rsp)
movq %rax, 0x10(%rsp)
addq %rax, %rax
movq %rax, -0x18(%rsp)
addq %r15, %r15
movq -0x58(%rsp), %rbp
xorl %r11d, %r11d
xorl %r14d, %r14d
movq %r14, %r9
movswl (%rsi,%r14), %edi
movl %edi, %r8d
negw %r8w
cmovsw %di, %r8w
movq 0x10(%rsp), %rax
leaq (%rax,%r11), %rbx
movq -0x18(%rsp), %rax
leaq (%rax,%rbp), %r14
cmpq %rbx, %r13
cmovbeq -0x78(%rsp), %r14
movw %r8w, (%r14)
testl %edi, %edi
je 0x10dd3
testw %di, %di
jle 0x10dd7
bsrl %edi, %ebx
xorl $0xffe0, %ebx           # imm = 0xFFE0
addl $0x21, %ebx
jmp 0x10de6
xorl %ebx, %ebx
jmp 0x10de6
movl %edi, %ebx
negl %ebx
bsrl %ebx, %ebx
notl %ebx
orl $0xffe0, %ebx           # imm = 0xFFE0
movq -0x48(%rsp), %rax
leaq (%rax,%r11), %r14
movq -0x10(%rsp), %rax
leaq (%rax,%rbp), %r13
movq -0x68(%rsp), %rax
cmpq %r14, %rax
movq -0x78(%rsp), %rdx
cmovbeq %rdx, %r13
leaq (%r10,%r11), %r14
movq -0x8(%rsp), %rcx
addq %rbp, %rcx
cmpq %r14, %rax
cmovbeq %rdx, %rcx
movw %bx, (%r13)
movw %r8w, (%rcx)
testw %di, %di
je 0x10e40
testw %di, %di
movq %r9, %r14
jle 0x10e51
bsrl %edi, %edi
xorl $0xffe0, %edi           # imm = 0xFFE0
addl $0x21, %edi
jmp 0x10e5e
xorl %edi, %edi
movq -0x68(%rsp), %r13
movq -0x78(%rsp), %rbx
movq %r9, %r14
jmp 0x10e68
negl %edi
bsrl %edi, %edi
notl %edi
orl $0xffe0, %edi           # imm = 0xFFE0
movq -0x68(%rsp), %r13
movq -0x78(%rsp), %rbx
movq 0x8(%rsp), %rax
leaq (%rax,%r11), %rcx
movq (%rsp), %rax
leaq (%rax,%rbp), %r8
cmpq %rcx, %r13
cmovbeq %rbx, %r8
movw %di, (%r8)
addq $0x2, %r14
addq -0x38(%rsp), %r11
addq 0x50(%rsp), %rbp
cmpq %r14, %r15
jne 0x10d89
movq -0x28(%rsp), %r10
movq -0x30(%rsp), %rcx
movl -0x6c(%rsp), %edx
movl -0x5c(%rsp), %r15d
jmp 0x1118c
cmpl $0x0, -0x20(%rsp)
jle 0x11232
movl 0x18(%r10), %eax
leal -0x1(%rax), %esi
movl -0x7c(%rsp), %ecx
imull %eax, %ecx
movl %ecx, -0x7c(%rsp)
movq (%r10), %r9
movq -0x50(%rsp), %rdi
leal 0x1(%rdi), %ecx
movslq %edi, %r10
movslq %ecx, %rdi
movq -0x58(%rsp), %rcx
leaq (%rcx,%rdi,2), %r11
leaq (%rcx,%r10,2), %r14
xorl %ebp, %ebp
movl %ebp, %r8d
movl %r15d, %ecx
shll %cl, %r8d
movl %edx, %ecx
sarl %cl, %r8d
cmpl %eax, %r8d
cmovgel %esi, %r8d
addl -0x7c(%rsp), %r8d
movslq %r8d, %rcx
movswl (%r9,%rcx,2), %ecx
movl %ecx, %r8d
negw %r8w
cmovsw %cx, %r8w
cmpq %r10, %r13
cmovaq %r14, %rbx
movw %r8w, (%rbx)
testl %ecx, %ecx
je 0x10f40
testw %cx, %cx
jle 0x10f44
bsrl %ecx, %ecx
xorl $0xffe0, %ecx           # imm = 0xFFE0
addl $0x21, %ecx
jmp 0x10f51
xorl %ecx, %ecx
jmp 0x10f51
negl %ecx
bsrl %ecx, %ecx
notl %ecx
orl $0xffe0, %ecx           # imm = 0xFFE0
movq -0x78(%rsp), %rbx
cmpq %rdi, %r13
movq %rbx, %r8
cmovaq %r11, %r8
movw %cx, (%r8)
incq %rbp
addq %r12, %rdi
movq -0x38(%rsp), %rcx
addq %rcx, %r11
addq %r12, %r10
addq %rcx, %r14
cmpq %rbp, -0x40(%rsp)
jne 0x10ef0
jmp 0x11232
cmpl $0x0, -0x40(%rsp)
jle 0x11232
imull -0x7c(%rsp), %ecx
movq -0x50(%rsp), %rax
leal 0x1(%rax), %edx
cltq
movslq %ecx, %rcx
addq %rcx, %rcx
addq (%r10), %rcx
movslq %edx, %rdx
movq -0x58(%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, %r13
movq %rbx, %r11
cmovaq %rdi, %r11
movw %r10w, (%r11)
testl %r9d, %r9d
je 0x10ff9
testw %r9w, %r9w
jle 0x10ffe
bsrl %r9d, %r9d
xorl $0xffe0, %r9d           # imm = 0xFFE0
addl $0x21, %r9d
jmp 0x1100f
xorl %r9d, %r9d
jmp 0x1100f
negl %r9d
bsrl %r9d, %r9d
notl %r9d
orl $0xffe0, %r9d           # imm = 0xFFE0
cmpq %rdx, %r13
movq %rbx, %r10
cmovaq %rsi, %r10
movw %r9w, (%r10)
incq %r8
addq %r12, %rdx
movq -0x38(%rsp), %r9
addq %r9, %rsi
addq %r12, %rax
addq %r9, %rdi
cmpq %r8, -0x40(%rsp)
jne 0x10fbe
jmp 0x11232
cmpl $0x2, %ecx
jl 0x11187
movq %rcx, -0x30(%rsp)
imull -0x7c(%rsp), %ecx
movq 0x20(%rsp), %rdx
movslq 0x18(%rdx), %rax
movq (%rdx), %rsi
movq 0x8(%rdx), %r9
movq %rsi, (%rsp)
subq %rsi, %r9
sarq %r9
leal 0x1(%r8), %edx
movslq %r8d, %rsi
movq %rsi, -0x8(%rsp)
movslq %edx, %rdx
movq %rdx, -0x10(%rsp)
movslq %ecx, %rcx
movl %edi, -0x6c(%rsp)
movl %edi, %edx
movq %rdx, 0x8(%rsp)
addq %rcx, %rcx
movq %r10, -0x28(%rsp)
addq (%r10), %rcx
movq %rcx, -0x18(%rsp)
leaq (%rax,%rax), %r11
movl -0x48(%rsp), %esi
negl %esi
xorl %edi, %edi
xorl %r14d, %r14d
movq %r12, 0x38(%rsp)
cmpl $0x0, -0x48(%rsp)
jle 0x11169
movq %rbx, %rdx
movq -0x18(%rsp), %rcx
movswl (%rcx,%rdi,2), %ebx
movl %ebx, %r10d
negw %r10w
cmovsw %bx, %r10w
movl %ebx, %ecx
negl %ecx
bsrl %ecx, %ebp
notl %ebp
orl $-0x20, %ebp
bsrl %ebx, %r8d
xorl $-0x20, %r8d
addl $0x21, %r8d
testl %ebx, %ebx
movq %r14, 0x10(%rsp)
movslq %r14d, %rcx
cmovlel %ebp, %r8d
cmovel %ebx, %r8d
imulq %rax, %rcx
movq -0x10(%rsp), %rbx
leaq (%rbx,%rcx), %rbp
movq (%rsp), %r14
leaq (%r14,%rbp,2), %rbx
addq -0x8(%rsp), %rcx
leaq (%r14,%rcx,2), %r14
xorl %r13d, %r13d
cmpq %rcx, %r9
movq %rdx, %r12
cmovaq %r14, %r12
cmpq %rbp, %r9
movq %rdx, %r15
cmovaq %rbx, %r15
movw %r10w, (%r12)
movw %r8w, (%r15)
addq %rax, %rbp
addq %r11, %rbx
addq %rax, %rcx
addq %r11, %r14
decl %r13d
cmpl %r13d, %esi
jne 0x1111e
movq 0x10(%rsp), %r14
subl %r13d, %r14d
movl -0x5c(%rsp), %r15d
movq 0x38(%rsp), %r12
movq -0x68(%rsp), %r13
movq %rdx, %rbx
incq %rdi
cmpq 0x8(%rsp), %rdi
jne 0x110b0
movq -0x28(%rsp), %r10
movq -0x30(%rsp), %rcx
movl -0x6c(%rsp), %edx
jmp 0x1118c
xorl %r14d, %r14d
xorl %edx, %edx
cmpl -0x40(%rsp), %r14d
jge 0x11232
movq (%r10), %rax
imull -0x7c(%rsp), %ecx
addl %edx, %ecx
movslq %ecx, %rcx
movswl (%rax,%rcx,2), %esi
movl %esi, %eax
negw %ax
cmovsw %si, %ax
movl %esi, %ecx
negl %ecx
bsrl %ecx, %edi
notl %edi
orl $-0x20, %edi
bsrl %esi, %ecx
xorl $-0x20, %ecx
addl $0x21, %ecx
testl %esi, %esi
movslq %r14d, %r10
movslq -0x50(%rsp), %r8
cmovlel %edi, %ecx
cmovel %esi, %ecx
movq %r12, %rdx
imulq %r10, %rdx
leaq (%rdx,%r8), %rsi
incq %rsi
addq %r8, %rdx
movq -0x58(%rsp), %r8
leaq (%r8,%rdx,2), %rdi
addq $0x2, %rdi
leaq (%r8,%rdx,2), %r8
movq -0x20(%rsp), %r9
subq %r10, %r9
cmpq %rdx, %r13
movq %rbx, %r10
cmovaq %r8, %r10
cmpq %rsi, %r13
movq %rbx, %r11
cmovaq %rdi, %r11
movw %ax, (%r10)
movw %cx, (%r11)
addq %r12, %rsi
movq -0x38(%rsp), %r10
addq %r10, %rdi
addq %r12, %rdx
addq %r10, %r8
decq %r9
jne 0x11200
movq -0x50(%rsp), %r8
addl $0x2, %r8d
movq 0x30(%rsp), %rax
movl 0x10(%rax), %eax
movq 0x28(%rsp), %rsi
movq 0x48(%rsp), %rdi
movq 0x40(%rsp), %r9
cmpq $0x2, %rdi
jl 0x11264
movq %r9, %rdi
cmpl %eax, %r8d
jl 0x10c7d
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq