#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ merge(int *, int *, int, int, int);
void __merge_sort(int src[], int dst[], int low, int high, int max) {
  if (low == high)
    dst[low] = src[low];
  else {
    int mid = (low + high) / 2;
    int *space = (int *)malloc(sizeof(int) * max);
    if (NULL != space) {
      __merge_sort(src, space, low, mid, max);
      __merge_sort(src, space, mid + 1, high, max);
      merge(space, dst, low, mid, high);
    }
  }
}


x86 assembly (clang, -O0):
<__merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1171 <__merge_sort+0x41>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11ee <__merge_sort+0xbe>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
je     11e9 <__merge_sort+0xb9>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1030 <__merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1030 <__merge_sort@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1040 <merge@plt>
jmp    11ee <__merge_sort+0xbe>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__merge_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%rbp
mov    %rdi,%r13
cmp    %ecx,%edx
jne    1155 <__merge_sort+0x25>
movslq %ebx,%rax
mov    0x0(%r13,%rax,4),%ecx
mov    %ecx,0x0(%rbp,%rax,4)
jmp    11d2 <__merge_sort+0xa2>
mov    %r8d,%r14d
mov    %ecx,%r15d
lea    0x0(,%r14,4),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11d2 <__merge_sort+0xa2>
mov    %rax,%r12
lea    (%r15,%rbx,1),%eax
mov    %rbp,(%rsp)
mov    %r14,%rbp
mov    %eax,%r14d
shr    $0x1f,%r14d
add    %eax,%r14d
sar    %r14d
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
mov    %r14d,%ecx
mov    %ebp,%r8d
call   1030 <__merge_sort@plt>
lea    0x1(%r14),%edx
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15d,%ecx
mov    %ebp,%r8d
call   1030 <__merge_sort@plt>
mov    %r12,%rdi
mov    (%rsp),%rsi
mov    %ebx,%edx
mov    %r14d,%ecx
mov    %r15d,%r8d
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(i32* %0, i32* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%13 = load i32, i32* %8
%14 = load i32, i32* %9
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %26
16: ; preds = %5
%17 = load i32*, i32** %6
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = load i32*, i32** %7
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
store i32 %21, i32* %25
br label %58
26: ; preds = %5
%27 = load i32, i32* %8
%28 = load i32, i32* %9
%29 = add nsw i32 %27, %28
%30 = sdiv i32 %29, 2
store i32 %30, i32* %11
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = mul i64 4, %32
%34 = trunc i64 %33 to i32
%35 = call i64 @malloc(i32 %34)
%36 = inttoptr i64 %35 to i32*
store i32* %36, i32** %12
%37 = load i32*, i32** %12
%38 = icmp ne i32* null, %37
br i1 %38, label %39, label %57
39: ; preds = %26
%40 = load i32*, i32** %6
%41 = load i32*, i32** %12
%42 = load i32, i32* %8
%43 = load i32, i32* %11
%44 = load i32, i32* %10
%45 = load i32*, i32** %6
%46 = load i32*, i32** %12
%47 = load i32, i32* %11
%48 = add nsw i32 %47, 1
%49 = load i32, i32* %9
%50 = load i32, i32* %10
%51 = load i32*, i32** %12
%52 = load i32*, i32** %7
%53 = load i32, i32* %8
%54 = load i32, i32* %11
%55 = load i32, i32* %9
%56 = call i32 @merge(i32* %51, i32* %52, i32 %53, i32 %54, i32 %55)
br label %57
57: ; preds = %39, %26
br label %58
58: ; preds = %57, %16
ret void
}

LLVM IR (-O2):
define void @__merge_sort(i32* %0, i32* %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp eq i32 %2, %3
br i1 %6, label %7, label %12
7: ; preds = %5
%8 = sext i32 %2 to i64
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = load i32, i32* %9
%11 = getelementptr inbounds i32, i32* %1, i64 %8
store i32 %10, i32* %11
br label %19
12: ; preds = %5
%13 = add nsw i32 %3, %2
%14 = sdiv i32 %13, 2
%15 = shl i32 %4, 2
%16 = tail call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i32*
%18 = icmp eq i64 %16, 0
br i1 %18, label %19, label %20
19: ; preds = %7, %12, %20
ret void
20: ; preds = %12
tail call void @__merge_sort(i32* %0, i32* %17, i32 %2, i32 %14, i32 %4)
%21 = add nsw i32 %14, 1
tail call void @__merge_sort(i32* %0, i32* %17, i32 %21, i32 %3, i32 %4)
%22 = tail call i32 @merge(i32* %17, i32* %1, i32 %2, i32 %14, i32 %3)
br label %19
}