#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);
void msort(int a[], int begin, int end) {
  int m;
  if (begin < end) {
    m = partition(a, begin, end);
    if (begin < m - 1)
      msort(a, begin, m - 1);
    if (m < end)
      msort(a, m, end);
  }
}


x86 assembly (clang, -O0):
<msort>:
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    1193 <msort+0x73>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <partition@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1173 <msort+0x53>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1040 <msort@plt>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    118e <msort+0x6e>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <msort@plt>
jmp    1193 <msort+0x73>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
jmp    1147 <msort+0x27>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%ebp
cmp    %r15d,%ebx
jge    116e <msort+0x4e>
cmp    %r15d,%ebp
jge    116e <msort+0x4e>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1030 <partition@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%edx
cmp    %ebp,%edx
jle    1140 <msort+0x20>
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <msort@plt>
jmp    1140 <msort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @msort(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 %34
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* %5
%17 = load i32, i32* %7
%18 = sub nsw i32 %17, 1
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %25
20: ; preds = %11
%21 = load i32*, i32** %4
%22 = load i32, i32* %5
%23 = load i32, i32* %7
%24 = sub nsw i32 %23, 1
br label %25
25: ; preds = %20, %11
%26 = load i32, i32* %7
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i32*, i32** %4
%31 = load i32, i32* %7
%32 = load i32, i32* %6
br label %33
33: ; preds = %29, %25
br label %34
34: ; preds = %33, %3
ret void
}

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