// File: /workspace/github_cpp_makefile_star2_O2/cloudinary[P]fuif/encoding/context_predict.h
// Function: init_properties(std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>&, Image const&, int, int, fuif_options&)
void init_properties(Ranges &pr, const Image &image, int beginc, int endc, fuif_options &options) {
    int offset=0;
//    for (int j=beginc-1; j>=image.nb_meta_channels && offset < options.max_properties; j--) {
    for (int j=beginc-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 minval = image.channel[j].minval;
        if (minval > 0) minval = 0;
        int maxval = image.channel[j].maxval;
        if (maxval < 0) maxval = 0;
        pr.push_back(std::pair<PropertyVal,PropertyVal>(0,fooabs((maxval > -minval ? maxval : minval))));
        offset++;
        pr.push_back(std::pair<PropertyVal,PropertyVal>(slog(minval),slog(maxval)));
        offset++;
//        pr.push_back(std::pair<PropertyVal,PropertyVal>(slog(minval-maxval),slog(maxval-minval)));
//        offset++;
    }

    pixel_type minval = LARGEST_VAL;
    pixel_type maxval = SMALLEST_VAL;
    int maxh = 0;
    int maxw = 0;
    for (int j=beginc; j<=endc; j++) {
        if (image.channel[j].minval < minval) minval = image.channel[j].minval;
        if (image.channel[j].maxval > maxval) maxval = image.channel[j].maxval;
        if (image.channel[j].h > maxh) maxh = image.channel[j].h;
        if (image.channel[j].w > maxw) maxw = image.channel[j].w;
    }
    if (minval > 0) minval = 0;
    if (maxval < 0) maxval = 0;

//    printf("range = %i..%i\n",minval,maxval);
    // neighbors
    pr.push_back(std::pair<PropertyVal,PropertyVal>(0,MAX(fooabs(minval),fooabs(maxval))));
    pr.push_back(std::pair<PropertyVal,PropertyVal>(0,MAX(fooabs(minval),fooabs(maxval))));
    pr.push_back(std::pair<PropertyVal,PropertyVal>(slog(minval),slog(maxval)));
    pr.push_back(std::pair<PropertyVal,PropertyVal>(slog(minval),slog(maxval)));

    // location
    pr.push_back(std::pair<PropertyVal,PropertyVal>(0,maxh-1));
    pr.push_back(std::pair<PropertyVal,PropertyVal>(0,maxw-1));

    // blah
    pr.push_back(std::pair<PropertyVal,PropertyVal>(minval+minval-maxval,maxval+maxval-minval));
    pr.push_back(std::pair<PropertyVal,PropertyVal>(minval+minval-maxval,maxval+maxval-minval));

    // FFV1
    pr.push_back(std::pair<PropertyVal,PropertyVal>(slog(minval-maxval),slog(maxval-minval)));
    pr.push_back(std::pair<PropertyVal,PropertyVal>(slog(minval-maxval),slog(maxval-minval)));
    pr.push_back(std::pair<PropertyVal,PropertyVal>(slog(minval-maxval),slog(maxval-minval)));
    pr.push_back(std::pair<PropertyVal,PropertyVal>(slog(minval-maxval),slog(maxval-minval)));
    pr.push_back(std::pair<PropertyVal,PropertyVal>(slog(minval-maxval),slog(maxval-minval)));

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %r15d
movq %rsi, %r12
movl %edx, %ebx
xorl %ebp, %ebp
leaq 0x4(%rsp), %r13
xorl %r14d, %r14d
movl 0x10(%r8), %eax
movq (%r12), %rdx
movl %ebx, %r10d
leaq -0x1(%rbx), %r9
shlq $0x6, %rbx
leaq (%rdx,%rbx), %rsi
addq $-0x20, %rsi
movq %r9, %rbx
testl %r10d, %r10d
jle 0xc5e7
cmpl %eax, %r14d
jge 0xc5e7
movzwl (%rsi), %r11d
movzwl 0x2(%rsi), %r9d
cmpw %r9w, %r11w
je 0xc52f
cmpl $0x0, 0xc(%rsi)
jns 0xc53b
decl %r10d
decq %rbx
addq $-0x40, %rsi
jmp 0xc508
testw %r11w, %r11w
movl $0x0, %eax
cmovsl %r11d, %eax
testw %r9w, %r9w
cmovlel %ebp, %r9d
movl %r15d, 0x10(%rsp)
movq %r13, %r15
movswl %ax, %r13d
movzwl %r9w, %ebp
movl %r13d, %edx
negl %edx
cmpl %edx, %ebp
cmovbel %eax, %r9d
movl %r9d, %eax
negw %ax
cmovsw %r9w, %ax
andl $0x0, 0x4(%rsp)
cwtl
movl %eax, 0x8(%rsp)
movq %r15, %rsi
movq %r12, 0x18(%rsp)
movq %rdi, %r12
movl %ecx, 0xc(%rsp)
movq %r8, 0x20(%rsp)
callq 0x1281c
movl %r13d, %edi
callq 0x43c8
movl %eax, %r13d
movl %ebp, %edi
xorl %ebp, %ebp
callq 0x43c8
movswl %r13w, %ecx
movq %r15, %r13
movl 0x10(%rsp), %r15d
movl %ecx, 0x4(%rsp)
cwtl
movl %eax, 0x8(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x1281c
movq 0x20(%rsp), %r8
movl 0xc(%rsp), %ecx
movq %r12, %rdi
movq 0x18(%rsp), %r12
addl $0x2, %r14d
jmp 0xc4ea
movslq %r15d, %rax
movslq %ecx, %rcx
movq %rax, %rsi
shlq $0x6, %rsi
addq %rsi, %rdx
addq $0x22, %rdx
xorl %r15d, %r15d
movw $0x8001, %r13w          # imm = 0x8001
movw $0x7fff, %si            # imm = 0x7FFF
xorl %ebx, %ebx
cmpq %rcx, %rax
jg 0xc647
movl -0x2(%rdx), %r9d
cmpw %si, %r9w
cmovgel %esi, %r9d
movzwl (%rdx), %r8d
cmpw %r13w, %r8w
cmovlel %r13d, %r8d
movl -0x6(%rdx), %esi
cmpl %r15d, %esi
cmovgl %esi, %r15d
movl -0xa(%rdx), %esi
cmpl %ebx, %esi
cmovgl %esi, %ebx
incq %rax
addq $0x40, %rdx
movl %r9d, %esi
movl %r8d, %r13d
jmp 0xc609
xorl %eax, %eax
testw %si, %si
movl $0x0, %r12d
cmovsl %esi, %r12d
movl %r12d, 0xc(%rsp)
testw %r13w, %r13w
cmovlel %eax, %r13d
negl %r12d
cmpw %r12w, %r13w
cmovgl %r13d, %r12d
leaq 0x4(%rsp), %r14
andl $0x0, (%r14)
movl $0xffff, %ebp           # imm = 0xFFFF
andl %ebp, %r12d
movl %r12d, 0x4(%r14)
movq %r14, %rsi
movq %rdi, 0x10(%rsp)
callq 0x1281c
andl $0x0, (%r14)
movl %r12d, 0x4(%r14)
leaq 0x4(%rsp), %rsi
movq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x1281c
movswl 0xc(%rsp), %r12d
movl %r12d, %edi
movq %r12, 0x20(%rsp)
callq 0x43c8
movw %ax, 0x18(%rsp)
andl %r13d, %ebp
movl %ebp, %edi
callq 0x43c8
movswl 0x18(%rsp), %ecx
leaq 0x4(%rsp), %rdx
movl %ecx, (%rdx)
cwtl
movl %eax, 0x4(%rdx)
leaq 0x4(%rsp), %rsi
movq %r14, %rdi
callq 0x1281c
movl %r12d, %edi
callq 0x43c8
movl %eax, %r12d
movl %ebp, %edi
callq 0x43c8
movswl %r12w, %ecx
leaq 0x4(%rsp), %rdx
movl %ecx, (%rdx)
cwtl
movl %eax, 0x4(%rdx)
leaq 0x4(%rsp), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x1281c
decl %r15d
andl $0x0, (%r12)
movl %r15d, 0x4(%r12)
leaq 0x4(%rsp), %r15
movq %r14, %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x1281c
decl %ebx
andl $0x0, (%r15)
movl %ebx, 0x4(%r15)
leaq 0x4(%rsp), %r14
movq %r12, %rdi
movq %r12, %r15
movq %r14, %rsi
callq 0x1281c
movq 0x20(%rsp), %rax
leal (%rax,%rax), %ebx
subl %ebp, %ebx
addl %ebp, %ebp
subl %eax, %ebp
movl %ebx, (%r14)
movl %ebp, 0x4(%r14)
leaq 0x4(%rsp), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x1281c
movl %ebx, (%r14)
movl %ebp, 0x4(%r14)
leaq 0x4(%rsp), %rsi
movq %r12, %rdi
callq 0x1281c
movl 0xc(%rsp), %ebx
movl %ebx, %eax
subl %r13d, %eax
movswl %ax, %ebp
movl %ebp, %edi
callq 0x43c8
movl %eax, %r12d
subl %ebx, %r13d
movswl %r13w, %r14d
movl %r14d, %edi
callq 0x43c8
movswl %r12w, %ecx
leaq 0x4(%rsp), %rdx
movl %ecx, (%rdx)
cwtl
movl %eax, 0x4(%rdx)
leaq 0x4(%rsp), %r13
movq %r15, %rbx
movq %r15, %rdi
movq %r13, %rsi
callq 0x1281c
movl %ebp, %edi
callq 0x43c8
movl %eax, %r12d
movl %r14d, %edi
callq 0x43c8
movswl %r12w, %ecx
movl %ecx, (%r13)
cwtl
movl %eax, 0x4(%r13)
leaq 0x4(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1281c
movl %ebp, %edi
callq 0x43c8
movl %eax, %r12d
movl %r14d, %edi
callq 0x43c8
movswl %r12w, %ecx
movl %ecx, (%r15)
cwtl
movl %eax, 0x4(%r15)
leaq 0x4(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1281c
movl %ebp, %edi
callq 0x43c8
movl %eax, %r12d
movl %r14d, %edi
callq 0x43c8
movswl %r12w, %ecx
movl %ecx, (%r15)
cwtl
movl %eax, 0x4(%r15)
leaq 0x4(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1281c
movl %ebp, %edi
callq 0x43c8
movl %eax, %ebp
movl %r14d, %edi
callq 0x43c8
movswl %bp, %ecx
movl %ecx, (%r15)
cwtl
movl %eax, 0x4(%r15)
leaq 0x4(%rsp), %rsi
movq %rbx, %rdi
callq 0x1281c
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq