#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 *malloc(size_t);
size_t random();
size_t *GenExchangeTable(size_t len) {
  size_t *exTable = malloc((len - 1) * sizeof(size_t));
  for (size_t i = len - 1; i > 0; i--)
    exTable[len - 1 - i] = random() % (i + 1);
  return exTable;
}


x86 assembly (clang, -O0):
<GenExchangeTable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
sub    $0x1,%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    1191 <GenExchangeTable+0x71>
mov    $0x0,%al
call   1030 <random@plt>
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
xor    %edx,%edx
div    %rcx
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    $0x1,%rcx
sub    -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    114d <GenExchangeTable+0x2d>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GenExchangeTable>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    -0x1(%rdi),%r15
lea    -0x8(,%rdi,8),%rdi
ff
call   1040 <malloc@plt>
mov    %rax,%r14
test   %r15,%r15
je     117f <GenExchangeTable+0x5f>
mov    %r14,%r15
jmp    1166 <GenExchangeTable+0x46>
cs nopw 0x0(%rax,%rax,1)
xor    %edx,%edx
div    %rbx
mov    %rdx,(%r15)
add    $0xffffffffffffffff,%rbx
add    $0x8,%r15
cmp    $0x1,%rbx
je     117f <GenExchangeTable+0x5f>
xor    %eax,%eax
call   1030 <random@plt>
mov    %rax,%rcx
or     %rbx,%rcx
shr    $0x20,%rcx
jne    1150 <GenExchangeTable+0x30>
xor    %edx,%edx
div    %ebx
jmp    1155 <GenExchangeTable+0x35>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64* @GenExchangeTable(i64 %0) {
%2 = alloca i64
%3 = alloca i64*
%4 = alloca i64
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = sub i64 %5, 1
%7 = mul i64 %6, 8
%8 = call i64* @malloc(i64 %7)
store i64* %8, i64** %3
%9 = load i64, i64* %2
%10 = sub i64 %9, 1
store i64 %10, i64* %4
br label %11
11: ; preds = %25, %1
%12 = load i64, i64* %4
%13 = icmp ugt i64 %12, 0
br i1 %13, label %14, label %28
14: ; preds = %11
%15 = call i64 (...) @random()
%16 = load i64, i64* %4
%17 = add i64 %16, 1
%18 = urem i64 %15, %17
%19 = load i64*, i64** %3
%20 = load i64, i64* %2
%21 = sub i64 %20, 1
%22 = load i64, i64* %4
%23 = sub i64 %21, %22
%24 = getelementptr inbounds i64, i64* %19, i64 %23
store i64 %18, i64* %24
br label %25
25: ; preds = %14
%26 = load i64, i64* %4
%27 = add i64 %26, -1
store i64 %27, i64* %4
br label %11
28: ; preds = %11
%29 = load i64*, i64** %3
ret i64* %29
}

LLVM IR (-O2):
define noalias i64* @GenExchangeTable(i64 %0) {
%2 = add i64 %0, -1
%3 = shl i64 %2, 3
%4 = tail call i64* @malloc(i64 %3)
%5 = icmp eq i64 %2, 0
br i1 %5, label %6, label %7
6: ; preds = %7, %1
ret i64* %4
7: ; preds = %1, %7
%8 = phi i64 [ %14, %7 ], [ %2, %1 ]
%9 = tail call i64 (...) @random()
%10 = add i64 %8, 1
%11 = urem i64 %9, %10
%12 = sub nuw i64 %2, %8
%13 = getelementptr inbounds i64, i64* %4, i64 %12
store i64 %11, i64* %13
%14 = add i64 %8, -1
%15 = icmp eq i64 %14, 0
br i1 %15, label %6, label %7
}