#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ input_frame;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ memcpy(float *, float *, int);
void PermuteWaveformChannels(const int *permutation, float *waveform,
                             int num_frames, int num_channels) {
  float input_frame[32];
  const int kMaxChannels = sizeof(input_frame) / sizeof(*input_frame);
  (void)kMaxChannels;
  assert(1 <= num_channels && num_channels <= kMaxChannels);
  int i;
  for (i = 0; i < num_frames; ++i, waveform += num_channels) {
    memcpy(input_frame, waveform, num_channels * sizeof(float));
    int c;
    for (c = 0; c < num_channels; ++c) {
      waveform[c] = input_frame[permutation[c]];
    }
  }
}


x86 assembly (clang, -O0):
<PermuteWaveformChannels>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x20,-0xa4(%rbp)
xor    %eax,%eax
mov    $0x1,%ecx
cmp    -0x18(%rbp),%ecx
mov    %al,-0xad(%rbp)
jg     1166 <PermuteWaveformChannels+0x46>
cmpl   $0x20,-0x18(%rbp)
setle  %al
mov    %al,-0xad(%rbp)
mov    -0xad(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movl   $0x0,-0xa8(%rbp)
mov    -0xa8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    122c <PermuteWaveformChannels+0x10c>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0xac(%rbp)
mov    -0xac(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11fe <PermuteWaveformChannels+0xde>
mov    -0x8(%rbp),%rax
movslq -0xac(%rbp),%rcx
movslq (%rax,%rcx,4),%rax
movss  -0xa0(%rbp,%rax,4),%xmm0
ff ff
mov    -0x10(%rbp),%rax
movslq -0xac(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0xac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xac(%rbp)
jmp    11b3 <PermuteWaveformChannels+0x93>
jmp    1203 <PermuteWaveformChannels+0xe3>
mov    -0xa8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa8(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1180 <PermuteWaveformChannels+0x60>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PermuteWaveformChannels>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %rcx,0x10(%rsp)
lea    -0x1(%rcx),%eax
xor    %edi,%edi
cmp    $0x20,%eax
setb   %dil
call   1030 <assert@plt>
mov    %r14d,0xc(%rsp)
test   %r14d,%r14d
jle    127d <PermuteWaveformChannels+0x15d>
mov    0x10(%rsp),%rax
movslq %eax,%r13
lea    0x0(,%rax,4),%ecx
mov    %ecx,0x8(%rsp)
mov    %eax,%r15d
lea    -0x1(%r15),%rax
mov    %rax,0x18(%rsp)
mov    %r15d,%r14d
and    $0x3,%r14d
and    $0xfffffffc,%r15d
shl    $0x2,%r13
xor    %r12d,%r12d
jmp    11b2 <PermuteWaveformChannels+0x92>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12d
add    %r13,%rbp
cmp    0xc(%rsp),%r12d
je     127d <PermuteWaveformChannels+0x15d>
lea    0x20(%rsp),%rdi
mov    %rbp,%rsi
mov    0x8(%rsp),%edx
call   1040 <memcpy@plt>
cmpl   $0x0,0x10(%rsp)
jle    11a0 <PermuteWaveformChannels+0x80>
cmpq   $0x3,0x18(%rsp)
jae    11e0 <PermuteWaveformChannels+0xc0>
xor    %eax,%eax
jmp    123c <PermuteWaveformChannels+0x11c>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq (%rbx,%rax,4),%rcx
movss  0x20(%rsp,%rcx,4),%xmm0
movss  %xmm0,0x0(%rbp,%rax,4)
movslq 0x4(%rbx,%rax,4),%rcx
movss  0x20(%rsp,%rcx,4),%xmm0
movss  %xmm0,0x4(%rbp,%rax,4)
movslq 0x8(%rbx,%rax,4),%rcx
movss  0x20(%rsp,%rcx,4),%xmm0
movss  %xmm0,0x8(%rbp,%rax,4)
movslq 0xc(%rbx,%rax,4),%rcx
movss  0x20(%rsp,%rcx,4),%xmm0
movss  %xmm0,0xc(%rbp,%rax,4)
add    $0x4,%rax
cmp    %rax,%r15
jne    11f0 <PermuteWaveformChannels+0xd0>
test   %r14,%r14
je     11a0 <PermuteWaveformChannels+0x80>
lea    0x0(,%rax,4),%rcx
add    %rbp,%rcx
lea    (%rbx,%rax,4),%rax
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
movslq (%rax,%rdx,4),%rsi
movss  0x20(%rsp,%rsi,4),%xmm0
movss  %xmm0,(%rcx,%rdx,4)
add    $0x1,%rdx
cmp    %rdx,%r14
jne    1260 <PermuteWaveformChannels+0x140>
jmp    11a0 <PermuteWaveformChannels+0x80>
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @PermuteWaveformChannels(i32* %0, float* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca float*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [32 x float]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %5
store float* %1, float** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 32, i32* %10
%13 = load i32, i32* %8
%14 = icmp sle i32 1, %13
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load i32, i32* %8
%17 = icmp sle i32 %16, 32
br label %18
18: ; preds = %15, %4
%19 = phi i1 [ false, %4 ], [ %17, %15 ]
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
store i32 0, i32* %11
br label %22
22: ; preds = %55, %18
%23 = load i32, i32* %11
%24 = load i32, i32* %7
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %62
26: ; preds = %22
%27 = getelementptr inbounds [32 x float], [32 x float]* %9, i64 0, i64 0
%28 = load float*, float** %6
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = mul i64 %30, 4
%32 = trunc i64 %31 to i32
%33 = call i32 @memcpy(float* %27, float* %28, i32 %32)
store i32 0, i32* %12
br label %34
34: ; preds = %51, %26
%35 = load i32, i32* %12
%36 = load i32, i32* %8
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %54
38: ; preds = %34
%39 = load i32*, i32** %5
%40 = load i32, i32* %12
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = load i32, i32* %42
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [32 x float], [32 x float]* %9, i64 0, i64 %44
%46 = load float, float* %45
%47 = load float*, float** %6
%48 = load i32, i32* %12
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds float, float* %47, i64 %49
store float %46, float* %50
br label %51
51: ; preds = %38
%52 = load i32, i32* %12
%53 = add nsw i32 %52, 1
store i32 %53, i32* %12
br label %34
54: ; preds = %34
br label %55
55: ; preds = %54
%56 = load i32, i32* %11
%57 = add nsw i32 %56, 1
store i32 %57, i32* %11
%58 = load i32, i32* %8
%59 = load float*, float** %6
%60 = sext i32 %58 to i64
%61 = getelementptr inbounds float, float* %59, i64 %60
store float* %61, float** %6
br label %22
62: ; preds = %22
ret void
}

LLVM IR (-O2):
define void @PermuteWaveformChannels(i32* nocapture %0, float* %1, i32 %2, i32 %3) {
%5 = alloca [32 x float]
%6 = bitcast [32 x float]* %5 to i8*
%7 = add i32 %3, -1
%8 = icmp ult i32 %7, 32
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = icmp sgt i32 %2, 0
br i1 %11, label %12, label %79
12: ; preds = %4
%13 = getelementptr inbounds [32 x float], [32 x float]* %5, i64 0, i64 0
%14 = sext i32 %3 to i64
%15 = shl i32 %3, 2
%16 = icmp sgt i32 %3, 0
%17 = zext i32 %3 to i64
%18 = add nsw i64 %17, -1
%19 = and i64 %17, 3
%20 = icmp ult i64 %18, 3
%21 = and i64 %17, 4294967292
%22 = icmp eq i64 %19, 0
br label %23
23: ; preds = %12, %75
%24 = phi i32 [ 0, %12 ], [ %76, %75 ]
%25 = phi float* [ %1, %12 ], [ %77, %75 ]
%26 = call i32 @memcpy(float* %13, float* %25, i32 %15)
br i1 %16, label %27, label %75
27: ; preds = %23
br i1 %20, label %61, label %28
28: ; preds = %27, %28
%29 = phi i64 [ %58, %28 ], [ 0, %27 ]
%30 = phi i64 [ %59, %28 ], [ 0, %27 ]
%31 = getelementptr inbounds i32, i32* %0, i64 %29
%32 = load i32, i32* %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [32 x float], [32 x float]* %5, i64 0, i64 %33
%35 = load float, float* %34
%36 = getelementptr inbounds float, float* %25, i64 %29
store float %35, float* %36
%37 = or i64 %29, 1
%38 = getelementptr inbounds i32, i32* %0, i64 %37
%39 = load i32, i32* %38
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [32 x float], [32 x float]* %5, i64 0, i64 %40
%42 = load float, float* %41
%43 = getelementptr inbounds float, float* %25, i64 %37
store float %42, float* %43
%44 = or i64 %29, 2
%45 = getelementptr inbounds i32, i32* %0, i64 %44
%46 = load i32, i32* %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [32 x float], [32 x float]* %5, i64 0, i64 %47
%49 = load float, float* %48
%50 = getelementptr inbounds float, float* %25, i64 %44
store float %49, float* %50
%51 = or i64 %29, 3
%52 = getelementptr inbounds i32, i32* %0, i64 %51
%53 = load i32, i32* %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [32 x float], [32 x float]* %5, i64 0, i64 %54
%56 = load float, float* %55
%57 = getelementptr inbounds float, float* %25, i64 %51
store float %56, float* %57
%58 = add nuw nsw i64 %29, 4
%59 = add i64 %30, 4
%60 = icmp eq i64 %59, %21
br i1 %60, label %61, label %28
61: ; preds = %28, %27
%62 = phi i64 [ 0, %27 ], [ %58, %28 ]
br i1 %22, label %75, label %63
63: ; preds = %61, %63
%64 = phi i64 [ %72, %63 ], [ %62, %61 ]
%65 = phi i64 [ %73, %63 ], [ 0, %61 ]
%66 = getelementptr inbounds i32, i32* %0, i64 %64
%67 = load i32, i32* %66
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [32 x float], [32 x float]* %5, i64 0, i64 %68
%70 = load float, float* %69
%71 = getelementptr inbounds float, float* %25, i64 %64
store float %70, float* %71
%72 = add nuw nsw i64 %64, 1
%73 = add i64 %65, 1
%74 = icmp eq i64 %73, %19
br i1 %74, label %75, label %63
75: ; preds = %61, %63, %23
%76 = add nuw nsw i32 %24, 1
%77 = getelementptr inbounds float, float* %25, i64 %14
%78 = icmp eq i32 %76, %2
br i1 %78, label %79, label %23
79: ; preds = %75, %4
ret void
}