#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 */

/* Variables and functions */
int bitrev(int, int);
int log_2(int);
void permute_bitrev(int n, double *A_re, double *A_im) {
  int i, bri, log2n;
  double t_re, t_im;
  log2n = log_2(n);
  for (i = 0; i < n; i++) {
    bri = bitrev(i, log2n);
    if (bri <= i)
      continue;
    t_re = A_re[i];
    t_im = A_im[i];
    A_re[i] = A_re[bri];
    A_im[i] = A_im[bri];
    A_re[bri] = t_re;
    A_im[bri] = t_im;
  }
}


x86 assembly (clang, -O0):
<permute_bitrev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <log_2@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11fa <permute_bitrev+0xda>
mov    -0x1c(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1040 <bitrev@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     1170 <permute_bitrev+0x50>
jmp    11ec <permute_bitrev+0xcc>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x38(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1145 <permute_bitrev+0x25>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permute_bitrev>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
call   1030 <log_2@plt>
test   %ebp,%ebp
jle    1198 <permute_bitrev+0x78>
mov    %eax,%r15d
mov    %ebp,%r12d
xor    %ebp,%ebp
jmp    1159 <permute_bitrev+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbp
cmp    %rbp,%r12
je     1198 <permute_bitrev+0x78>
mov    %ebp,%edi
mov    %r15d,%esi
call   1040 <bitrev@plt>
cltq
cmp    %rax,%rbp
jge    1150 <permute_bitrev+0x30>
movsd  (%rbx,%rbp,8),%xmm0
movsd  (%r14,%rbp,8),%xmm1
movsd  (%rbx,%rax,8),%xmm2
movsd  %xmm2,(%rbx,%rbp,8)
movsd  (%r14,%rax,8),%xmm2
movsd  %xmm2,(%r14,%rbp,8)
movsd  %xmm0,(%rbx,%rax,8)
movsd  %xmm1,(%r14,%rax,8)
jmp    1150 <permute_bitrev+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @permute_bitrev(i32 %0, double* nocapture %1, double* nocapture %2) {
%4 = tail call i32 @log_2(i32 %0)
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %26
6: ; preds = %3
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %23
%9 = phi i64 [ 0, %6 ], [ %24, %23 ]
%10 = trunc i64 %9 to i32
%11 = tail call i32 @bitrev(i32 %10, i32 %4)
%12 = sext i32 %11 to i64
%13 = icmp slt i64 %9, %12
br i1 %13, label %14, label %23
14: ; preds = %8
%15 = getelementptr inbounds double, double* %1, i64 %9
%16 = load double, double* %15
%17 = getelementptr inbounds double, double* %2, i64 %9
%18 = load double, double* %17
%19 = getelementptr inbounds double, double* %1, i64 %12
%20 = load double, double* %19
store double %20, double* %15
%21 = getelementptr inbounds double, double* %2, i64 %12
%22 = load double, double* %21
store double %22, double* %17
store double %16, double* %19
store double %18, double* %21
br label %23
23: ; preds = %8, %14
%24 = add nuw nsw i64 %9, 1
%25 = icmp eq i64 %24, %7
br i1 %25, label %26, label %8
26: ; preds = %23, %3
ret void
}