void msort(int *array, int *tmp_array, int left, int right) {
  if (!array || !tmp_array) {
    printf("You passed NULL in function %s()\n", __FUNCTION__);
    return;
  }
  if (left > right) {
    printf("left %d bigger than right %d\n", left, right);
  }
  int center = 0;
  if (left < right) {
    center = (left + right) / 2;
    msort(array, tmp_array, left, center);
    msort(array, tmp_array, center + 1, right);
    merge(array, tmp_array, left, center + 1, right);
  }
}


x86 assembly (clang, -O0):
<msort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     115c <msort+0x2c>
cmpq   $0x0,-0x10(%rbp)
jne    1176 <msort+0x46>
lea    0xe9d(%rip),%rdi
lea    0xeb8(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ff <msort+0xcf>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1196 <msort+0x66>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11ff <msort+0xcf>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1030 <msort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
call   1030 <msort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%r8d
mov    $0x0,%al
call   1050 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     11b4 <msort+0x84>
mov    %rsi,%r15
test   %rsi,%rsi
je     11b4 <msort+0x84>
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %rdi,%r12
cmp    %ecx,%edx
jle    1164 <msort+0x34>
lea    0xed0(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %r14d,%ebx
jge    11d1 <msort+0xa1>
lea    (%r14,%rbx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1030 <msort@plt>
add    $0x1,%ebp
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1030 <msort@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <merge@plt>
lea    0xe45(%rip),%rdi
lea    0xe60(%rip),%rsi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"You passed NULL in function %s()\0A\00"
@__FUNCTION__.msort = [6 x i8] c"msort\00"
@.str.1 = [30 x i8] c"left %d bigger than right %d\0A\00"
define void @msort(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = load i32*, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %17, label %15
15: ; preds = %12, %4
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__FUNCTION__.msort, i64 0, i64 0))
br label %50
17: ; preds = %12
%18 = load i32, i32* %7
%19 = load i32, i32* %8
%20 = icmp sgt i32 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i32, i32* %7
%23 = load i32, i32* %8
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %23)
br label %25
25: ; preds = %21, %17
store i32 0, i32* %9
%26 = load i32, i32* %7
%27 = load i32, i32* %8
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %50
29: ; preds = %25
%30 = load i32, i32* %7
%31 = load i32, i32* %8
%32 = add nsw i32 %30, %31
%33 = sdiv i32 %32, 2
store i32 %33, i32* %9
%34 = load i32*, i32** %5
%35 = load i32*, i32** %6
%36 = load i32, i32* %7
%37 = load i32, i32* %9
%38 = load i32*, i32** %5
%39 = load i32*, i32** %6
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
%42 = load i32, i32* %8
%43 = load i32*, i32** %5
%44 = load i32*, i32** %6
%45 = load i32, i32* %7
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
%48 = load i32, i32* %8
%49 = call i32 (i32*, i32*, i32, i32, i32, ...) bitcast (i32 (...)* @merge to i32 (i32*, i32*, i32, i32, i32, ...)*)(i32* %43, i32* %44, i32 %45, i32 %47, i32 %48)
br label %50
50: ; preds = %15, %29, %25
ret void
}

LLVM IR (-O2):
@.str = [34 x i8] c"You passed NULL in function %s()\0A\00"
@__FUNCTION__.msort = [6 x i8] c"msort\00"
@.str.1 = [30 x i8] c"left %d bigger than right %d\0A\00"
define void @msort(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = icmp ne i32* %0, null
%6 = icmp ne i32* %1, null
%7 = and i1 %5, %6
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__FUNCTION__.msort, i64 0, i64 0))
br label %16
10: ; preds = %4
%11 = icmp sgt i32 %2, %3
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %3)
br label %14
14: ; preds = %12, %10
%15 = icmp slt i32 %2, %3
br i1 %15, label %17, label %16
16: ; preds = %8, %14, %17
ret void
17: ; preds = %14
%18 = add nsw i32 %3, %2
%19 = sdiv i32 %18, 2
tail call void @msort(i32* %0, i32* %1, i32 %2, i32 %19)
%20 = add nsw i32 %19, 1
tail call void @msort(i32* %0, i32* %1, i32 %20, i32 %3)
%21 = tail call i32 (i32*, i32*, i32, i32, i32, ...) bitcast (i32 (...)* @merge to i32 (i32*, i32*, i32, i32, i32, ...)*)(i32* %0, i32* %1, i32 %2, i32 %20, i32 %3)
br label %16
}