#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 rand();
void array_shuffle(int *arr, size_t length) {
  size_t i, r;
  for (i = 0; i < length; ++i) {
    r = rand() % length;
    do {
      int t = arr[i];
      arr[i] = arr[r];
      arr[r] = t;
    } while (0);
    ;
  }
}


x86 assembly (clang, -O0):
<array_shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1191 <array_shuffle+0x81>
mov    $0x0,%al
call   1030 <rand@plt>
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1180 <array_shuffle+0x70>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <array_shuffle+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_shuffle>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     1168 <array_shuffle+0x58>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
jmp    114e <array_shuffle+0x3e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edx,%edx
div    %r14
mov    (%r15,%rbx,4),%eax
mov    (%r15,%rdx,4),%ecx
mov    %ecx,(%r15,%rbx,4)
mov    %eax,(%r15,%rdx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
je     1168 <array_shuffle+0x58>
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rcx
or     %r14,%rcx
shr    $0x20,%rcx
jne    1130 <array_shuffle+0x20>
xor    %edx,%edx
div    %r14d
jmp    1135 <array_shuffle+0x25>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @array_shuffle(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
store i64 0, i64* %5
br label %8
8: ; preds = %33, %2
%9 = load i64, i64* %5
%10 = load i64, i64* %4
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %36
12: ; preds = %8
%13 = call i64 (...) @rand()
%14 = load i64, i64* %4
%15 = urem i64 %13, %14
store i64 %15, i64* %6
br label %16
16: ; preds = %12
%17 = load i32*, i32** %3
%18 = load i64, i64* %5
%19 = getelementptr inbounds i32, i32* %17, i64 %18
%20 = load i32, i32* %19
store i32 %20, i32* %7
%21 = load i32*, i32** %3
%22 = load i64, i64* %6
%23 = getelementptr inbounds i32, i32* %21, i64 %22
%24 = load i32, i32* %23
%25 = load i32*, i32** %3
%26 = load i64, i64* %5
%27 = getelementptr inbounds i32, i32* %25, i64 %26
store i32 %24, i32* %27
%28 = load i32, i32* %7
%29 = load i32*, i32** %3
%30 = load i64, i64* %6
%31 = getelementptr inbounds i32, i32* %29, i64 %30
store i32 %28, i32* %31
br label %32
32: ; preds = %16
br label %33
33: ; preds = %32
%34 = load i64, i64* %5
%35 = add i64 %34, 1
store i64 %35, i64* %5
br label %8
36: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @array_shuffle(i32* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %14, label %4
4: ; preds = %2, %4
%5 = phi i64 [ %12, %4 ], [ 0, %2 ]
%6 = tail call i64 (...) @rand()
%7 = urem i64 %6, %1
%8 = getelementptr inbounds i32, i32* %0, i64 %5
%9 = load i32, i32* %8
%10 = getelementptr inbounds i32, i32* %0, i64 %7
%11 = load i32, i32* %10
store i32 %11, i32* %8
store i32 %9, i32* %10
%12 = add nuw i64 %5, 1
%13 = icmp eq i64 %12, %1
br i1 %13, label %14, label %4
14: ; preds = %4, %2
ret void
}