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


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

x86 assembly (clang, -O2):
<quick_sort>:
cmp    %edx,%esi
jge    1168 <quick_sort+0x48>
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
call   1030 <partition_rand@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>
addl   $0x1,0x2ed6(%rip)
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
%8 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %6
%10 = load i32, i32* %7
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %29
12: ; preds = %3
%13 = load i32*, i32** %5
%14 = load i32, i32* %6
%15 = load i32, i32* %7
%16 = call i32 @partition_rand(i32* %13, i32 %14, i32 %15)
store i32 %16, i32* %8
%17 = load i32*, i32** %5
%18 = load i32, i32* %6
%19 = load i32, i32* %8
%20 = sub nsw i32 %19, 1
%21 = call i32 @quick_sort(i32* %17, i32 %18, i32 %20)
%22 = load i32*, i32** %5
%23 = load i32, i32* %8
%24 = add nsw i32 %23, 1
%25 = load i32, i32* %7
%26 = call i32 @quick_sort(i32* %22, i32 %24, i32 %25)
%27 = load i32, i32* @quick_sort.ncnt
%28 = add nsw i32 %27, 1
store i32 %28, i32* @quick_sort.ncnt
br label %29
29: ; preds = %12, %3
%30 = load i32, i32* %4
ret i32 %30
}

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 %6, label %5
5: ; preds = %3, %6
ret i32 undef
6: ; preds = %3
%7 = tail call i32 @partition_rand(i32* %0, i32 %1, i32 %2)
%8 = add nsw i32 %7, -1
%9 = tail call i32 @quick_sort(i32* %0, i32 %1, i32 %8)
%10 = add nsw i32 %7, 1
%11 = tail call i32 @quick_sort(i32* %0, i32 %10, i32 %2)
%12 = load i32, i32* @quick_sort.ncnt
%13 = add nsw i32 %12, 1
store i32 %13, i32* @quick_sort.ncnt
br label %5
}