#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*/ srand(int);
void shuffle(int *v, int n) {
  int i1, i2;
  int tmp;
  srand(9);
  for (; n >= 2; n--) {
    i1 = n - 1;
    i2 = (unsigned)(rand() % n);
    tmp = v[i1];
    v[i1] = v[i2];
    v[i2] = tmp;
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x9,%edi
call   1030 <srand@plt>
cmpl   $0x2,-0xc(%rbp)
jl     119a <shuffle+0x7a>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1139 <shuffle+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0x9,%edi
call   1030 <srand@plt>
cmp    $0x2,%ebp
jl     116c <shuffle+0x4c>
mov    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
lea    -0x1(%rbp),%rbx
xor    %eax,%eax
call   1040 <rand@plt>
cltd
idiv   %ebp
mov    %ebx,%eax
mov    (%r14,%rax,4),%ecx
movslq %edx,%rdx
mov    (%r14,%rdx,4),%esi
mov    %esi,(%r14,%rax,4)
mov    %ecx,(%r14,%rdx,4)
cmp    $0x2,%rbp
mov    %rbx,%rbp
ja     1140 <shuffle+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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