#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 /*<<< orphan*/ display(int *, int, int);
int position(int *, int, int);
int /*<<< orphan*/ printf(char *, int, int, int);
void qSort(int *ptr, int lo, int hi) {
  int base;
  if (hi - lo <= 1) {
    return;
  } else {
    base = position(ptr, lo, hi);
    printf("\nIn qSort: lo=%d,hi=%d:base=%d", lo, hi, base);
    display(ptr, lo, hi);
    qSort(ptr, lo, base - 1);
    qSort(ptr, base + 1, hi);
  }
}


x86 assembly (clang, -O0):
<qSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0x1,%eax
jg     1166 <qSort+0x26>
jmp    11c0 <qSort+0x80>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1060 <position@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe78(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <display@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1030 <qSort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1030 <qSort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qSort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%eax
sub    %esi,%eax
cmp    $0x2,%eax
jl     11a7 <qSort+0x67>
mov    %edx,%r12d
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xea0(%rip),%r15
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
call   1060 <position@plt>
mov    %eax,%ebx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
mov    %eax,%ecx
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
call   1040 <display@plt>
lea    -0x1(%rbx),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <qSort@plt>
add    $0x1,%ebx
mov    %r12d,%eax
sub    %ebx,%eax
mov    %ebx,%ebp
cmp    $0x1,%eax
jg     1160 <qSort+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"\0AIn qSort: lo=%d,hi=%d:base=%d\00"
define void @qSort(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = load i32, i32* %5
%10 = sub nsw i32 %8, %9
%11 = icmp sle i32 %10, 1
br i1 %11, label %12, label %13
12: ; preds = %3
br label %34
13: ; preds = %3
%14 = load i32*, i32** %4
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = call i32 @position(i32* %14, i32 %15, i32 %16)
store i32 %17, i32* %7
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19, i32 %20)
%22 = load i32*, i32** %4
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = call i32 @display(i32* %22, i32 %23, i32 %24)
%26 = load i32*, i32** %4
%27 = load i32, i32* %5
%28 = load i32, i32* %7
%29 = sub nsw i32 %28, 1
%30 = load i32*, i32** %4
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
%33 = load i32, i32* %6
br label %34
34: ; preds = %12, %13
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"\0AIn qSort: lo=%d,hi=%d:base=%d\00"
define void @qSort(i32* %0, i32 %1, i32 %2) {
%4 = sub nsw i32 %2, %1
%5 = icmp slt i32 %4, 2
br i1 %5, label %15, label %6
6: ; preds = %3, %6
%7 = phi i32 [ %12, %6 ], [ %1, %3 ]
%8 = tail call i32 @position(i32* %0, i32 %7, i32 %2)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %2, i32 %8)
%10 = tail call i32 @display(i32* %0, i32 %7, i32 %2)
%11 = add nsw i32 %8, -1
tail call void @qSort(i32* %0, i32 %7, i32 %11)
%12 = add nsw i32 %8, 1
%13 = sub nsw i32 %2, %12
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %6
15: ; preds = %6, %3
ret void
}