// File: cloudinary[P]fuif/transform/permute.h
// Function: meta_permute(Image&, std::vector<int, std::allocator<int>>&, bool)
void meta_permute(Image &input, std::vector<int> &parameters, bool use_channel=false) {
    int nb = input.channel.size() - input.nb_meta_channels;
    if (parameters.size() == 0 || use_channel) {
      input.nb_meta_channels++;
      Channel pch(nb, 1, 0, nb-1);
      pch.hshift = -1;
      input.channel.insert(input.channel.begin(),pch);
    } else if (parameters.size() <= nb) {
      std::vector<Channel> inchannel = input.channel;
      for (int i=0; i<parameters.size(); i++) {
        int c = parameters[i];
        if (c < 0 || c >= parameters.size()) {
            e_printf("Invalid permutation: channel %i is lost\n",c);
            input.error=true;
            return;
        }
        for (int j=0; j<i; j++) if (parameters[i] == parameters[j]) {
            e_printf("Invalid permutation: both %i and %i map from channel number %i\n",i,j,parameters[i]);
            input.error=true;
            return;
        }
        input.channel[input.nb_meta_channels+c] = inchannel[input.nb_meta_channels+i];
        v_printf(5,"[%i -> %i] ",i,c);
      }
    } else {
        e_printf("Incorrect number of parameters in Permute transform.\n");
        input.error=true;
    }
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movb %dl, %al
movq %rdi, 0x100(%rsp)
movq %rsi, 0xf8(%rsp)
andb $0x1, %al
movb %al, 0xf7(%rsp)
movq 0x100(%rsp), %rdi
callq 0x4b80
movq 0x100(%rsp), %rcx
movslq 0x6c(%rcx), %rcx
subq %rcx, %rax
movl %eax, 0xf0(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x4d50
cmpq $0x0, %rax
je 0x10a96
testb $0x1, 0xf7(%rsp)
je 0x10b8d
movq 0x100(%rsp), %rax
movl 0x6c(%rax), %ecx
incl %ecx
movl %ecx, 0x6c(%rax)
movl 0xf0(%rsp), %esi
movl %esi, %eax
decl %eax
movq %rsp, %rcx
movl $0x0, 0x18(%rcx)
movl $0x0, 0x10(%rcx)
movl $0x0, 0x8(%rcx)
movl $0x0, (%rcx)
movswl %ax, %r8d
leaq 0xb0(%rsp), %rdi
movq %rdi, 0x50(%rsp)
xorl %ecx, %ecx
movl $0x1, %r9d
movl %r9d, %edx
callq 0x12200
movl $0xffffffff, 0xdc(%rsp) # imm = 0xFFFFFFFF
movq 0x100(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x127d0
movq %rax, 0xa0(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x12840
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rdx
movq 0xa8(%rsp), %rsi
callq 0x12c20
movq %rax, 0x58(%rsp)
jmp 0x10b48
movq 0x58(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x12380
jmp 0x10def
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x12380
jmp 0x10df7
movq 0xf8(%rsp), %rdi
callq 0x4d50
movslq 0xf0(%rsp), %rcx
cmpq %rcx, %rax
ja 0x10dd0
movq 0x100(%rsp), %rsi
leaq 0x70(%rsp), %rdi
callq 0x13580
movl $0x0, 0x6c(%rsp)
movslq 0x6c(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x4d50
movq %rax, %rcx
movq 0x40(%rsp), %rax
cmpq %rcx, %rax
jae 0x10db0
movq 0xf8(%rsp), %rdi
movslq 0x6c(%rsp), %rsi
callq 0x12190
movl (%rax), %eax
movl %eax, 0x68(%rsp)
cmpl $0x0, 0x68(%rsp)
jl 0x10c30
movslq 0x68(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x4d50
movq %rax, %rcx
movq 0x38(%rsp), %rax
cmpq %rcx, %rax
jb 0x10c83
movl 0x68(%rsp), %esi
leaq 0x362c7(%rip), %rdi     # 0x46f02
xorl %eax, %eax
callq 0x3a670
jmp 0x10c44
movq 0x100(%rsp), %rax
movb $0x1, 0xa8(%rax)
movl $0x1, 0x64(%rsp)
jmp 0x10db8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x13680
jmp 0x10df7
movl $0x0, 0x60(%rsp)
movl 0x60(%rsp), %eax
cmpl 0x6c(%rsp), %eax
jge 0x10d36
movq 0xf8(%rsp), %rdi
movslq 0x6c(%rsp), %rsi
callq 0x12190
movl (%rax), %eax
movl %eax, 0x34(%rsp)
movq 0xf8(%rsp), %rdi
movslq 0x60(%rsp), %rsi
callq 0x12190
movq %rax, %rcx
movl 0x34(%rsp), %eax
cmpl (%rcx), %eax
jne 0x10d24
movl 0x6c(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x60(%rsp), %ecx
movl %ecx, 0x30(%rsp)
movq 0xf8(%rsp), %rdi
movslq %eax, %rsi
callq 0x12190
movl 0x2c(%rsp), %esi
movl 0x30(%rsp), %edx
movl (%rax), %ecx
leaq 0x3622c(%rip), %rdi     # 0x46f2b
xorl %eax, %eax
callq 0x3a670
jmp 0x10d08
movq 0x100(%rsp), %rax
movb $0x1, 0xa8(%rax)
movl $0x1, 0x64(%rsp)
jmp 0x10db8
jmp 0x10d26
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0x10c8b
movq 0x100(%rsp), %rax
movl 0x6c(%rax), %eax
movl 0x6c(%rsp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
leaq 0x70(%rsp), %rdi
callq 0x4ba0
movq %rax, 0x20(%rsp)
movq 0x100(%rsp), %rdi
movl 0x6c(%rdi), %eax
movl 0x68(%rsp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0x4ba0
movq 0x20(%rsp), %rsi
movq %rax, %rdi
callq 0x12390
jmp 0x10d81
movl 0x6c(%rsp), %edx
movl 0x68(%rsp), %ecx
leaq 0x361db(%rip), %rsi     # 0x46f6b
xorl %eax, %eax
movl $0x5, %edi
callq 0x3a770
jmp 0x10d9e
jmp 0x10da0
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x10bc5
movl $0x0, 0x64(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x13680
movl 0x64(%rsp), %eax
testl %eax, %eax
je 0x10dce
jmp 0x10dcc
jmp 0x10def
jmp 0x10ded
leaq 0x361a0(%rip), %rdi     # 0x46f77
movb $0x0, %al
callq 0x3a670
movq 0x100(%rsp), %rax
movb $0x1, 0xa8(%rax)
jmp 0x10def
addq $0x108, %rsp            # imm = 0x108
retq
movq 0x98(%rsp), %rdi
callq 0x36a0
nopw %cs:(%rax,%rax)