#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*/ MergeSort(int *, int /*<<< orphan*/, int, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int test2(int arr[], int length) {
  for (int i = 0; i < length; i++) {
    printf("%4d", arr[i]);
  }
  printf("\n");
  int *temp = (int *)malloc(sizeof(int) * length);
  memset(temp, 0, length);
  MergeSort(arr, 0, length - 1, temp);
  for (int i = 0; i < length; i++) {
    printf("%4d", arr[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<test2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1189 <test2+0x49>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1156 <test2+0x16>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
mov    -0x18(%rbp),%rcx
xor    %esi,%esi
call   1060 <MergeSort@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1207 <test2+0xc7>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d4 <test2+0x94>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test2>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
test   %esi,%esi
jle    11f9 <test2+0xa9>
mov    %r14d,%r13d
lea    0xe8f(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1180 <test2+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x0(,%r14,4),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1050 <memset@plt>
lea    -0x1(%r14),%edx
mov    %r12,%rdi
xor    %esi,%esi
mov    %r15,%rcx
call   1070 <MergeSort@plt>
test   %r14d,%r14d
jle    1234 <test2+0xe4>
lea    0xe25(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11e0 <test2+0x90>
jmp    1234 <test2+0xe4>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x0(,%r14,4),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1050 <memset@plt>
add    $0xffffffff,%r14d
mov    %r12,%rdi
xor    %esi,%esi
mov    %r14d,%edx
mov    %r15,%rcx
call   1070 <MergeSort@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%4d\00"
define i32 @test2(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %23
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %16
6: ; preds = %16
%7 = tail call i32 @putchar(i32 10)
%8 = shl i32 %1, 2
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i32*
%11 = tail call i32 @memset(i32* %10, i32 0, i32 %1)
%12 = add nsw i32 %1, -1
%13 = tail call i32 @MergeSort(i32* %0, i32 0, i32 %12, i32* %10)
br i1 %3, label %14, label %31
14: ; preds = %6
%15 = zext i32 %1 to i64
br label %33
16: ; preds = %4, %16
%17 = phi i64 [ 0, %4 ], [ %21, %16 ]
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = load i32, i32* %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = add nuw nsw i64 %17, 1
%22 = icmp eq i64 %21, %5
br i1 %22, label %6, label %16
23: ; preds = %2
%24 = tail call i32 @putchar(i32 10)
%25 = shl i32 %1, 2
%26 = tail call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i32*
%28 = tail call i32 @memset(i32* %27, i32 0, i32 %1)
%29 = add nsw i32 %1, -1
%30 = tail call i32 @MergeSort(i32* %0, i32 0, i32 %29, i32* %27)
br label %31
31: ; preds = %33, %23, %6
%32 = tail call i32 @putchar(i32 10)
ret i32 0
33: ; preds = %14, %33
%34 = phi i64 [ 0, %14 ], [ %38, %33 ]
%35 = getelementptr inbounds i32, i32* %0, i64 %34
%36 = load i32, i32* %35
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %36)
%38 = add nuw nsw i64 %34, 1
%39 = icmp eq i64 %38, %15
br i1 %39, label %31, label %33
}