#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 quick_sort(int v[], int left, int right) {
  static int ncnt = 0;
  if (left < right) {
    int last = partition(v, left, right);
    quick_sort(v, left, last - 1);
    quick_sort(v, last + 1, right);
    ncnt++;
  }
  return ncnt;
}


x86 assembly (clang, -O0):
<quick_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1183 <quick_sort+0x63>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <partition@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1040 <quick_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <quick_sort@plt>
mov    0x2eba(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2eb1(%rip)
mov    0x2eab(%rip),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quick_sort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    %edx,%esi
jge    1168 <quick_sort+0x48>
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
call   1030 <partition@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <quick_sort@plt>
add    $0x1,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
call   1040 <quick_sort@plt>
mov    0x2ed7(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ece(%rip)
jmp    116e <quick_sort+0x4e>
mov    0x2ec6(%rip),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@quick_sort.ncnt = internal global i32 0
define i32 @quick_sort(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = load i32, i32* %6
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %28
11: ; preds = %3
%12 = load i32*, i32** %4
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = call i32 @partition(i32* %12, i32 %13, i32 %14)
store i32 %15, i32* %7
%16 = load i32*, i32** %4
%17 = load i32, i32* %5
%18 = load i32, i32* %7
%19 = sub nsw i32 %18, 1
%20 = call i32 @quick_sort(i32* %16, i32 %17, i32 %19)
%21 = load i32*, i32** %4
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
%24 = load i32, i32* %6
%25 = call i32 @quick_sort(i32* %21, i32 %23, i32 %24)
%26 = load i32, i32* @quick_sort.ncnt
%27 = add nsw i32 %26, 1
store i32 %27, i32* @quick_sort.ncnt
br label %28
28: ; preds = %11, %3
%29 = load i32, i32* @quick_sort.ncnt
ret i32 %29
}

LLVM IR (-O2):
@quick_sort.ncnt = internal unnamed_addr global i32 0
define i32 @quick_sort(i32* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = load i32, i32* @quick_sort.ncnt
br label %15
7: ; preds = %3
%8 = tail call i32 @partition(i32* %0, i32 %1, i32 %2)
%9 = add nsw i32 %8, -1
%10 = tail call i32 @quick_sort(i32* %0, i32 %1, i32 %9)
%11 = add nsw i32 %8, 1
%12 = tail call i32 @quick_sort(i32* %0, i32 %11, i32 %2)
%13 = load i32, i32* @quick_sort.ncnt
%14 = add nsw i32 %13, 1
store i32 %14, i32* @quick_sort.ncnt
br label %15
15: ; preds = %5, %7
%16 = phi i32 [ %6, %5 ], [ %14, %7 ]
ret i32 %16
}