#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*/ printf(char *, ...);
int /*<<< orphan*/ swap(int *, int, int);
void qSort(int v[], int left, int right) {
  int i, last;
  if (left >= right) {
    return;
  }
  int subdiv = (left + right) / 2;
  swap(v, left, subdiv);
  last = left;
  for (i = left + 1; i <= right; i++) {
    if (v[i] < v[left]) {
      swap(v, ++last, i);
    }
  }
  swap(v, left, last);
  qSort(v, left, last - 1);
  qSort(v, last + 1, right);
  printf("Q sorted array ");
  for (i = 0; i < 10; i++) {
    printf("%3d", v[i]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<qSort>:
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
jl     1153 <qSort+0x23>
jmp    1259 <qSort+0x129>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1050 <swap@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11d2 <qSort+0xa2>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0xc(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jge    11bf <qSort+0x8f>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
mov    -0x14(%rbp),%edx
call   1050 <swap@plt>
jmp    11c4 <qSort+0x94>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1182 <qSort+0x52>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
call   1030 <qSort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1030 <qSort@plt>
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    124b <qSort+0x11b>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    121a <qSort+0xea>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qSort>:
cmp    %edx,%esi
jge    11b8 <qSort+0x78>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r12
lea    (%rbx,%rbp,1),%eax
mov    %eax,%edx
shr    $0x1f,%edx
add    %eax,%edx
sar    %edx
call   1060 <swap@plt>
movslq %ebp,%r15
mov    %rbx,0x10(%rsp)
mov    %rbp,%rax
movslq %ebx,%r14
add    $0x1,%ebp
mov    %r15,%r13
mov    %rax,0x8(%rsp)
mov    %eax,%ebx
jmp    1198 <qSort+0x58>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %r13,%r14
je     11b9 <qSort+0x79>
mov    0x4(%r12,%r13,4),%eax
add    $0x1,%r13
cmp    (%r12,%r15,4),%eax
jge    1190 <qSort+0x50>
add    $0x1,%ebx
mov    %r12,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1060 <swap@plt>
jmp    1190 <qSort+0x50>
ret
mov    %r12,%rdi
mov    0x8(%rsp),%rbp
mov    %ebp,%esi
mov    %ebx,%edx
call   1060 <swap@plt>
lea    -0x1(%rbx),%edx
mov    %r12,%rdi
mov    %ebp,%esi
call   1040 <qSort@plt>
add    $0x1,%ebx
mov    %r12,%rdi
mov    %ebx,%esi
mov    0x10(%rsp),%rdx
call   1040 <qSort@plt>
lea    0xe10(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r12),%esi
lea    0xe0e(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%r12),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r12),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%r12),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r12),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%r12),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%r12),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x1c(%r12),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%r12),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x24(%r12),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"Q sorted array \00"
@.str.1 = [4 x i8] c"%3d\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @qSort(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = icmp sge i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %3
br label %81
14: ; preds = %3
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = add nsw i32 %15, %16
%18 = sdiv i32 %17, 2
store i32 %18, i32* %9
%19 = load i32*, i32** %4
%20 = load i32, i32* %5
%21 = load i32, i32* %9
%22 = call i32 @swap(i32* %19, i32 %20, i32 %21)
%23 = load i32, i32* %5
store i32 %23, i32* %8
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %26
26: ; preds = %49, %14
%27 = load i32, i32* %7
%28 = load i32, i32* %6
%29 = icmp sle i32 %27, %28
br i1 %29, label %30, label %52
30: ; preds = %26
%31 = load i32*, i32** %4
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %34
%36 = load i32*, i32** %4
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = icmp slt i32 %35, %40
br i1 %41, label %42, label %48
42: ; preds = %30
%43 = load i32*, i32** %4
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
%46 = load i32, i32* %7
%47 = call i32 @swap(i32* %43, i32 %45, i32 %46)
br label %48
48: ; preds = %42, %30
br label %49
49: ; preds = %48
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %26
52: ; preds = %26
%53 = load i32*, i32** %4
%54 = load i32, i32* %5
%55 = load i32, i32* %8
%56 = call i32 @swap(i32* %53, i32 %54, i32 %55)
%57 = load i32*, i32** %4
%58 = load i32, i32* %5
%59 = load i32, i32* %8
%60 = sub nsw i32 %59, 1
%61 = load i32*, i32** %4
%62 = load i32, i32* %8
%63 = add nsw i32 %62, 1
%64 = load i32, i32* %6
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %66
66: ; preds = %76, %52
%67 = load i32, i32* %7
%68 = icmp slt i32 %67, 10
br i1 %68, label %69, label %79
69: ; preds = %66
%70 = load i32*, i32** %4
%71 = load i32, i32* %7
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %70, i64 %72
%74 = load i32, i32* %73
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %69
%77 = load i32, i32* %7
%78 = add nsw i32 %77, 1
store i32 %78, i32* %7
br label %66
79: ; preds = %66
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %81
81: ; preds = %79, %13
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"Q sorted array \00"
@.str.1 = [4 x i8] c"%3d\00"
define void @qSort(i32* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
br i1 %4, label %5, label %62
5: ; preds = %3
%6 = add nsw i32 %2, %1
%7 = sdiv i32 %6, 2
%8 = tail call i32 @swap(i32* %0, i32 %1, i32 %7)
%9 = sext i32 %1 to i64
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = sext i32 %2 to i64
br label %12
12: ; preds = %5, %24
%13 = phi i64 [ %9, %5 ], [ %15, %24 ]
%14 = phi i32 [ %1, %5 ], [ %25, %24 ]
%15 = add nsw i64 %13, 1
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = load i32, i32* %16
%18 = load i32, i32* %10
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %12
%21 = add nsw i32 %14, 1
%22 = trunc i64 %15 to i32
%23 = tail call i32 @swap(i32* %0, i32 %21, i32 %22)
br label %24
24: ; preds = %12, %20
%25 = phi i32 [ %21, %20 ], [ %14, %12 ]
%26 = icmp eq i64 %15, %11
br i1 %26, label %27, label %12
27: ; preds = %24
%28 = tail call i32 @swap(i32* %0, i32 %1, i32 %25)
%29 = add nsw i32 %25, -1
tail call void @qSort(i32* %0, i32 %1, i32 %29)
%30 = add nsw i32 %25, 1
tail call void @qSort(i32* %0, i32 %30, i32 %2)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%32 = load i32, i32* %0
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds i32, i32* %0, i64 1
%35 = load i32, i32* %34
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds i32, i32* %0, i64 2
%38 = load i32, i32* %37
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds i32, i32* %0, i64 3
%41 = load i32, i32* %40
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %41)
%43 = getelementptr inbounds i32, i32* %0, i64 4
%44 = load i32, i32* %43
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %44)
%46 = getelementptr inbounds i32, i32* %0, i64 5
%47 = load i32, i32* %46
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %47)
%49 = getelementptr inbounds i32, i32* %0, i64 6
%50 = load i32, i32* %49
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %50)
%52 = getelementptr inbounds i32, i32* %0, i64 7
%53 = load i32, i32* %52
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %53)
%55 = getelementptr inbounds i32, i32* %0, i64 8
%56 = load i32, i32* %55
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %56)
%58 = getelementptr inbounds i32, i32* %0, i64 9
%59 = load i32, i32* %58
%60 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %59)
%61 = tail call i32 @putchar(i32 10)
br label %62
62: ; preds = %3, %27
ret void
}