#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 partition(int *, int, int);
int /*<<< orphan*/ pause(int *);
int /*<<< orphan*/ printSubArray(int, int, int *);
int /*<<< orphan*/ printf(char *);
void quicksort1(int array[], int lo, int hi, int *skip) {
  if (lo >= hi) {
    return;
  }
  printf("\nArray before partition: ");
  printSubArray(lo, hi, array);
  int p = partition(array, lo, hi);
  printf("Array after partition: ");
  printSubArray(lo, hi, array);
  pause(skip);
  printf("\nQuicksort below pivot: ");
  printSubArray(lo, p, array);
  quicksort1(array, lo, p, skip);
  pause(skip);
  printf("\nQuicksort above pivot: ");
  printSubArray(p + 1, hi, array);
  quicksort1(array, p + 1, hi, skip);
  printf("\nCombining sorted halves:\n");
  printSubArray(lo, hi, array);
}


x86 assembly (clang, -O0):
<quicksort1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     1177 <quicksort1+0x27>
jmp    124e <quicksort1+0xfe>
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rdx
call   1060 <printSubArray@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <partition@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rdx
call   1060 <printSubArray@plt>
mov    -0x18(%rbp),%rdi
call   1050 <pause@plt>
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x8(%rbp),%rdx
call   1060 <printSubArray@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1070 <quicksort1@plt>
mov    -0x18(%rbp),%rdi
call   1050 <pause@plt>
lea    0xe45(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rdx
call   1060 <printSubArray@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1070 <quicksort1@plt>
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rdx
call   1060 <printSubArray@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quicksort1>:
cmp    %edx,%esi
jge    1240 <quicksort1+0xe0>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r12
lea    0xe7e(%rip),%rdi
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %r14d,%esi
mov    %r12,%rdx
call   1070 <printSubArray@plt>
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1040 <partition@plt>
mov    %eax,%ebx
lea    0xe70(%rip),%rdi
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %r14d,%esi
mov    %r12,%rdx
call   1070 <printSubArray@plt>
mov    %r15,%rdi
call   1060 <pause@plt>
lea    0xe67(%rip),%rdi
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r12,%rdx
call   1070 <printSubArray@plt>
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15,%rcx
call   1080 <quicksort1@plt>
mov    %r15,%rdi
call   1060 <pause@plt>
lea    0xe51(%rip),%rdi
call   1050 <printf@plt>
add    $0x1,%ebx
mov    %ebx,%edi
mov    %r14d,%esi
mov    %r12,%rdx
call   1070 <printSubArray@plt>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %r15,%rcx
call   1080 <quicksort1@plt>
lea    0xe3e(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    %r14d,%esi
mov    %r12,%rdx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <printSubArray@plt>
ret

LLVM IR (-O0):
@.str = [26 x i8] c"\0AArray before partition: \00"
@.str.1 = [24 x i8] c"Array after partition: \00"
@.str.2 = [25 x i8] c"\0AQuicksort below pivot: \00"
@.str.3 = [25 x i8] c"\0AQuicksort above pivot: \00"
@.str.4 = [27 x i8] c"\0ACombining sorted halves:\0A\00"
define void @quicksort1(i32* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%10 = load i32, i32* %6
%11 = load i32, i32* %7
%12 = icmp sge i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %4
br label %58
14: ; preds = %4
%15 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = load i32*, i32** %5
%19 = call i32 @printSubArray(i32 %16, i32 %17, i32* %18)
%20 = load i32*, i32** %5
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = call i32 @partition(i32* %20, i32 %21, i32 %22)
store i32 %23, i32* %9
%24 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = load i32*, i32** %5
%28 = call i32 @printSubArray(i32 %25, i32 %26, i32* %27)
%29 = load i32*, i32** %8
%30 = call i32 @pause(i32* %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* %6
%33 = load i32, i32* %9
%34 = load i32*, i32** %5
%35 = call i32 @printSubArray(i32 %32, i32 %33, i32* %34)
%36 = load i32*, i32** %5
%37 = load i32, i32* %6
%38 = load i32, i32* %9
%39 = load i32*, i32** %8
%40 = load i32*, i32** %8
%41 = call i32 @pause(i32* %40)
%42 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* %9
%44 = add nsw i32 %43, 1
%45 = load i32, i32* %7
%46 = load i32*, i32** %5
%47 = call i32 @printSubArray(i32 %44, i32 %45, i32* %46)
%48 = load i32*, i32** %5
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
%51 = load i32, i32* %7
%52 = load i32*, i32** %8
%53 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%54 = load i32, i32* %6
%55 = load i32, i32* %7
%56 = load i32*, i32** %5
%57 = call i32 @printSubArray(i32 %54, i32 %55, i32* %56)
br label %58
58: ; preds = %14, %13
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"\0AArray before partition: \00"
@.str.1 = [24 x i8] c"Array after partition: \00"
@.str.2 = [25 x i8] c"\0AQuicksort below pivot: \00"
@.str.3 = [25 x i8] c"\0AQuicksort above pivot: \00"
@str = [26 x i8] c"\0ACombining sorted halves:\00"
define void @quicksort1(i32* %0, i32 %1, i32 %2, i32* %3) {
%5 = icmp slt i32 %1, %2
br i1 %5, label %7, label %6
6: ; preds = %4, %7
ret void
7: ; preds = %4
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @printSubArray(i32 %1, i32 %2, i32* %0)
%10 = tail call i32 @partition(i32* %0, i32 %1, i32 %2)
%11 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @printSubArray(i32 %1, i32 %2, i32* %0)
%13 = tail call i32 @pause(i32* %3)
%14 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @printSubArray(i32 %1, i32 %10, i32* %0)
tail call void @quicksort1(i32* %0, i32 %1, i32 %10, i32* %3)
%16 = tail call i32 @pause(i32* %3)
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%18 = add nsw i32 %10, 1
%19 = tail call i32 @printSubArray(i32 %18, i32 %2, i32* %0)
tail call void @quicksort1(i32* %0, i32 %18, i32 %2, i32* %3)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%21 = tail call i32 @printSubArray(i32 %1, i32 %2, i32* %0)
br label %6
}