// File: cloudinary[P]fuif/transform/palette.h
// Function: meta_palette(Image&, std::vector<int, std::allocator<int>>)
void meta_palette(Image &input, std::vector<int> parameters) {
    if (parameters.size() != 3) {
        e_printf("Error: Palette transform with incorrect parameters.\n");
        input.error = true; return;
    }
    int begin_c = input.nb_meta_channels+parameters[0];
    int end_c = input.nb_meta_channels+parameters[1];
    if (begin_c > end_c || end_c >= input.channel.size()) {
        e_printf("Error: Palette transform with incorrect parameters.\n");
        input.error = true; return;
    }
    int nb = end_c - begin_c + 1;
    int &nb_colors = parameters[2];
    input.nb_meta_channels++;
    input.nb_channels -= nb-1;
    input.channel.erase(input.channel.begin()+begin_c+1,input.channel.begin()+end_c+1);
    Channel pch(nb_colors,nb, 0, 1);
    pch.hshift = -1;
    input.channel.insert(input.channel.begin(),pch);
}

// Assembly:
subq $0x148, %rsp            # imm = 0x148
movq %rsi, 0x60(%rsp)
movq %rdi, %rax
movq 0x60(%rsp), %rdi
movq %rdi, 0x68(%rsp)
movq %rax, 0x140(%rsp)
movq %rdi, 0x138(%rsp)
callq 0x4d50
cmpq $0x3, %rax
je 0xa996
leaq 0x3c0cc(%rip), %rdi     # 0x46a47
movb $0x0, %al
callq 0x3a670
movq 0x140(%rsp), %rax
movb $0x1, 0xa8(%rax)
jmp 0xac4c
movq 0x68(%rsp), %rdi
movq 0x140(%rsp), %rax
movl 0x6c(%rax), %eax
movl %eax, 0x58(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x12190
movq 0x68(%rsp), %rdi
movq %rax, %rcx
movl 0x58(%rsp), %eax
addl (%rcx), %eax
movl %eax, 0x134(%rsp)
movq 0x140(%rsp), %rax
movl 0x6c(%rax), %eax
movl %eax, 0x5c(%rsp)
movl $0x1, %esi
callq 0x12190
movq %rax, %rcx
movl 0x5c(%rsp), %eax
addl (%rcx), %eax
movl %eax, 0x130(%rsp)
movl 0x134(%rsp), %eax
cmpl 0x130(%rsp), %eax
jg 0xaa28
movslq 0x130(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x140(%rsp), %rdi
callq 0x4b80
movq %rax, %rcx
movq 0x50(%rsp), %rax
cmpq %rcx, %rax
jb 0xaa4a
leaq 0x3c018(%rip), %rdi     # 0x46a47
movb $0x0, %al
callq 0x3a670
movq 0x140(%rsp), %rax
movb $0x1, 0xa8(%rax)
jmp 0xac4c
movq 0x68(%rsp), %rdi
movl 0x130(%rsp), %eax
movl 0x134(%rsp), %ecx
subl %ecx, %eax
incl %eax
movl %eax, 0x12c(%rsp)
movl $0x2, %esi
callq 0x12190
movq %rax, 0x120(%rsp)
movq 0x140(%rsp), %rax
movl 0x6c(%rax), %ecx
incl %ecx
movl %ecx, 0x6c(%rax)
movl 0x12c(%rsp), %edx
movq 0x140(%rsp), %rax
movl 0x64(%rax), %ecx
subl %edx, %ecx
incl %ecx
movl %ecx, 0x64(%rax)
movq 0x140(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x127d0
movq %rax, 0x100(%rsp)
movslq 0x134(%rsp), %rsi
leaq 0x100(%rsp), %rdi
callq 0x12800
movq %rax, 0x108(%rsp)
leaq 0x108(%rsp), %rdi
movl $0x1, %esi
movq %rsi, 0x28(%rsp)
callq 0x12800
movq %rax, 0x110(%rsp)
leaq 0x118(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x12840
movq 0x140(%rsp), %rdi
callq 0x127d0
movq %rax, 0xe0(%rsp)
movslq 0x130(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
callq 0x12800
movq 0x28(%rsp), %rsi
movq %rax, 0xe8(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x12800
movq %rax, 0xf0(%rsp)
leaq 0xf8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x12840
movq 0x30(%rsp), %rdi
movq 0x118(%rsp), %rsi
movq 0xf8(%rsp), %rdx
callq 0x12730
movq %rax, 0xd8(%rsp)
movq 0x120(%rsp), %rax
movl (%rax), %esi
movl 0x12c(%rsp), %edx
movq %rsp, %rax
movl $0x0, 0x18(%rax)
movl $0x0, 0x10(%rax)
movl $0x0, 0x8(%rax)
movl $0x0, (%rax)
leaq 0x98(%rsp), %rdi
movq %rdi, 0x40(%rsp)
xorl %ecx, %ecx
movl $0x1, %r9d
movl %r9d, %r8d
callq 0x12200
movl $0xffffffff, 0xc4(%rsp) # imm = 0xFFFFFFFF
movq 0x140(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x127d0
movq %rax, 0x88(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x12840
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rdx
movq 0x90(%rsp), %rsi
callq 0x12c20
movq %rax, 0x48(%rsp)
jmp 0xac35
movq 0x48(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x12380
addq $0x148, %rsp            # imm = 0x148
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x12380
movq 0x80(%rsp), %rdi
callq 0x36a0
nop