#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 */
long BitReverse(long, long);
void Reverse(long N, long M, double *x) {
  long j, k;
  for (k = 0; k < N; k++) {
    j = BitReverse(M, k);
    if (j > k) {
      {
        double tmp;
        tmp = x[2 * j];
        x[2 * j] = x[2 * k];
        x[2 * k] = tmp;
      };
      {
        double tmp;
        tmp = x[2 * j + 1];
        x[2 * j + 1] = x[2 * k + 1];
        x[2 * k + 1] = tmp;
      };
    }
  }
}


x86 assembly (clang, -O0):
<Reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    120f <Reverse+0xff>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <BitReverse@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jle    11f9 <Reverse+0xe9>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
shl    $0x1,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
shl    $0x1,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
movsd  0x8(%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
shl    $0x1,%rcx
movsd  0x8(%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
movsd  %xmm0,0x8(%rax,%rcx,8)
movsd  -0x38(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
shl    $0x1,%rcx
movsd  %xmm0,0x8(%rax,%rcx,8)
jmp    11fe <Reverse+0xee>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    112c <Reverse+0x1c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Reverse>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
jle    1167 <Reverse+0x57>
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
xor    %ebx,%ebx
mov    %rdx,%r13
jmp    113d <Reverse+0x2d>
xchg   %ax,%ax
add    $0x1,%rbx
add    $0x10,%r13
cmp    %rbx,%r12
je     1167 <Reverse+0x57>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <BitReverse@plt>
cmp    %rbx,%rax
jle    1130 <Reverse+0x20>
shl    $0x4,%rax
movups (%r15,%rax,1),%xmm0
movups 0x0(%r13),%xmm1
movups %xmm1,(%r15,%rax,1)
movups %xmm0,0x0(%r13)
jmp    1130 <Reverse+0x20>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @Reverse(i64 %0, i64 %1, double* nocapture %2) {
%4 = icmp sgt i64 %0, 0
br i1 %4, label %5, label %23
5: ; preds = %3, %20
%6 = phi i64 [ %21, %20 ], [ 0, %3 ]
%7 = tail call i64 @BitReverse(i64 %1, i64 %6)
%8 = icmp sgt i64 %7, %6
br i1 %8, label %9, label %20
9: ; preds = %5
%10 = shl nsw i64 %7, 1
%11 = getelementptr inbounds double, double* %2, i64 %10
%12 = shl nuw nsw i64 %6, 1
%13 = getelementptr inbounds double, double* %2, i64 %12
%14 = bitcast double* %11 to <2 x double>*
%15 = load <2 x double>, <2 x double>* %14
%16 = bitcast double* %13 to <2 x double>*
%17 = load <2 x double>, <2 x double>* %16
%18 = bitcast double* %11 to <2 x double>*
store <2 x double> %17, <2 x double>* %18
%19 = bitcast double* %13 to <2 x double>*
store <2 x double> %15, <2 x double>* %19
br label %20
20: ; preds = %5, %9
%21 = add nuw nsw i64 %6, 1
%22 = icmp eq i64 %21, %0
br i1 %22, label %23, label %5
23: ; preds = %20, %3
ret void
}