#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 *, size_t, size_t, size_t);
void merge_sort_top_down_internal(int array[], int temp[], size_t low,
                                  size_t high) {
  if (low >= high) {
    return;
  }
  size_t middle = low + (high - low) / 2;
  merge_sort_top_down_internal(array, temp, low, middle);
  merge_sort_top_down_internal(array, temp, middle + 1, high);
  merge(array, temp, low, middle, high);
}


x86 assembly (clang, -O0):
<merge_sort_top_down_internal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     114b <merge_sort_top_down_internal+0x2b>
jmp    11a9 <merge_sort_top_down_internal+0x89>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    -0x18(%rbp),%rcx
shr    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1030 <merge_sort_top_down_internal@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
add    $0x1,%rdx
mov    -0x20(%rbp),%rcx
call   1030 <merge_sort_top_down_internal@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1040 <merge@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort_top_down_internal>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbp
sub    %rdx,%rbp
jbe    1186 <merge_sort_top_down_internal+0x66>
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
shr    %rbp
lea    (%rdx,%rbp,1),%r13
mov    %r13,%rcx
call   1030 <merge_sort_top_down_internal@plt>
lea    (%rbx,%rbp,1),%rdx
add    $0x1,%rdx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rcx
call   1030 <merge_sort_top_down_internal@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r13,%rcx
mov    %r14,%r8
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <merge@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @merge_sort_top_down_internal(i32* %0, i32* %1, i64 %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i32* %0, i32** %5
store i32* %1, i32** %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%10 = load i64, i64* %7
%11 = load i64, i64* %8
%12 = icmp uge i64 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %4
br label %36
14: ; preds = %4
%15 = load i64, i64* %7
%16 = load i64, i64* %8
%17 = load i64, i64* %7
%18 = sub i64 %16, %17
%19 = udiv i64 %18, 2
%20 = add i64 %15, %19
store i64 %20, i64* %9
%21 = load i32*, i32** %5
%22 = load i32*, i32** %6
%23 = load i64, i64* %7
%24 = load i64, i64* %9
%25 = load i32*, i32** %5
%26 = load i32*, i32** %6
%27 = load i64, i64* %9
%28 = add i64 %27, 1
%29 = load i64, i64* %8
%30 = load i32*, i32** %5
%31 = load i32*, i32** %6
%32 = load i64, i64* %7
%33 = load i64, i64* %9
%34 = load i64, i64* %8
%35 = call i32 @merge(i32* %30, i32* %31, i64 %32, i64 %33, i64 %34)
br label %36
36: ; preds = %14, %13
ret void
}

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