#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);
void limited_quicksort(int A[], int p, int r, int treshold) {
  if (r - p > treshold) {
    int q = partition(A, p, r);
    limited_quicksort(A, p, q, treshold);
    limited_quicksort(A, q + 1, r, treshold);
  }
}


x86 assembly (clang, -O0):
<limited_quicksort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    117d <limited_quicksort+0x5d>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <partition@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1030 <limited_quicksort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1030 <limited_quicksort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<limited_quicksort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%eax
sub    %esi,%eax
cmp    %ecx,%eax
jle    116d <limited_quicksort+0x4d>
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%ebx
mov    %rdi,%r12
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
call   1040 <partition@plt>
mov    %eax,%ebp
mov    %r12,%rdi
mov    %ebx,%esi
mov    %eax,%edx
mov    %r14d,%ecx
call   1030 <limited_quicksort@plt>
add    $0x1,%ebp
mov    %r15d,%eax
sub    %ebp,%eax
mov    %ebp,%ebx
cmp    %r14d,%eax
jg     1140 <limited_quicksort+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @limited_quicksort(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = sub nsw i32 %10, %11
%13 = load i32, i32* %8
%14 = icmp sgt i32 %12, %13
br i1 %14, label %15, label %29
15: ; preds = %4
%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* %9
%20 = load i32*, i32** %5
%21 = load i32, i32* %6
%22 = load i32, i32* %9
%23 = load i32, i32* %8
%24 = load i32*, i32** %5
%25 = load i32, i32* %9
%26 = add nsw i32 %25, 1
%27 = load i32, i32* %7
%28 = load i32, i32* %8
br label %29
29: ; preds = %15, %4
ret void
}

LLVM IR (-O2):
define void @limited_quicksort(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = sub nsw i32 %2, %1
%6 = icmp sgt i32 %5, %3
br i1 %6, label %7, label %13
7: ; preds = %4, %7
%8 = phi i32 [ %10, %7 ], [ %1, %4 ]
%9 = tail call i32 @partition(i32* %0, i32 %8, i32 %2)
tail call void @limited_quicksort(i32* %0, i32 %8, i32 %9, i32 %3)
%10 = add nsw i32 %9, 1
%11 = sub nsw i32 %2, %10
%12 = icmp sgt i32 %11, %3
br i1 %12, label %7, label %13
13: ; preds = %7, %4
ret void
}