#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*/ printf(char *, int, int, int *);
void quick_sort(int *a, int left, int right) {
  int p;
  if (!a || left < 0 || right < 0) {
    printf("\nERROR: Incorrect inputs to quick sort algo, 		"
           "	left = %d, right = %d, arr* = %p",
           left, right, a);
    return;
  }
  if (left < right) {
    p = partition(a, left, right);
    quick_sort(a, left, p - 1);
    quick_sort(a, p + 1, right);
  }
  return;
}


x86 assembly (clang, -O0):
<quick_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1161 <quick_sort+0x31>
cmpl   $0x0,-0xc(%rbp)
jl     1161 <quick_sort+0x31>
cmpl   $0x0,-0x10(%rbp)
jge    117c <quick_sort+0x4c>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
jmp    11c3 <quick_sort+0x93>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11be <quick_sort+0x8e>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <partition@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1050 <quick_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1050 <quick_sort@plt>
jmp    11c3 <quick_sort+0x93>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quick_sort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
test   %rdi,%rdi
je     117f <quick_sort+0x4f>
mov    %ebp,%eax
or     %r15d,%eax
js     117f <quick_sort+0x4f>
nopl   0x0(%rax,%rax,1)
cmp    %r15d,%ebp
jge    119f <quick_sort+0x6f>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1030 <partition@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <quick_sort@plt>
add    $0x1,%ebx
mov    %ebx,%eax
or     %r15d,%eax
mov    %ebx,%ebp
jns    1150 <quick_sort+0x20>
jmp    1181 <quick_sort+0x51>
mov    %ebp,%ebx
lea    0xe78(%rip),%rdi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [81 x i8] c"\0AERROR: Incorrect inputs to quick sort algo, \09\09\09left = %d, right = %d, arr* = %p\00"
define void @quick_sort(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** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %16
10: ; preds = %3
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %13, %10, %3
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = load i32*, i32** %4
%20 = call i32 @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18, i32* %19)
br label %39
21: ; preds = %13
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %38
25: ; preds = %21
%26 = load i32*, i32** %4
%27 = load i32, i32* %5
%28 = load i32, i32* %6
%29 = call i32 @partition(i32* %26, i32 %27, i32 %28)
store i32 %29, i32* %7
%30 = load i32*, i32** %4
%31 = load i32, i32* %5
%32 = load i32, i32* %7
%33 = sub nsw i32 %32, 1
%34 = load i32*, i32** %4
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
%37 = load i32, i32* %6
br label %38
38: ; preds = %25, %21
br label %39
39: ; preds = %38, %16
ret void
}

LLVM IR (-O2):
@.str = [81 x i8] c"\0AERROR: Incorrect inputs to quick sort algo, \09\09\09left = %d, right = %d, arr* = %p\00"
define void @quick_sort(i32* %0, i32 %1, i32 %2) {
%4 = icmp eq i32* %0, null
%5 = or i32 %1, %2
%6 = icmp slt i32 %5, 0
%7 = or i1 %4, %6
br i1 %7, label %8, label %11
8: ; preds = %14, %3
%9 = phi i32 [ %1, %3 ], [ %17, %14 ]
%10 = tail call i32 @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %2, i32* %0)
br label %20
11: ; preds = %3, %14
%12 = phi i32 [ %17, %14 ], [ %1, %3 ]
%13 = icmp slt i32 %12, %2
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = tail call i32 @partition(i32* %0, i32 %12, i32 %2)
%16 = add nsw i32 %15, -1
tail call void @quick_sort(i32* %0, i32 %12, i32 %16)
%17 = add nsw i32 %15, 1
%18 = or i32 %17, %2
%19 = icmp slt i32 %18, 0
br i1 %19, label %8, label %11
20: ; preds = %11, %8
ret void
}