#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_array(int *, int *, int, int, int);
void sort(int *elements, int *aux_elements, int low, int high) {
  int mid = low + (high - low) / 2;
  if (low >= high)
    return;
  sort(elements, aux_elements, low, mid);
  sort(elements, aux_elements, mid + 1, high);
  merge_array(elements, aux_elements, low, mid, high);
}


x86 assembly (clang, -O0):
<sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     1165 <sort+0x45>
jmp    11a5 <sort+0x85>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1040 <sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
call   1040 <sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1030 <merge_array@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort>:
mov    %ecx,%eax
sub    %edx,%eax
jle    1176 <sort+0x56>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
add    %edx,%ebx
mov    %ebx,%ecx
call   1040 <sort@plt>
lea    0x1(%rbx),%edx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12d,%ecx
call   1040 <sort@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %r12d,%r8d
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <merge_array@plt>
ret

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

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