#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, int, int);
void quick(int *a, int *m, int left, int right) {
  int p = (left + right) / 2;
  int pnew;
  if (left < right) {
    pnew = partition(a, m, left, right, p);
    quick(a, m, left, pnew - 1);
    quick(a, m, pnew + 1, right);
  }
}


x86 assembly (clang, -O0):
<quick>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1199 <quick+0x79>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1030 <partition@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
call   1040 <quick@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
call   1040 <quick@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quick>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    %ecx,%edx
jge    1180 <quick+0x60>
mov    %ecx,%r12d
mov    %edx,%r13d
mov    %rsi,%r14
mov    %rdi,%r15
nopl   0x0(%rax)
lea    (%r12,%r13,1),%eax
mov    %eax,%r8d
shr    $0x1f,%r8d
add    %eax,%r8d
sar    %r8d
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r13d,%edx
mov    %r12d,%ecx
call   1030 <partition@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%ecx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r13d,%edx
call   1040 <quick@plt>
add    $0x1,%ebx
mov    %ebx,%r13d
cmp    %r12d,%ebx
jl     1140 <quick+0x20>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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