#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_up2down(int a[], int start, int end) {
  if (a == NULL || start >= end)
    return;
  int mid = (end + start) / 2;
  merge_sort_up2down(a, start, mid);
  merge_sort_up2down(a, mid + 1, end);
  merge(a, start, mid, end);
}


x86 assembly (clang, -O0):
<merge_sort_up2down>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1149 <merge_sort_up2down+0x29>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     114e <merge_sort_up2down+0x2e>
jmp    1192 <merge_sort_up2down+0x72>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <merge_sort_up2down@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1030 <merge_sort_up2down@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1040 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

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

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

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