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


x86 assembly (clang, -O0):
<MSort>:
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    1181 <MSort+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    1201 <MSort+0xc1>
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   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11f8 <MSort+0xb8>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1030 <MSort@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 <MSort@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1050 <Merge@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MSort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%rbp
mov    %rdi,%r12
cmp    %ecx,%edx
jne    1171 <MSort+0x31>
movslq %ebx,%rax
mov    (%r12,%rax,4),%ecx
mov    %ecx,0x0(%rbp,%rax,4)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r8d,%r14d
mov    %ecx,%r15d
lea    0x0(,%r14,4),%edi
call   1060 <malloc@plt>
mov    %rax,%r13
test   %rax,%rax
je     11e0 <MSort+0xa0>
lea    (%r15,%rbx,1),%eax
mov    %rbp,(%rsp)
mov    %r14,%rbp
mov    %eax,%r14d
shr    $0x1f,%r14d
add    %eax,%r14d
sar    %r14d
mov    %r12,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
mov    %r14d,%ecx
mov    %ebp,%r8d
call   1030 <MSort@plt>
lea    0x1(%r14),%edx
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15d,%ecx
mov    %ebp,%r8d
call   1030 <MSort@plt>
mov    %r13,%rdi
mov    (%rsp),%rsi
mov    %ebx,%edx
mov    %r14d,%ecx
mov    %r15d,%r8d
call   1050 <Merge@plt>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <free@plt>

LLVM IR (-O0):
define void @MSort(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 %59
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 i32* @malloc(i32 %34)
store i32* %35, i32** %12
%36 = load i32*, i32** %12
%37 = icmp ne i32* %36, null
br i1 %37, label %38, label %56
38: ; preds = %26
%39 = load i32*, i32** %6
%40 = load i32*, i32** %12
%41 = load i32, i32* %8
%42 = load i32, i32* %11
%43 = load i32, i32* %10
%44 = load i32*, i32** %6
%45 = load i32*, i32** %12
%46 = load i32, i32* %11
%47 = add nsw i32 %46, 1
%48 = load i32, i32* %9
%49 = load i32, i32* %10
%50 = load i32*, i32** %12
%51 = load i32*, i32** %7
%52 = load i32, i32* %8
%53 = load i32, i32* %11
%54 = load i32, i32* %9
%55 = call i32 @Merge(i32* %50, i32* %51, i32 %52, i32 %53, i32 %54)
br label %56
56: ; preds = %38, %26
%57 = load i32*, i32** %12
%58 = call i32 @free(i32* %57)
br label %59
59: ; preds = %56, %16
ret void
}

LLVM IR (-O2):
define void @MSort(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 %23
12: ; preds = %5
%13 = add nsw i32 %3, %2
%14 = sdiv i32 %13, 2
%15 = shl i32 %4, 2
%16 = tail call i32* @malloc(i32 %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %12
tail call void @MSort(i32* %0, i32* %16, i32 %2, i32 %14, i32 %4)
%19 = add nsw i32 %14, 1
tail call void @MSort(i32* %0, i32* %16, i32 %19, i32 %3, i32 %4)
%20 = tail call i32 @Merge(i32* %16, i32* %1, i32 %2, i32 %14, i32 %3)
br label %21
21: ; preds = %18, %12
%22 = tail call i32 @free(i32* %16)
br label %23
23: ; preds = %21, %7
ret void
}