#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 */
size_t *GenExchangeTable(size_t);
int /*<<< orphan*/ free(size_t *);
void Shuffle(char *data, size_t len) {
  size_t *exTable = GenExchangeTable(len);
  for (size_t i = len - 1; i > 0; i--) {
    size_t n = exTable[len - 1 - i];
    char tmp = data[i];
    data[i] = data[n];
    data[n] = tmp;
  }
  free(exTable);
}


x86 assembly (clang, -O0):
<Shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <GenExchangeTable@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jbe    11af <Shuffle+0x8f>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
sub    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x29(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1149 <Shuffle+0x29>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Shuffle>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <GenExchangeTable@plt>
mov    %r14,%rcx
add    $0xffffffffffffffff,%rcx
je     11a3 <Shuffle+0x83>
test   $0x1,%cl
je     115a <Shuffle+0x3a>
mov    (%rax),%rcx
mov    -0x1(%r15,%r14,1),%sil
mov    (%r15,%rcx,1),%dl
mov    %dl,-0x1(%r15,%r14,1)
mov    %sil,(%r15,%rcx,1)
lea    -0x2(%r14),%rcx
cmp    $0x2,%r14
je     11a3 <Shuffle+0x83>
lea    (%r15,%rcx,1),%rdx
neg    %rcx
lea    (%rax,%r14,8),%rsi
nopl   0x0(%rax,%rax,1)
mov    -0x8(%rsi,%rcx,8),%rdi
movzbl (%rdx),%r8d
movzbl (%r15,%rdi,1),%ebx
mov    %bl,(%rdx)
mov    %r8b,(%r15,%rdi,1)
mov    (%rsi,%rcx,8),%rdi
movzbl -0x1(%rdx),%r8d
movzbl (%r15,%rdi,1),%ebx
mov    %bl,-0x1(%rdx)
mov    %r8b,(%r15,%rdi,1)
add    $0xfffffffffffffffe,%rdx
add    $0x2,%rcx
jne    1170 <Shuffle+0x50>
mov    %rax,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @Shuffle(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8
store i8* %0, i8** %3
store i64 %1, i64* %4
%9 = load i64, i64* %4
%10 = call i64* @GenExchangeTable(i64 %9)
store i64* %10, i64** %5
%11 = load i64, i64* %4
%12 = sub i64 %11, 1
store i64 %12, i64* %6
br label %13
13: ; preds = %39, %2
%14 = load i64, i64* %6
%15 = icmp ugt i64 %14, 0
br i1 %15, label %16, label %42
16: ; preds = %13
%17 = load i64*, i64** %5
%18 = load i64, i64* %4
%19 = sub i64 %18, 1
%20 = load i64, i64* %6
%21 = sub i64 %19, %20
%22 = getelementptr inbounds i64, i64* %17, i64 %21
%23 = load i64, i64* %22
store i64 %23, i64* %7
%24 = load i8*, i8** %3
%25 = load i64, i64* %6
%26 = getelementptr inbounds i8, i8* %24, i64 %25
%27 = load i8, i8* %26
store i8 %27, i8* %8
%28 = load i8*, i8** %3
%29 = load i64, i64* %7
%30 = getelementptr inbounds i8, i8* %28, i64 %29
%31 = load i8, i8* %30
%32 = load i8*, i8** %3
%33 = load i64, i64* %6
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8 %31, i8* %34
%35 = load i8, i8* %8
%36 = load i8*, i8** %3
%37 = load i64, i64* %7
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8 %35, i8* %38
br label %39
39: ; preds = %16
%40 = load i64, i64* %6
%41 = add i64 %40, -1
store i64 %41, i64* %6
br label %13
42: ; preds = %13
%43 = load i64*, i64** %5
%44 = call i32 @free(i64* %43)
ret void
}

LLVM IR (-O2):
define void @Shuffle(i8* nocapture %0, i64 %1) {
%3 = tail call i64* @GenExchangeTable(i64 %1)
%4 = add i64 %1, -1
%5 = icmp eq i64 %4, 0
br i1 %5, label %19, label %6
6: ; preds = %2
%7 = and i64 %4, 1
%8 = icmp eq i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %6
%10 = load i64, i64* %3
%11 = getelementptr inbounds i8, i8* %0, i64 %4
%12 = load i8, i8* %11
%13 = getelementptr inbounds i8, i8* %0, i64 %10
%14 = load i8, i8* %13
store i8 %14, i8* %11
store i8 %12, i8* %13
%15 = add i64 %1, -2
br label %16
16: ; preds = %9, %6
%17 = phi i64 [ %4, %6 ], [ %15, %9 ]
%18 = icmp eq i64 %1, 2
br i1 %18, label %19, label %21
19: ; preds = %16, %21, %2
%20 = tail call i32 @free(i64* %3)
ret void
21: ; preds = %16, %21
%22 = phi i64 [ %38, %21 ], [ %17, %16 ]
%23 = sub nuw i64 %4, %22
%24 = getelementptr inbounds i64, i64* %3, i64 %23
%25 = load i64, i64* %24
%26 = getelementptr inbounds i8, i8* %0, i64 %22
%27 = load i8, i8* %26
%28 = getelementptr inbounds i8, i8* %0, i64 %25
%29 = load i8, i8* %28
store i8 %29, i8* %26
store i8 %27, i8* %28
%30 = add i64 %22, -1
%31 = sub nuw i64 %4, %30
%32 = getelementptr inbounds i64, i64* %3, i64 %31
%33 = load i64, i64* %32
%34 = getelementptr inbounds i8, i8* %0, i64 %30
%35 = load i8, i8* %34
%36 = getelementptr inbounds i8, i8* %0, i64 %33
%37 = load i8, i8* %36
store i8 %37, i8* %34
store i8 %35, i8* %36
%38 = add i64 %22, -2
%39 = icmp eq i64 %38, 0
br i1 %39, label %19, label %21
}