#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 rand();
int /*<<< orphan*/ swap(int *, int *);
void shuffle(int arr[], int n) {
  int i, k;
  for (i = 1; i < n; ++i) {
    swap(arr + i, arr + rand() % (i + 1));
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1192 <shuffle+0x72>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <swap@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <shuffle+0x16>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%esi
jl     1166 <shuffle+0x46>
mov    %rdi,%r14
mov    %esi,%r15d
lea    0x4(%rdi),%r12
mov    $0x1,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <rand@plt>
add    $0x1,%rbx
cltd
idiv   %ebx
movslq %edx,%rax
lea    (%r14,%rax,4),%rsi
mov    %r12,%rdi
call   1030 <swap@plt>
add    $0x4,%r12
cmp    %rbx,%r15
jne    1140 <shuffle+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @shuffle(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 1, i32* %5
br label %7
7: ; preds = %24, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %27
11: ; preds = %7
%12 = load i32*, i32** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
%16 = load i32*, i32** %3
%17 = call i32 (...) @rand()
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
%20 = srem i32 %17, %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %16, i64 %21
%23 = call i32 @swap(i32* %15, i32* %22)
br label %24
24: ; preds = %11
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %7
27: ; preds = %7
ret void
}

LLVM IR (-O2):
define void @shuffle(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %17
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 1, %4 ], [ %10, %6 ]
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = tail call i32 (...) @rand()
%10 = add nuw nsw i64 %7, 1
%11 = trunc i64 %10 to i32
%12 = srem i32 %9, %11
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = tail call i32 @swap(i32* %8, i32* %14)
%16 = icmp eq i64 %10, %5
br i1 %16, label %17, label %6
17: ; preds = %6, %2
ret void
}