#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 randomInteger(int /*<<< orphan*/, int);
int /*<<< orphan*/ randomize();
int /*<<< orphan*/ swapIntegerElements(int *, int, int);
int shuffleSort(int *array, int n) {
  int lh, rh;
  randomize();
  for (lh = 0; lh < n; lh++) {
    rh = randomInteger(0, n - 1);
    swapIntegerElements(array, lh, rh);
  }
  return n;
}


x86 assembly (clang, -O0):
<shuffleSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1050 <randomize@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1186 <shuffleSort+0x56>
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
xor    %edi,%edi
call   1040 <randomInteger@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <swapIntegerElements@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114d <shuffleSort+0x1d>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffleSort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <randomize@plt>
test   %r15d,%r15d
jle    116d <shuffleSort+0x3d>
lea    -0x1(%r15),%ebx
nop
xor    %edi,%edi
mov    %ebx,%esi
call   1040 <randomInteger@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1030 <swapIntegerElements@plt>
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    1150 <shuffleSort+0x20>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @shuffleSort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = call i32 (...) @randomize()
store i32 0, i32* %5
br label %8
8: ; preds = %20, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %23
12: ; preds = %8
%13 = load i32, i32* %4
%14 = sub nsw i32 %13, 1
%15 = call i32 @randomInteger(i32 0, i32 %14)
store i32 %15, i32* %6
%16 = load i32*, i32** %3
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = call i32 @swapIntegerElements(i32* %16, i32 %17, i32 %18)
br label %20
20: ; preds = %12
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %8
23: ; preds = %8
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
define i32 @shuffleSort(i32* %0, i32 returned %1) {
%3 = tail call i32 (...) @randomize()
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %13
5: ; preds = %2
%6 = add nsw i32 %1, -1
br label %7
7: ; preds = %5, %7
%8 = phi i32 [ 0, %5 ], [ %11, %7 ]
%9 = tail call i32 @randomInteger(i32 0, i32 %6)
%10 = tail call i32 @swapIntegerElements(i32* %0, i32 %8, i32 %9)
%11 = add nuw nsw i32 %8, 1
%12 = icmp eq i32 %11, %1
br i1 %12, label %13, label %7
13: ; preds = %7, %2
ret i32 %1
}