#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_arr(int *, int, int, int, int);
void merge_sort(int arr[], int sort_order, int low, int high) {
  int mid;
  if (low < high) {
    mid = (low + high) / 2;
    merge_sort(arr, sort_order, low, mid);
    merge_sort(arr, sort_order, (mid + 1), high);
    merge_arr(arr, sort_order, low, mid, high);
  } else {
    return;
  }
}


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    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1194 <merge_sort+0x74>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1030 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
mov    -0x14(%rbp),%ecx
call   1030 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%r8d
call   1040 <merge_arr@plt>
jmp    1199 <merge_sort+0x79>
jmp    1199 <merge_sort+0x79>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
cmp    %ecx,%edx
jge    1176 <merge_sort+0x56>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %esi,%r15d
mov    %rdi,%r12
lea    (%r14,%rbx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %ebp,%ecx
call   1030 <merge_sort@plt>
lea    0x1(%rbp),%edx
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r14d,%ecx
call   1030 <merge_sort@plt>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r14d,%r8d
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <merge_arr@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
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %7
%11 = load i32, i32* %8
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %33
13: ; preds = %4
%14 = load i32, i32* %7
%15 = load i32, i32* %8
%16 = add nsw i32 %14, %15
%17 = sdiv i32 %16, 2
store i32 %17, i32* %9
%18 = load i32*, i32** %5
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = load i32, i32* %9
%22 = load i32*, i32** %5
%23 = load i32, i32* %6
%24 = load i32, i32* %9
%25 = add nsw i32 %24, 1
%26 = load i32, i32* %8
%27 = load i32*, i32** %5
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = load i32, i32* %9
%31 = load i32, i32* %8
%32 = call i32 @merge_arr(i32* %27, i32 %28, i32 %29, i32 %30, i32 %31)
br label %34
33: ; preds = %4
br label %34
34: ; preds = %33, %13
ret void
}

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