#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*/ assert(int);
int /*<<< orphan*/ merge(int *, int, int, int);
int /*<<< orphan*/ print_array(int *, int);
int /*<<< orphan*/ printf(char *, int, int);
void merge_sort(int *arr, int l, int r) {
  assert(arr && "arr argument can not be null");
  printf("\nMerge_sort(l=%d, r=%d)", l, r);
  print_array(arr, 5);
  if (l >= r) {
    return;
  }
  int m = l + (r - l) / 2;
  merge_sort(arr, l, m);
  merge_sort(arr, m + 1, r);
  merge(arr, l, m, r);
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x15(%rbp)
je     117c <merge_sort+0x2c>
mov    $0x1,%al
mov    %al,-0x15(%rbp)
jmp    117c <merge_sort+0x2c>
mov    -0x15(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x5,%esi
call   1030 <print_array@plt>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     11ba <merge_sort+0x6a>
jmp    120b <merge_sort+0xbb>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1070 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1070 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1060 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebx
mov    %rdi,%r12
xor    %edi,%edi
test   %r12,%r12
setne  %dil
call   1050 <assert@plt>
lea    0xe8b(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
call   1040 <printf@plt>
mov    %r12,%rdi
mov    $0x5,%esi
call   1030 <print_array@plt>
mov    %r14d,%eax
sub    %ebx,%eax
jle    11d6 <merge_sort+0x86>
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
lea    (%rbx,%rbp,1),%r15d
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
call   1070 <merge_sort@plt>
lea    (%rbx,%rbp,1),%esi
add    $0x1,%esi
mov    %r12,%rdi
mov    %r14d,%edx
call   1070 <merge_sort@plt>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <merge@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"arr argument can not be null\00"
@.str.1 = [24 x i8] c"\0AMerge_sort(l=%d, r=%d)\00"
define void @merge_sort(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %3
br label %11
11: ; preds = %10, %3
%12 = phi i1 [ false, %3 ], [ true, %10 ]
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %16)
%18 = load i32*, i32** %4
%19 = call i32 @print_array(i32* %18, i32 5)
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = icmp sge i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %11
br label %43
24: ; preds = %11
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = load i32, i32* %5
%28 = sub nsw i32 %26, %27
%29 = sdiv i32 %28, 2
%30 = add nsw i32 %25, %29
store i32 %30, i32* %7
%31 = load i32*, i32** %4
%32 = load i32, i32* %5
%33 = load i32, i32* %7
%34 = load i32*, i32** %4
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
%37 = load i32, i32* %6
%38 = load i32*, i32** %4
%39 = load i32, i32* %5
%40 = load i32, i32* %7
%41 = load i32, i32* %6
%42 = call i32 @merge(i32* %38, i32 %39, i32 %40, i32 %41)
br label %43
43: ; preds = %24, %23
ret void
}

LLVM IR (-O2):
@.str.1 = [24 x i8] c"\0AMerge_sort(l=%d, r=%d)\00"
define void @merge_sort(i32* %0, i32 %1, i32 %2) {
%4 = icmp ne i32* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %2)
%8 = tail call i32 @print_array(i32* %0, i32 5)
%9 = icmp sgt i32 %2, %1
br i1 %9, label %11, label %10
10: ; preds = %3, %11
ret void
11: ; preds = %3
%12 = sub nsw i32 %2, %1
%13 = sdiv i32 %12, 2
%14 = add nsw i32 %13, %1
tail call void @merge_sort(i32* %0, i32 %1, i32 %14)
%15 = add nsw i32 %14, 1
tail call void @merge_sort(i32* %0, i32 %15, i32 %2)
%16 = tail call i32 @merge(i32* %0, i32 %1, i32 %14, i32 %2)
br label %10
}