// File: /workspace/github_cpp_makefile_star2_O1/cloudinary[P]fuif/transform/palette.h
// Function: inv_palette(Image&, std::vector<int, std::allocator<int>>)
bool inv_palette(Image &input, std::vector<int> parameters) {
    if (input.nb_meta_channels < 1) {
        e_printf("Error: Palette transform without palette.\n");
        return false;
    }
    if (parameters.size() != 3) {
        e_printf("Error: Palette transform with incorrect parameters.\n");
        return false;
    }
    int nb = input.channel[0].h;
    int c0 = input.nb_meta_channels + parameters[0];
    if (c0 >= input.channel.size()) {
        e_printf("Error: Palette transform with incorrect parameters.\n");
        return false;
    }
    int w = input.channel[c0].w;
    int h = input.channel[c0].h;
    // might be false in case of lossy
    //assert(input.channel[c0].minval == 0);
    //assert(input.channel[c0].maxval == palette.w-1);
    for (int i=1; i<nb; i++) {
        input.channel.insert(input.channel.begin()+c0+1, Channel(w,h,0,1));
        input.channel[c0+i].component = parameters[0]+i;
    }
    const Channel &palette = input.channel[0];
    for (int y=0; y<h; y++) {
        for (int x=0; x<w; x++) {
            int index = CLAMP(input.channel[c0].value(y,x),0,palette.w-1);
            for (int c=0; c<nb; c++)
                input.channel[c0+c].value(y,x) = palette.value(c,index);
        }
    }
    input.nb_channels += nb-1;
    input.nb_meta_channels--;
    input.channel.erase(input.channel.begin(),input.channel.begin()+1);
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movslq 0x6c(%rdi), %rcx
testq %rcx, %rcx
jle 0x9357
movq %rsi, %rbx
movq (%rsi), %rdx
movq 0x8(%rsi), %rax
subq %rdx, %rax
cmpq $0xc, %rax
jne 0x934e
movq %rdi, %rbp
movq (%rdi), %rax
movq 0x8(%rdi), %rsi
movslq (%rdx), %rdx
addq %rcx, %rdx
subq %rax, %rsi
sarq $0x6, %rsi
cmpq %rdx, %rsi
jbe 0x934e
movl 0x1c(%rax), %ecx
movq %rdx, %rsi
movq %rdx, 0x28(%rsp)
shlq $0x6, %rsi
movl 0x18(%rax,%rsi), %edx
movq %rdx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movl 0x1c(%rax,%rsi), %eax
movl %eax, (%rsp)
movq %rcx, 0x18(%rsp)
cmpl $0x2, %ecx
jl 0x91d7
movl (%rsp), %eax
imull 0x10(%rsp), %eax
cltq
movq %rax, 0x30(%rsp)
movq 0x8(%rsp), %rax
leaq 0x7c(%rax), %r12
movl $0x1, %r14d
movq (%rbp), %rax
movq 0x8(%rsp), %rcx
leaq (%rax,%rcx), %r13
addq $0x40, %r13
xorl %eax, %eax
movw %ax, 0x4(%rsp)
leaq 0x58(%rsp), %r15
movq %r15, %rdi
movq 0x30(%rsp), %rsi
leaq 0x4(%rsp), %rdx
leaq 0x7(%rsp), %rcx
callq 0xe312
movq 0x10(%rsp), %rax
movl %eax, 0x70(%rsp)
movl (%rsp), %eax
movl %eax, 0x74(%rsp)
movl $0x10000, 0x78(%rsp)    # imm = 0x10000
movl $0x1, 0x80(%rsp)
leaq 0x84(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movl $0xffffffff, 0x94(%rsp) # imm = 0xFFFFFFFF
xorl %eax, %eax
movw %ax, 0x7c(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0xfee4
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x91b5
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq (%rbx), %rax
movl (%rax), %eax
addl %r14d, %eax
movq (%rbp), %rcx
movl %eax, (%rcx,%r12)
incq %r14
addq $0x40, %r12
cmpq %r14, 0x18(%rsp)
jne 0x9119
movq %rbp, 0x38(%rsp)
movq (%rbp), %rsi
cmpl $0x0, (%rsp)
jle 0x932a
movq 0x8(%rsp), %rbp
leaq (%rsi,%rbp), %rax
movq %rax, 0x40(%rsp)
leaq (%rsi,%rbp), %rax
addq $0x24, %rax
movq %rax, 0x50(%rsp)
leaq 0x24(%rsi), %r15
movslq 0x28(%rsp), %rax
shlq $0x6, %rax
addq %rsi, %rax
addq $0x24, %rax
movq %rax, 0x48(%rsp)
movq $0x0, 0x20(%rsp)
cmpl $0x0, 0x10(%rsp)
jle 0x9315
movq 0x40(%rsp), %rax
movslq 0x18(%rax), %rcx
movslq 0x20(%rsp), %r10
imulq %r10, %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rcx
movq 0x8(%rax), %rax
movq %rcx, 0x30(%rsp)
subq %rcx, %rax
sarq %rax
movq %rax, 0x28(%rsp)
xorl %r12d, %r12d
movq 0x8(%rsp), %rax
addq %r12, %rax
cmpq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax,2), %rax
cmovbeq 0x50(%rsp), %rax
movswl (%rax), %eax
testl %eax, %eax
js 0x9296
movl 0x18(%rsi), %ecx
leal -0x1(%rcx), %edi
cmpl %eax, %ecx
cmovgl %eax, %edi
movslq %edi, %r13
jmp 0x9299
xorl %r13d, %r13d
cmpl $0x0, 0x18(%rsp)
jle 0x9307
movslq 0x18(%rsi), %rbx
movq (%rsi), %rcx
movq 0x8(%rsi), %rax
subq %rcx, %rax
sarq %rax
leaq (%rcx,%r13,2), %r8
leaq (%rbx,%rbx), %rdi
movq 0x18(%rsp), %rbp
movq 0x48(%rsp), %rcx
cmpq %r13, %rax
movq %r15, %rdx
cmovaq %r8, %rdx
movzwl (%rdx), %edx
movslq -0xc(%rcx), %r9
imulq %r10, %r9
addq %r12, %r9
movq -0x24(%rcx), %r11
movq -0x1c(%rcx), %r14
subq %r11, %r14
sarq %r14
cmpq %r9, %r14
leaq (%r11,%r9,2), %r9
cmovbeq %rcx, %r9
movw %dx, (%r9)
addq $0x40, %rcx
addq %rbx, %r13
addq %rdi, %r8
decq %rbp
jne 0x92c3
incq %r12
cmpq 0x10(%rsp), %r12
jne 0x9263
movq 0x20(%rsp), %rax
incl %eax
movq %rax, 0x20(%rsp)
cmpl (%rsp), %eax
jne 0x9227
movq 0x38(%rsp), %rdi
movl 0x64(%rdi), %eax
movq 0x18(%rsp), %rcx
addl %ecx, %eax
decl %eax
movl %eax, 0x64(%rdi)
decl 0x6c(%rdi)
leaq 0x40(%rsi), %rdx
callq 0xfd3a
movb $0x1, %bl
jmp 0x9367
leaq 0x1c7c2(%rip), %rdi     # 0x25b17
jmp 0x935e
leaq 0x1c78e(%rip), %rdi     # 0x25aec
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x3796
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x9395
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0x35a0