#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();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void shuffle(void **base, size_t n_items) {
  srand(time(NULL));
  size_t i, j;
  void *tmp;
  for (i = 0; i < n_items - 1; i++) {
    j = i + rand() % (n_items - i);
    tmp = base[j];
    base[j] = base[i];
    base[i] = tmp;
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11dd <shuffle+0xad>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
mov    -0x10(%rbp),%rcx
sub    -0x18(%rbp),%rcx
xor    %edx,%edx
div    %rcx
mov    -0x30(%rbp),%rax
add    %rdx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1158 <shuffle+0x28>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
jmp    1170 <shuffle+0x40>
nopl   (%rax)
xor    %edx,%edx
div    %r15
add    %rbx,%rdx
mov    (%r14,%rdx,8),%rax
mov    (%r14,%rbx,8),%rcx
mov    %rcx,(%r14,%rdx,8)
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
add    $0xffffffffffffffff,%r15
cmp    $0x1,%r15
je     1190 <shuffle+0x60>
xor    %eax,%eax
call   1050 <rand@plt>
mov    %rax,%rcx
or     %r15,%rcx
shr    $0x20,%rcx
jne    1150 <shuffle+0x20>
xor    %edx,%edx
div    %r15d
jmp    1155 <shuffle+0x25>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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