#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 */
scalar_t__ issorted(int *, int);
int /*<<< orphan*/ partition(int *, int, int);
int /*<<< orphan*/ printf(char *, char *);
int rand();
int main(int argc, char const *argv[]) {
  int arr[1000];
  for (int i = 0; i < 1000; i++) {
    arr[i] = rand() % 3;
  }
  partition(arr, 1000, 1);
  printf("issorted=%s\n", issorted(arr, 1000) ? "true" : "false");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xfb4(%rbp)
cmpl   $0x3e8,-0xfb4(%rbp)
jge    11a4 <main+0x64>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
movslq -0xfb4(%rbp),%rax
mov    %edx,-0xfb0(%rbp,%rax,4)
mov    -0xfb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb4(%rbp)
jmp    1163 <main+0x23>
lea    -0xfb0(%rbp),%rdi
mov    $0x3e8,%esi
mov    $0x1,%edx
call   1030 <partition@plt>
lea    -0xfb0(%rbp),%rdi
mov    $0x3e8,%esi
call   1050 <issorted@plt>
mov    %rax,%rcx
lea    0xe3d(%rip),%rsi
lea    0xe31(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xe15(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xfa0,%rsp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    1150 <main+0x10>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    $0x1,%edx
call   1030 <partition@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1050 <issorted@plt>
test   %rax,%rax
lea    0xe64(%rip),%rax
lea    0xe58(%rip),%rsi
cmove  %rax,%rsi
lea    0xe40(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xfa0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"issorted=%s\0A\00"
@.str.1 = [5 x i8] c"true\00"
@.str.2 = [6 x i8] c"false\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1000 x i32]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %8
8: ; preds = %17, %2
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 1000
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 3
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %15
store i32 %13, i32* %16
br label %17
17: ; preds = %11
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 1
store i32 %19, i32* %7
br label %8
20: ; preds = %8
%21 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 0
%22 = call i32 @partition(i32* %21, i32 1000, i32 1)
%23 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 0
%24 = call i64 @issorted(i32* %23, i32 1000)
%25 = icmp ne i64 %24, 0
%26 = zext i1 %25 to i64
%27 = select i1 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%28 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"issorted=%s\0A\00"
@.str.1 = [5 x i8] c"true\00"
@.str.2 = [6 x i8] c"false\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1000 x i32]
%4 = bitcast [1000 x i32]* %3 to i8*
br label %12
5: ; preds = %12
%6 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 0
%7 = call i32 @partition(i32* %6, i32 1000, i32 1)
%8 = call i64 @issorted(i32* %6, i32 1000)
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0)
%11 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %10)
ret i32 0
12: ; preds = %2, %12
%13 = phi i64 [ 0, %2 ], [ %17, %12 ]
%14 = tail call i32 (...) @rand()
%15 = srem i32 %14, 3
%16 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 %13
store i32 %15, i32* %16
%17 = add nuw nsw i64 %13, 1
%18 = icmp eq i64 %17, 1000
br i1 %18, label %5, label %12
}