#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*/ merge(int *, int, int, int);
void merge_sort(int a[], int first, int middle, int last) {
  if (first < last) {
    merge_sort(a, first, (first + middle) / 2, middle);
    merge_sort(a, middle + 1, (last + middle) / 2, last);
    merge(a, first, middle, last);
  }
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1194 <merge_sort+0x74>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
mov    -0x10(%rbp),%ecx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
add    $0x1,%esi
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
mov    -0x14(%rbp),%ecx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1030 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
cmp    %ecx,%esi
jge    1183 <merge_sort+0x63>
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%ebx
mov    %rdi,%r12
lea    (%r15,%rbx,1),%eax
mov    %eax,%edx
shr    $0x1f,%edx
add    %eax,%edx
sar    %edx
mov    %r15d,%ecx
call   1040 <merge_sort@plt>
lea    0x1(%r15),%esi
lea    (%r14,%r15,1),%eax
mov    %eax,%edx
shr    $0x1f,%edx
add    %eax,%edx
sar    %edx
mov    %r12,%rdi
mov    %r14d,%ecx
call   1040 <merge_sort@plt>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <merge@plt>
ret

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

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