// File: /workspace/github_cpp_makefile_star2_O1/cloudinary[P]fuif/transform/permute.h
// Function: fwd_permute(Image&, std::vector<int, std::allocator<int>>&)
bool fwd_permute(Image &input, std::vector<int> &parameters) {
    // TODO: implement this without copying stuff
    Image tmp = input;
    if (parameters.size() < 3) {
        e_printf("Invalid permutation: not enough parameters\n");
        return false;
    }
    bool use_channel = true;
    if (parameters[0] == -1) {
        parameters.erase(parameters.begin(), parameters.begin()+1);
        use_channel = false;
    }
    meta_permute(input, parameters, use_channel);
    if (!use_channel) return true;

    assert(input.channel[0].w == input.channel.size() - input.nb_meta_channels);
    if (parameters.size() != input.channel[0].w) {
        e_printf("Invalid permutation: need to specify %i new channels, gave only %i\n",input.channel[0].w,parameters.size());
        return false;
    }
    v_printf(5,"Permutation: ");
    for (int i=0; i<input.channel[0].w; i++) {
        input.channel[0].value(0,i) = parameters[i];
        int c = input.channel[0].value(0,i);
        if (c < 0 || c >= input.channel[0].w) {
            e_printf("Invalid permutation: %i is not a channel number\n",c);
            return false;
        }
        for (int j=0; j<i; j++) if (input.channel[0].value(0,i) == input.channel[0].value(0,j)) {
            e_printf("Invalid permutation: both %i and %i map to channel number %i\n",i,j,input.channel[0].value(0,i));
            return false;
        }
        input.channel[input.nb_meta_channels+c] = tmp.channel[tmp.nb_meta_channels+i];
        v_printf(5,"[%i -> %i] ",i,c);
    }
    v_printf(5,"\n");
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %r14
movq %rdi, %r15
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0xe196
leaq 0x20(%rsp), %r13
leaq 0x18(%r15), %rsi
movq %r13, %rdi
callq 0xe732
movups 0x30(%r15), %xmm0
leaq 0x48(%rsp), %rdi
movups %xmm0, -0x10(%rdi)
leaq 0x40(%r15), %rsi
callq 0x641c
movups 0x58(%r15), %xmm0
movups 0x64(%r15), %xmm1
leaq 0x80(%rsp), %rdi
movups %xmm1, -0x14(%rdi)
movups %xmm0, -0x20(%rdi)
leaq 0x78(%r15), %rsi
callq 0xe7bc
movups 0x90(%r15), %xmm0
movups 0x99(%r15), %xmm1
movups %xmm1, 0xa1(%rsp)
movups %xmm0, 0x98(%rsp)
movq (%r14), %r12
movq 0x8(%r14), %rdx
movq %rdx, %rax
subq %r12, %rax
cmpq $0x8, %rax
ja 0xd0b7
xorl %ebx, %ebx
leaq 0x18fd2(%rip), %rdi     # 0x2607d
xorl %eax, %eax
callq 0x3796
jmp 0xd26a
movl (%r12), %ebp
cmpl $-0x1, %ebp
jne 0xd0eb
leaq 0x4(%r12), %rbx
subq %rbx, %rdx
je 0xd0d5
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3510
movq 0x8(%r14), %rax
movq %rax, %rcx
subq %rbx, %rcx
addq %rcx, %r12
cmpq %r12, %rax
je 0xd0eb
movq %r12, 0x8(%r14)
xorl %edx, %edx
cmpl $-0x1, %ebp
setne %dl
movq %r15, %rdi
movq %r14, %rsi
callq 0xcdec
movb $0x1, %bl
cmpl $-0x1, %ebp
je 0xd26a
movq 0x8(%r14), %rdx
subq (%r14), %rdx
sarq $0x2, %rdx
movq (%r15), %rax
movslq 0x18(%rax), %rsi
cmpq %rsi, %rdx
jne 0xd23d
leaq 0x18e8d(%rip), %rsi     # 0x25fb8
movl $0x5, %edi
xorl %eax, %eax
callq 0x1d0d6
movq (%r15), %rax
movl 0x18(%rax), %edx
testl %edx, %edx
jle 0xd223
xorl %r12d, %r12d
movq (%r14), %rdi
movq (%rax), %rcx
movq 0x8(%rax), %rsi
subq %rcx, %rsi
sarq %rsi
addq $0x24, %rax
cmpq %r12, %rsi
leaq (%rcx,%r12,2), %r8
cmovbeq %rax, %r8
movl (%rdi,%r12,4), %edi
movw %di, (%r8)
movswl %di, %r13d
testw %r13w, %r13w
js 0xd2c4
cmpl %r13d, %edx
jle 0xd2c4
testq %r12, %r12
je 0xd1ad
xorl %edx, %edx
cmpq %rdx, %rsi
movq %rax, %r8
cmovaq %rcx, %r8
cmpw %di, (%r8)
je 0xd24f
incq %rdx
addq $0x2, %rcx
cmpq %rdx, %r12
jne 0xd18d
movslq 0x74(%rsp), %rax
movslq %r12d, %rbx
addq %rax, %rbx
shlq $0x6, %rbx
addq 0x8(%rsp), %rbx
movslq 0x6c(%r15), %rax
movslq %r13d, %rbp
addq %rax, %rbp
shlq $0x6, %rbp
addq (%r15), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
callq 0xe65e
movq 0x38(%rbx), %rax
movq %rax, 0x38(%rbp)
movups 0x18(%rbx), %xmm0
movups 0x28(%rbx), %xmm1
movups %xmm1, 0x28(%rbp)
movups %xmm0, 0x18(%rbp)
movl $0x5, %edi
leaq 0x18e3a(%rip), %rsi     # 0x2603b
movl %r12d, %edx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x1d0d6
incq %r12
movq (%r15), %rax
movslq 0x18(%rax), %rdx
cmpq %rdx, %r12
movb $0x1, %bl
jl 0xd148
leaq 0x1a75c(%rip), %rsi     # 0x27986
movl $0x5, %edi
xorl %eax, %eax
callq 0x1d0d6
leaq 0x20(%rsp), %r13
jmp 0xd26a
xorl %ebx, %ebx
leaq 0x18e63(%rip), %rdi     # 0x260a9
xorl %eax, %eax
callq 0x3796
jmp 0xd26a
xorl %ebx, %ebx
leaq 0x18ec6(%rip), %rdi     # 0x2611e
movl %r12d, %esi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x3796
leaq 0x20(%rsp), %r13
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0xd287
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0xd29e
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq %r13, %rdi
callq 0xe808
leaq 0x8(%rsp), %rdi
callq 0xe220
movl %ebx, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
leaq 0x18e20(%rip), %rdi     # 0x260ed
movl %r13d, %esi
xorl %eax, %eax
callq 0x3796
leaq 0x20(%rsp), %r13
jmp 0xd26a
jmp 0xd2e6
jmp 0xd2e6
jmp 0xd2e6
jmp 0xd2e6
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0xded8
jmp 0xd32b
movq %rax, %r14
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0xd314
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
jmp 0xd314
movq %rax, %r14
movq %r13, %rdi
callq 0xe808
jmp 0xd321
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0xe220
movq %r14, %rdi
callq 0x35a0