#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);
scalar_t__ malloc(int);
void MergeSort(int *source, int *target, int s, int t) {
  int m, *temp;
  if (s == t) {
    target[s] = source[s];
  } else {
    temp = (int *)malloc(sizeof(int) * (t - s + 1));
    m = (s + t) / 2;
    MergeSort(source, temp, s, m);
    MergeSort(source, temp, m + 1, t);
    Merge(temp, target, s, m, t);
  }
}


x86 assembly (clang, -O0):
<MergeSort>:
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    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    116d <MergeSort+0x3d>
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    11d8 <MergeSort+0xa8>
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1050 <MergeSort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
call   1050 <MergeSort@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1030 <Merge@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MergeSort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rsi,%r14
mov    %rdi,%r12
mov    %ecx,%eax
sub    %edx,%eax
jne    1163 <MergeSort+0x33>
movslq %ebx,%rax
mov    (%r12,%rax,4),%ecx
mov    %ecx,(%r14,%rax,4)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edx,%r15d
lea    0x4(,%rax,4),%edi
call   1040 <malloc@plt>
mov    %rax,%r13
lea    (%rbx,%r15,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
mov    %ebp,%ecx
call   1050 <MergeSort@plt>
lea    0x1(%rbp),%edx
mov    %r12,%rdi
mov    %r13,%rsi
mov    %ebx,%ecx
call   1050 <MergeSort@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    %ebx,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <Merge@plt>

LLVM IR (-O0):
define void @MergeSort(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32, i32* %7
%12 = load i32, i32* %8
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %24
14: ; preds = %4
%15 = load i32*, i32** %5
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = load i32*, i32** %6
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
store i32 %19, i32* %23
br label %53
24: ; preds = %4
%25 = load i32, i32* %8
%26 = load i32, i32* %7
%27 = sub nsw i32 %25, %26
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = mul i64 4, %29
%31 = trunc i64 %30 to i32
%32 = call i64 @malloc(i32 %31)
%33 = inttoptr i64 %32 to i32*
store i32* %33, i32** %10
%34 = load i32, i32* %7
%35 = load i32, i32* %8
%36 = add nsw i32 %34, %35
%37 = sdiv i32 %36, 2
store i32 %37, i32* %9
%38 = load i32*, i32** %5
%39 = load i32*, i32** %10
%40 = load i32, i32* %7
%41 = load i32, i32* %9
%42 = load i32*, i32** %5
%43 = load i32*, i32** %10
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
%46 = load i32, i32* %8
%47 = load i32*, i32** %10
%48 = load i32*, i32** %6
%49 = load i32, i32* %7
%50 = load i32, i32* %9
%51 = load i32, i32* %8
%52 = call i32 @Merge(i32* %47, i32* %48, i32 %49, i32 %50, i32 %51)
br label %53
53: ; preds = %24, %14
ret void
}

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