#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 u_next(int);
int /*<<< orphan*/ u_random(int);
int /*<<< orphan*/ u_swap(int *, int, int);
void knuth_shuffle(int *items, int size, int seed) {
  u_random(seed);
  for (int i = 0; i < size - 1; i++) {
    int j = i + u_next(size - i);
    u_swap(items, i, j);
  }
}


x86 assembly (clang, -O0):
<knuth_shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <u_random@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    119a <knuth_shuffle+0x6a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
sub    -0x14(%rbp),%edi
call   1050 <u_next@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <u_swap@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1151 <knuth_shuffle+0x21>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<knuth_shuffle>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    %edx,%edi
call   1040 <u_random@plt>
cmp    $0x2,%ebp
jl     116f <knuth_shuffle+0x3f>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1050 <u_next@plt>
lea    (%rax,%rbx,1),%edx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <u_swap@plt>
add    $0x1,%ebx
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jne    1150 <knuth_shuffle+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @knuth_shuffle(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = call i32 @u_random(i32 %9)
store i32 0, i32* %7
br label %11
11: ; preds = %27, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %5
%14 = sub nsw i32 %13, 1
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %30
16: ; preds = %11
%17 = load i32, i32* %7
%18 = load i32, i32* %5
%19 = load i32, i32* %7
%20 = sub nsw i32 %18, %19
%21 = call i32 @u_next(i32 %20)
%22 = add nsw i32 %17, %21
store i32 %22, i32* %8
%23 = load i32*, i32** %4
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = call i32 @u_swap(i32* %23, i32 %24, i32 %25)
br label %27
27: ; preds = %16
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %11
30: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @knuth_shuffle(i32* %0, i32 %1, i32 %2) {
%4 = tail call i32 @u_random(i32 %2)
%5 = add i32 %1, -1
%6 = icmp sgt i32 %1, 1
br i1 %6, label %8, label %7
7: ; preds = %8, %3
ret void
8: ; preds = %3, %8
%9 = phi i32 [ %14, %8 ], [ 0, %3 ]
%10 = sub nsw i32 %1, %9
%11 = tail call i32 @u_next(i32 %10)
%12 = add nsw i32 %11, %9
%13 = tail call i32 @u_swap(i32* %0, i32 %9, i32 %12)
%14 = add nuw nsw i32 %9, 1
%15 = icmp eq i32 %14, %5
br i1 %15, label %7, label %8
}