#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 quicksort(int a[], int first, int last) {
  int q;
  printf("first and last is %d  and  %d\n", first, last);
  if (first < last) {
    q = partition(a, first, last);
    printf("index = %d \n", q);
    quicksort(a, first, (q - 1));
    quicksort(a, (q + 1), last);
  }
}


x86 assembly (clang, -O0):
<quicksort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11a9 <quicksort+0x79>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <partition@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
call   1040 <quicksort@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x18(%rbp),%edx
call   1040 <quicksort@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quicksort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r13d
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xeb6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %r13d,%ebp
jge    11b1 <quicksort+0x81>
lea    0xec2(%rip),%r15
lea    0xe9c(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r13d,%edx
call   1030 <partition@plt>
mov    %eax,%ebx
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    -0x1(%rbx),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <quicksort@plt>
add    $0x1,%ebx
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%ebp
cmp    %r13d,%ebx
jl     1170 <quicksort+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [31 x i8] c"first and last is %d and %d\0A\00"
@.str.1 = [13 x i8] c"index = %d \0A\00"
define i32 @quicksort(i32* %0, i32 %1, i32 %2) {
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%5 = icmp slt i32 %1, %2
br i1 %5, label %6, label %15
6: ; preds = %3, %6
%7 = phi i32 [ %12, %6 ], [ %1, %3 ]
%8 = tail call i32 @partition(i32* %0, i32 %7, i32 %2)
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = add nsw i32 %8, -1
%11 = tail call i32 @quicksort(i32* %0, i32 %7, i32 %10)
%12 = add nsw i32 %8, 1
%13 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %2)
%14 = icmp slt i32 %12, %2
br i1 %14, label %6, label %15
15: ; preds = %6, %3
ret i32 undef
}