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

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


x86 assembly (clang, -O0):
<shuffle_leaves>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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),%edi
call   1040 <srand48@plt>
cmpq   $0x1,-0x10(%rbp)
jbe    11cf <shuffle_leaves+0x9f>
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jbe    11ca <shuffle_leaves+0x9a>
mov    $0x0,%al
call   1050 <drand48@plt>
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,8),%rdx
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    116b <shuffle_leaves+0x3b>
jmp    11cf <shuffle_leaves+0x9f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle_leaves>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%edi
call   1040 <srand48@plt>
cmp    $0x2,%r15
jb     1197 <shuffle_leaves+0x67>
mov    %r15d,%eax
add    $0xffffffff,%eax
je     1197 <shuffle_leaves+0x67>
mov    %eax,%eax
lea    (%r14,%rax,8),%rbx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <drand48@plt>
imul   %r15d,%eax
mov    (%r14,%rax,8),%rcx
mov    (%rbx),%rdx
mov    %rdx,(%r14,%rax,8)
mov    %rcx,(%rbx)
add    $0xffffffff,%r15d
add    $0xfffffffffffffff8,%rbx
cmp    $0x1,%r15d
jne    1170 <shuffle_leaves+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.node = type { i32 }
%struct.timeval = type { i32 }
define void @shuffle_leaves(%struct.node** 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
%10 = trunc i64 %1 to i32
%11 = add i32 %10, -1
%12 = icmp eq i32 %11, 0
%13 = or i1 %9, %12
br i1 %13, label %30, label %14
14: ; preds = %2
%15 = zext i32 %11 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ %15, %14 ], [ %26, %16 ]
%18 = phi i32 [ %10, %14 ], [ %29, %16 ]
%19 = tail call i32 (...) @drand48()
%20 = mul i32 %19, %18
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds %struct.node*, %struct.node** %0, i64 %21
%23 = load %struct.node*, %struct.node** %22
%24 = getelementptr inbounds %struct.node*, %struct.node** %0, i64 %17
%25 = load %struct.node*, %struct.node** %24
store %struct.node* %25, %struct.node** %22
store %struct.node* %23, %struct.node** %24
%26 = add nsw i64 %17, -1
%27 = trunc i64 %26 to i32
%28 = icmp eq i32 %27, 0
%29 = trunc i64 %17 to i32
br i1 %28, label %30, label %16
30: ; preds = %16, %2
ret void
}