#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 */
struct timeval {
  int tv_usec;
};

/* Variables and functions */
size_t drand48();
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ srand48(int);
void shuffleArray(int *array, size_t n) {
  struct timeval tv;
  gettimeofday(&tv, NULL);
  int usec = tv.tv_usec;
  srand48(usec);
  if (n > 1) {
    size_t i;
    for (i = n - 1; i > 0; i--) {
      size_t j = (unsigned int)(drand48() * (i + 1));
      int t = array[j];
      array[j] = array[i];
      array[i] = t;
    }
  }
}


x86 assembly (clang, -O0):
<shuffleArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <srand48@plt>
cmpq   $0x1,-0x10(%rbp)
jbe    11de <shuffleArray+0xae>
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jbe    11d9 <shuffleArray+0xa9>
mov    $0x0,%al
call   1050 <drand48@plt>
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
imul   %rcx,%rax
mov    %eax,%eax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    1172 <shuffleArray+0x42>
jmp    11de <shuffleArray+0xae>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffleArray>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    (%rsp),%edi
call   1040 <srand48@plt>
cmp    $0x2,%rbx
jb     1186 <shuffleArray+0x56>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <drand48@plt>
imul   %ebx,%eax
mov    (%r14,%rax,4),%ecx
mov    -0x4(%r14,%rbx,4),%edx
mov    %edx,(%r14,%rax,4)
mov    %ecx,-0x4(%r14,%rbx,4)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jne    1160 <shuffleArray+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
define void @shuffleArray(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca %struct.timeval
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
%10 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%12 = load i32, i32* %11
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = call i32 @srand48(i32 %13)
%15 = load i64, i64* %4
%16 = icmp ugt i64 %15, 1
br i1 %16, label %17, label %49
17: ; preds = %2
%18 = load i64, i64* %4
%19 = sub i64 %18, 1
store i64 %19, i64* %7
br label %20
20: ; preds = %45, %17
%21 = load i64, i64* %7
%22 = icmp ugt i64 %21, 0
br i1 %22, label %23, label %48
23: ; preds = %20
%24 = call i64 (...) @drand48()
%25 = load i64, i64* %7
%26 = add i64 %25, 1
%27 = mul i64 %24, %26
%28 = trunc i64 %27 to i32
%29 = zext i32 %28 to i64
store i64 %29, i64* %8
%30 = load i32*, i32** %3
%31 = load i64, i64* %8
%32 = getelementptr inbounds i32, i32* %30, i64 %31
%33 = load i32, i32* %32
store i32 %33, i32* %9
%34 = load i32*, i32** %3
%35 = load i64, i64* %7
%36 = getelementptr inbounds i32, i32* %34, i64 %35
%37 = load i32, i32* %36
%38 = load i32*, i32** %3
%39 = load i64, i64* %8
%40 = getelementptr inbounds i32, i32* %38, i64 %39
store i32 %37, i32* %40
%41 = load i32, i32* %9
%42 = load i32*, i32** %3
%43 = load i64, i64* %7
%44 = getelementptr inbounds i32, i32* %42, i64 %43
store i32 %41, i32* %44
br label %45
45: ; preds = %23
%46 = load i64, i64* %7
%47 = add i64 %46, -1
store i64 %47, i64* %7
br label %20
48: ; preds = %20
br label %49
49: ; preds = %48, %2
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
define void @shuffleArray(i32* nocapture %0, i64 %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%7 = load i32, i32* %6
%8 = tail call i32 @srand48(i32 %7)
%9 = icmp ult i64 %1, 2
br i1 %9, label %24, label %10
10: ; preds = %2
%11 = add i64 %1, -1
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ %22, %12 ], [ %11, %10 ]
%14 = phi i64 [ %13, %12 ], [ %1, %10 ]
%15 = tail call i64 (...) @drand48()
%16 = mul i64 %15, %14
%17 = and i64 %16, 4294967295
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = load i32, i32* %18
%20 = getelementptr inbounds i32, i32* %0, i64 %13
%21 = load i32, i32* %20
store i32 %21, i32* %18
store i32 %19, i32* %20
%22 = add i64 %13, -1
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %12
24: ; preds = %12, %2
ret void
}