#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(char *, int, int);
void quicksort(char *ch, int low, int high) {
  int partition_index;
  if (!ch || (low < 0) || (high < 0)) {
    return;
  }
  if (low < high) {
    int partition_index = partition(ch, low, high);
    quicksort(ch, low, partition_index - 1);
    quicksort(ch, partition_index + 1, high);
  }
}


x86 assembly (clang, -O0):
<quicksort>:
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     1151 <quicksort+0x31>
cmpl   $0x0,-0xc(%rbp)
jl     1151 <quicksort+0x31>
cmpl   $0x0,-0x10(%rbp)
jge    1156 <quicksort+0x36>
jmp    1198 <quicksort+0x78>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1198 <quicksort+0x78>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <partition@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
call   1040 <quicksort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <quicksort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quicksort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    %edx,%esi
jge    116d <quicksort+0x4d>
mov    %rdi,%r14
test   %rdi,%rdi
je     116d <quicksort+0x4d>
mov    %edx,%r15d
mov    %esi,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%eax
or     %r15d,%eax
js     116d <quicksort+0x4d>
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   1040 <quicksort@plt>
mov    %ebx,%ebp
add    $0x1,%ebp
cmp    %r15d,%ebp
jl     1140 <quicksort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @quicksort(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14, %11, %3
br label %35
18: ; preds = %14
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %35
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = call i32 @partition(i8* %23, i32 %24, i32 %25)
store i32 %26, i32* %8
%27 = load i8*, i8** %4
%28 = load i32, i32* %5
%29 = load i32, i32* %8
%30 = sub nsw i32 %29, 1
%31 = load i8*, i8** %4
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
%34 = load i32, i32* %6
br label %35
35: ; preds = %17, %22, %18
ret void
}

LLVM IR (-O2):
define void @quicksort(i8* %0, i32 %1, i32 %2) {
%4 = icmp ne i8* %0, null
%5 = or i32 %1, %2
%6 = icmp sgt i32 %5, -1
%7 = and i1 %4, %6
%8 = icmp slt i32 %1, %2
%9 = and i1 %8, %7
br i1 %9, label %10, label %19
10: ; preds = %3, %10
%11 = phi i32 [ %14, %10 ], [ %1, %3 ]
%12 = tail call i32 @partition(i8* %0, i32 %11, i32 %2)
%13 = add nsw i32 %12, -1
tail call void @quicksort(i8* %0, i32 %11, i32 %13)
%14 = add nsw i32 %12, 1
%15 = or i32 %14, %2
%16 = icmp sgt i32 %15, -1
%17 = icmp slt i32 %14, %2
%18 = and i1 %17, %16
br i1 %18, label %10, label %19
19: ; preds = %10, %3
ret void
}