#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*/ insertionsort(int *, size_t);
size_t partition(int *, size_t, size_t);
void quick_insertionsort(int a[], size_t p, size_t r) {
  if (p < r && ~r) {
    if (r - p < 25) {
      insertionsort(&a[p], r - p + 1);
    } else {
      size_t q = partition(a, p, r);
      quick_insertionsort(a, p, q - 1);
      quick_insertionsort(a, q + 1, r);
    }
  }
}


x86 assembly (clang, -O0):
<quick_insertionsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11df <quick_insertionsort+0xaf>
mov    -0x18(%rbp),%rax
xor    $0xffffffffffffffff,%rax
cmp    $0x0,%rax
je     11df <quick_insertionsort+0xaf>
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
cmp    $0x19,%rax
jae    119b <quick_insertionsort+0x6b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
sub    -0x10(%rbp),%rsi
add    $0x1,%rsi
call   1040 <insertionsort@plt>
jmp    11da <quick_insertionsort+0xaa>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <partition@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
sub    $0x1,%rdx
call   1050 <quick_insertionsort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x18(%rbp),%rdx
call   1050 <quick_insertionsort@plt>
jmp    11df <quick_insertionsort+0xaf>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quick_insertionsort>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0xffffffffffffffff,%rdx
je     1188 <quick_insertionsort+0x58>
mov    %rdx,%r15
mov    %rsi,%r12
cmp    %rsi,%rdx
jbe    1188 <quick_insertionsort+0x58>
mov    %rdi,%r14
nopl   0x0(%rax)
mov    %r15,%rsi
sub    %r12,%rsi
cmp    $0x18,%rsi
jbe    1194 <quick_insertionsort+0x64>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1030 <partition@plt>
mov    %rax,%rbx
lea    -0x1(%rax),%rdx
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <quick_insertionsort@plt>
add    $0x1,%rbx
mov    %rbx,%r12
cmp    %r15,%rbx
jb     1150 <quick_insertionsort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    (%r14,%r12,4),%rdi
add    $0x1,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <insertionsort@plt>

LLVM IR (-O0):
define void @quick_insertionsort(i32* %0, i64 %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32* %0, i32** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%8 = load i64, i64* %5
%9 = load i64, i64* %6
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %43
11: ; preds = %3
%12 = load i64, i64* %6
%13 = xor i64 %12, -1
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %43
15: ; preds = %11
%16 = load i64, i64* %6
%17 = load i64, i64* %5
%18 = sub i64 %16, %17
%19 = icmp ult i64 %18, 25
br i1 %19, label %20, label %29
20: ; preds = %15
%21 = load i32*, i32** %4
%22 = load i64, i64* %5
%23 = getelementptr inbounds i32, i32* %21, i64 %22
%24 = load i64, i64* %6
%25 = load i64, i64* %5
%26 = sub i64 %24, %25
%27 = add i64 %26, 1
%28 = call i32 @insertionsort(i32* %23, i64 %27)
br label %42
29: ; preds = %15
%30 = load i32*, i32** %4
%31 = load i64, i64* %5
%32 = load i64, i64* %6
%33 = call i64 @partition(i32* %30, i64 %31, i64 %32)
store i64 %33, i64* %7
%34 = load i32*, i32** %4
%35 = load i64, i64* %5
%36 = load i64, i64* %7
%37 = sub i64 %36, 1
%38 = load i32*, i32** %4
%39 = load i64, i64* %7
%40 = add i64 %39, 1
%41 = load i64, i64* %6
br label %42
42: ; preds = %29, %20
br label %43
43: ; preds = %42, %11, %3
ret void
}

LLVM IR (-O2):
define void @quick_insertionsort(i32* %0, i64 %1, i64 %2) {
%4 = icmp eq i64 %2, -1
%5 = icmp ule i64 %2, %1
%6 = or i1 %4, %5
br i1 %6, label %20, label %7
7: ; preds = %3, %15
%8 = phi i64 [ %18, %15 ], [ %1, %3 ]
%9 = sub i64 %2, %8
%10 = icmp ult i64 %9, 25
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = getelementptr inbounds i32, i32* %0, i64 %8
%13 = add nuw nsw i64 %9, 1
%14 = tail call i32 @insertionsort(i32* %12, i64 %13)
br label %20
15: ; preds = %7
%16 = tail call i64 @partition(i32* %0, i64 %8, i64 %2)
%17 = add i64 %16, -1
tail call void @quick_insertionsort(i32* %0, i64 %8, i64 %17)
%18 = add i64 %16, 1
%19 = icmp ult i64 %18, %2
br i1 %19, label %7, label %20
20: ; preds = %15, %3, %11
ret void
}