#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 */
char getchar();
int /*<<< orphan*/ printArray(int, int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ quicksort1(int *, int /*<<< orphan*/, int, int *);
void quicksort(int array[], int length) {
  printf("QUICKSORT ");
  printArray(length, array);
  printf("Press ENTER to step through, enter s to (s)kip: ");
  int skip = getchar() == 's' ? 1 : 0;
  if (skip) {
    getchar();
  }
  quicksort1(array, 0, length - 1, &skip);
  printf("\n\nFinal Array: ");
  printArray(length, array);
}


x86 assembly (clang, -O0):
<quicksort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1050 <printArray@plt>
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x73,%edx
cmove  %ecx,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     119e <quicksort+0x5e>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
lea    -0x10(%rbp),%rcx
call   1060 <quicksort1@plt>
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1050 <printArray@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quicksort>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xeaf(%rip),%rdi
call   1030 <printf@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1050 <printArray@plt>
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %ecx,%ecx
cmp    $0x73,%al
sete   %cl
mov    %ecx,0x4(%rsp)
jne    1188 <quicksort+0x48>
xor    %eax,%eax
call   1040 <getchar@plt>
lea    -0x1(%r14),%edx
lea    0x4(%rsp),%rcx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <quicksort1@plt>
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1050 <printArray@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"QUICKSORT \00"
@.str.1 = [49 x i8] c"Press ENTER to step through, enter s to (s)kip: \00"
@.str.2 = [16 x i8] c"\0A\0AFinal Array: \00"
define void @quicksort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %4
%8 = load i32*, i32** %3
%9 = call i32 @printArray(i32 %7, i32* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%11 = call signext i8 (...) @getchar()
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 115
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 1, i32 0
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call signext i8 (...) @getchar()
br label %20
20: ; preds = %18, %2
%21 = load i32*, i32** %3
%22 = load i32, i32* %4
%23 = sub nsw i32 %22, 1
%24 = call i32 @quicksort1(i32* %21, i32 0, i32 %23, i32* %5)
%25 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* %4
%27 = load i32*, i32** %3
%28 = call i32 @printArray(i32 %26, i32* %27)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"QUICKSORT \00"
@.str.1 = [49 x i8] c"Press ENTER to step through, enter s to (s)kip: \00"
@.str.2 = [16 x i8] c"\0A\0AFinal Array: \00"
define void @quicksort(i32* %0, i32 %1) {
%3 = alloca i32
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @printArray(i32 %1, i32* %0)
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%7 = bitcast i32* %3 to i8*
%8 = tail call signext i8 (...) @getchar()
%9 = icmp eq i8 %8, 115
%10 = zext i1 %9 to i32
store i32 %10, i32* %3
br i1 %9, label %11, label %13
11: ; preds = %2
%12 = tail call signext i8 (...) @getchar()
br label %13
13: ; preds = %11, %2
%14 = add nsw i32 %1, -1
%15 = call i32 @quicksort1(i32* %0, i32 0, i32 %14, i32* %3)
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @printArray(i32 %1, i32* %0)
ret void
}