#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 *const, int const, int const, int const);
int quicksort(int *const arr, int const left, int const right, int const size) {
  int pos_pivot;
  static int error = 0;
  if ((error == 0) && ((arr == NULL) || (right >= size) || (left < 0) ||
                       (right < 0) || (size <= 0)))
    return 1;
  if (error == 0)
    error = 1;
  if (left < right) {
    pos_pivot = partition(arr, left, right, size);
    quicksort(arr, left, pos_pivot - 1, size);
    quicksort(arr, pos_pivot + 1, right, size);
  }
  return 0;
}


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    %ecx,-0x1c(%rbp)
cmpl   $0x0,0x2ef8(%rip)
jne    1183 <quicksort+0x63>
cmpq   $0x0,-0x10(%rbp)
je     1177 <quicksort+0x57>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1177 <quicksort+0x57>
cmpl   $0x0,-0x14(%rbp)
jl     1177 <quicksort+0x57>
cmpl   $0x0,-0x18(%rbp)
jl     1177 <quicksort+0x57>
cmpl   $0x0,-0x1c(%rbp)
jg     1183 <quicksort+0x63>
movl   $0x1,-0x4(%rbp)
jmp    11ec <quicksort+0xcc>
cmpl   $0x0,0x2eaa(%rip)
jne    119a <quicksort+0x7a>
movl   $0x1,0x2e9a(%rip)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11e5 <quicksort+0xc5>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1030 <partition@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%edx
sub    $0x1,%edx
mov    -0x1c(%rbp),%ecx
call   1040 <quicksort@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
add    $0x1,%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1040 <quicksort@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quicksort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%r14
xor    %ecx,%ecx
cmpb   $0x0,0x2ef8(%rip)
jne    1162 <quicksort+0x42>
xchg   %ax,%ax
mov    $0x1,%edx
test   %r14,%r14
je     119d <quicksort+0x7d>
test   %r15d,%r15d
jle    119d <quicksort+0x7d>
cmp    %r15d,%r12d
jge    119d <quicksort+0x7d>
mov    %ebx,%eax
or     %r12d,%eax
js     119d <quicksort+0x7d>
movb   $0x1,0x2ed2(%rip)
cmp    %r12d,%ebx
jge    119b <quicksort+0x7b>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r15d,%ecx
call   1030 <partition@plt>
mov    %eax,%ebp
lea    -0x1(%rbp),%edx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%ecx
call   1040 <quicksort@plt>
add    $0x1,%ebp
mov    $0x1,%cl
mov    %ebp,%ebx
cmpb   $0x0,0x2e9d(%rip)
je     1140 <quicksort+0x20>
jmp    1162 <quicksort+0x42>
xor    %edx,%edx
xor    %eax,%eax
test   $0x1,%cl
cmove  %edx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@quicksort.error = internal global i32 0
define i32 @quicksort(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i32, i32* @quicksort.error
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %30
13: ; preds = %4
%14 = load i32*, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %29, label %16
16: ; preds = %13
%17 = load i32, i32* %8
%18 = load i32, i32* %9
%19 = icmp sge i32 %17, %18
br i1 %19, label %29, label %20
20: ; preds = %16
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %20
%24 = load i32, i32* %8
%25 = icmp slt i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* %9
%28 = icmp sle i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26, %23, %20, %16, %13
store i32 1, i32* %5
br label %57
30: ; preds = %26, %4
%31 = load i32, i32* @quicksort.error
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 1, i32* @quicksort.error
br label %34
34: ; preds = %33, %30
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %56
38: ; preds = %34
%39 = load i32*, i32** %6
%40 = load i32, i32* %7
%41 = load i32, i32* %8
%42 = load i32, i32* %9
%43 = call i32 @partition(i32* %39, i32 %40, i32 %41, i32 %42)
store i32 %43, i32* %10
%44 = load i32*, i32** %6
%45 = load i32, i32* %7
%46 = load i32, i32* %10
%47 = sub nsw i32 %46, 1
%48 = load i32, i32* %9
%49 = call i32 @quicksort(i32* %44, i32 %45, i32 %47, i32 %48)
%50 = load i32*, i32** %6
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
%53 = load i32, i32* %8
%54 = load i32, i32* %9
%55 = call i32 @quicksort(i32* %50, i32 %52, i32 %53, i32 %54)
br label %56
56: ; preds = %38, %34
store i32 0, i32* %5
br label %57
57: ; preds = %56, %29
%58 = load i32, i32* %5
ret i32 %58
}

LLVM IR (-O2):
@quicksort.error = internal unnamed_addr global i1 false
define i32 @quicksort(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i32* %0, null
%6 = icmp sge i32 %2, %3
%7 = icmp slt i32 %3, 1
br label %8
8: ; preds = %21, %4
%9 = phi i32 [ %1, %4 ], [ %25, %21 ]
%10 = phi i1 [ false, %4 ], [ true, %21 ]
%11 = load i1, i1* @quicksort.error
br i1 %11, label %19, label %12
12: ; preds = %8
br i1 %5, label %26, label %13
13: ; preds = %12
%14 = or i32 %9, %2
%15 = icmp slt i32 %14, 0
%16 = or i1 %6, %15
%17 = or i1 %7, %16
br i1 %17, label %26, label %18
18: ; preds = %13
store i1 true, i1* @quicksort.error
br label %19
19: ; preds = %8, %18
%20 = icmp slt i32 %9, %2
br i1 %20, label %21, label %26
21: ; preds = %19
%22 = tail call i32 @partition(i32* %0, i32 %9, i32 %2, i32 %3)
%23 = add nsw i32 %22, -1
%24 = tail call i32 @quicksort(i32* %0, i32 %9, i32 %23, i32 %3)
%25 = add nsw i32 %22, 1
br label %8
26: ; preds = %19, %12, %13
%27 = phi i32 [ 1, %13 ], [ 1, %12 ], [ 0, %19 ]
%28 = select i1 %10, i32 0, i32 %27
ret i32 %28
}