#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*/ printf(char *, ...);
int /*<<< orphan*/ sort(int *, int, int, int);
void partition(int *arr, int low, int high) {
  int middle = 0;
  printf("Inside partition Low : %d High %d\n", low, high);
  if (low < high) {
    middle = (low + high) / 2;
    partition(arr, low, middle);
    printf("partition 1 returned\n");
    partition(arr, middle + 1, high);
    printf("partition 2 returned\n");
    sort(arr, low, middle, high);
  }
}


x86 assembly (clang, -O0):
<partition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11c9 <partition+0x99>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <partition@plt>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1030 <partition@plt>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1050 <sort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<partition>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,%r15
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %r14d,%r12d
jge    11bf <partition+0x7f>
lea    (%r14,%r12,1),%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
mov    %r15,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
call   1040 <partition@plt>
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
lea    0x1(%rbx),%esi
mov    %r15,%rdi
mov    %r14d,%edx
call   1040 <partition@plt>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <sort@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Inside partition Low : %d High %d\0A\00"
@.str.1 = [22 x i8] c"partition 1 returned\0A\00"
@.str.2 = [22 x i8] c"partition 2 returned\0A\00"
define void @partition(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
store i32 0, i32* %7
%8 = load i32, i32* %5
%9 = load i32, i32* %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9)
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %33
14: ; preds = %3
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = add nsw i32 %15, %16
%18 = sdiv i32 %17, 2
store i32 %18, i32* %7
%19 = load i32*, i32** %4
%20 = load i32, i32* %5
%21 = load i32, i32* %7
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32*, i32** %4
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
%26 = load i32, i32* %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32*, i32** %4
%29 = load i32, i32* %5
%30 = load i32, i32* %7
%31 = load i32, i32* %6
%32 = call i32 @sort(i32* %28, i32 %29, i32 %30, i32 %31)
br label %33
33: ; preds = %14, %3
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"Inside partition Low : %d High %d\0A\00"
@str = [21 x i8] c"partition 1 returned\00"
@str.3 = [21 x i8] c"partition 2 returned\00"
define void @partition(i32* %0, i32 %1, i32 %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%5 = icmp slt i32 %1, %2
br i1 %5, label %7, label %6
6: ; preds = %3, %7
ret void
7: ; preds = %3
%8 = add nsw i32 %2, %1
%9 = sdiv i32 %8, 2
tail call void @partition(i32* %0, i32 %1, i32 %9)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%11 = add nsw i32 %9, 1
tail call void @partition(i32* %0, i32 %11, i32 %2)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.3, i64 0, i64 0))
%13 = tail call i32 @sort(i32* %0, i32 %1, i32 %9, i32 %2)
br label %6
}