#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*/ mergei(int *, int, int, int, int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ printvi(int *, int);
int /*<<< orphan*/ printvinl(int *, int);
int /*<<< orphan*/ putchar(char);
void top_down_merge_sorti_impl(int arr[], int lb, int ub, int temp[],
                               int level) {
  int mid;
  assert(arr != NULL && lb >= 0 && lb <= ub && temp != NULL);
  {
    int i;
    for (i = 0; i < level * 4; i++)
      putchar(' ');
  };
  printf("Sort: ");
  printvinl(arr + lb, ub - lb);
  if (ub - lb < 2)
    return;
  mid = (lb + ub) / 2;
  top_down_merge_sorti_impl(temp, lb, mid, arr, level + 1);
  top_down_merge_sorti_impl(temp, mid, ub, arr, level + 1);
  {
    int i;
    for (i = 0; i < level * 4; i++)
      putchar(' ');
  };
  printf("Merge: ");
  printvi(arr + lb, mid - lb);
  printf(" + ");
  printvi(arr + mid, ub - mid);
  mergei(arr, lb, mid, ub, temp);
  printf(" -> ");
  printvinl(temp + lb, ub - lb);
}


x86 assembly (clang, -O0):
<top_down_merge_sorti_impl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x29(%rbp)
je     11c5 <top_down_merge_sorti_impl+0x55>
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x29(%rbp)
jl     11c5 <top_down_merge_sorti_impl+0x55>
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
cmp    -0x10(%rbp),%ecx
mov    %al,-0x29(%rbp)
jg     11c5 <top_down_merge_sorti_impl+0x55>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x1c(%rbp),%ecx
shl    $0x2,%ecx
cmp    %ecx,%eax
jge    1202 <top_down_merge_sorti_impl+0x92>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d9 <top_down_merge_sorti_impl+0x69>
lea    0xdf7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%esi
sub    -0xc(%rbp),%esi
call   1090 <printvinl@plt>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0x2,%eax
jge    123c <top_down_merge_sorti_impl+0xcc>
jmp    133b <top_down_merge_sorti_impl+0x1cb>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
add    $0x1,%r8d
call   1070 <top_down_merge_sorti_impl@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
add    $0x1,%r8d
call   1070 <top_down_merge_sorti_impl@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x1c(%rbp),%ecx
shl    $0x2,%ecx
cmp    %ecx,%eax
jge    12b3 <top_down_merge_sorti_impl+0x143>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    128a <top_down_merge_sorti_impl+0x11a>
lea    0xd4d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%esi
sub    -0xc(%rbp),%esi
call   1080 <printvi@plt>
lea    0xd2f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
movslq -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%esi
sub    -0x20(%rbp),%esi
call   1080 <printvi@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%r8
call   1050 <mergei@plt>
lea    0xcf7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%esi
sub    -0xc(%rbp),%esi
call   1090 <printvinl@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<top_down_merge_sorti_impl>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8d,%ebp
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%r13
test   %rdi,%rdi
setne  %dl
test   %esi,%esi
setns  %al
and    %dl,%al
mov    %r15d,%ebx
sub    %esi,%ebx
setge  %sil
mov    %rcx,0x18(%rsp)
test   %rcx,%rcx
setne  %dl
and    %sil,%dl
and    %al,%dl
movzbl %dl,%edi
call   1060 <assert@plt>
lea    0x0(,%rbp,4),%eax
mov    %eax,0x8(%rsp)
mov    %rbp,0x10(%rsp)
test   %ebp,%ebp
jle    11ef <top_down_merge_sorti_impl+0x7f>
mov    0x8(%rsp),%eax
cmp    $0x2,%eax
mov    $0x1,%ebp
cmovge %eax,%ebp
nopl   0x0(%rax,%rax,1)
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    11e0 <top_down_merge_sorti_impl+0x70>
lea    0xe0a(%rip),%rdi
call   1040 <printf@plt>
movslq %r12d,%rbp
lea    0x0(,%rbp,4),%r14
add    %r13,%r14
mov    %r14,%rdi
mov    %ebx,%esi
call   1090 <printvinl@plt>
cmp    $0x2,%ebx
jge    1227 <top_down_merge_sorti_impl+0xb7>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,0x20(%rsp)
mov    %rbp,0x28(%rsp)
mov    %ebx,0xc(%rsp)
lea    (%r15,%r12,1),%eax
mov    0x18(%rsp),%rbp
mov    %eax,%r14d
shr    $0x1f,%r14d
add    %eax,%r14d
sar    %r14d
mov    %r13,%rbx
mov    0x10(%rsp),%rax
lea    0x1(%rax),%r13d
mov    %rbp,%rdi
mov    %r12d,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
mov    %r13d,%r8d
call   1070 <top_down_merge_sorti_impl@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %r15,0x30(%rsp)
mov    %r15d,%edx
mov    %rbx,%r15
mov    %rbx,%rcx
mov    %r13d,%r8d
call   1070 <top_down_merge_sorti_impl@plt>
cmpl   $0x0,0x10(%rsp)
jle    12af <top_down_merge_sorti_impl+0x13f>
mov    0x8(%rsp),%eax
cmp    $0x2,%eax
mov    $0x1,%ebp
cmovge %eax,%ebp
nopl   (%rax)
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    12a0 <top_down_merge_sorti_impl+0x130>
lea    0xd51(%rip),%rdi
call   1040 <printf@plt>
mov    %r14d,%esi
sub    %r12d,%esi
mov    0x20(%rsp),%rdi
call   1080 <printvi@plt>
lea    0xd3d(%rip),%rdi
call   1040 <printf@plt>
movslq %r14d,%rax
lea    (%r15,%rax,4),%rdi
mov    0x30(%rsp),%rbp
mov    %ebp,%esi
sub    %r14d,%esi
call   1080 <printvi@plt>
mov    %r15,%rdi
mov    %r12d,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
mov    0x18(%rsp),%rbx
mov    %rbx,%r8
call   1050 <mergei@plt>
lea    0xd07(%rip),%rdi
call   1040 <printf@plt>
mov    0x28(%rsp),%rax
lea    (%rbx,%rax,4),%rdi
mov    0xc(%rsp),%esi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <printvinl@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"Sort: \00"
@.str.1 = [8 x i8] c"Merge: \00"
@.str.2 = [4 x i8] c" + \00"
@.str.3 = [5 x i8] c" -> \00"
define void @top_down_merge_sorti_impl(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
%13 = 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
%14 = load i32*, i32** %6
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %26
16: ; preds = %5
%17 = load i32, i32* %7
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i32, i32* %7
%21 = load i32, i32* %8
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32*, i32** %9
%25 = icmp ne i32* %24, null
br label %26
26: ; preds = %23, %19, %16, %5
%27 = phi i1 [ false, %19 ], [ false, %16 ], [ false, %5 ], [ %25, %23 ]
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
store i32 0, i32* %12
br label %30
30: ; preds = %37, %26
%31 = load i32, i32* %12
%32 = load i32, i32* %10
%33 = mul nsw i32 %32, 4
%34 = icmp slt i32 %31, %33
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = call i32 @putchar(i8 signext 32)
br label %37
37: ; preds = %35
%38 = load i32, i32* %12
%39 = add nsw i32 %38, 1
store i32 %39, i32* %12
br label %30
40: ; preds = %30
%41 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%42 = load i32*, i32** %6
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
%46 = load i32, i32* %8
%47 = load i32, i32* %7
%48 = sub nsw i32 %46, %47
%49 = call i32 @printvinl(i32* %45, i32 %48)
%50 = load i32, i32* %8
%51 = load i32, i32* %7
%52 = sub nsw i32 %50, %51
%53 = icmp slt i32 %52, 2
br i1 %53, label %54, label %55
54: ; preds = %40
br label %116
55: ; preds = %40
%56 = load i32, i32* %7
%57 = load i32, i32* %8
%58 = add nsw i32 %56, %57
%59 = sdiv i32 %58, 2
store i32 %59, i32* %11
%60 = load i32*, i32** %9
%61 = load i32, i32* %7
%62 = load i32, i32* %11
%63 = load i32*, i32** %6
%64 = load i32, i32* %10
%65 = add nsw i32 %64, 1
%66 = load i32*, i32** %9
%67 = load i32, i32* %11
%68 = load i32, i32* %8
%69 = load i32*, i32** %6
%70 = load i32, i32* %10
%71 = add nsw i32 %70, 1
store i32 0, i32* %13
br label %72
72: ; preds = %79, %55
%73 = load i32, i32* %13
%74 = load i32, i32* %10
%75 = mul nsw i32 %74, 4
%76 = icmp slt i32 %73, %75
br i1 %76, label %77, label %82
77: ; preds = %72
%78 = call i32 @putchar(i8 signext 32)
br label %79
79: ; preds = %77
%80 = load i32, i32* %13
%81 = add nsw i32 %80, 1
store i32 %81, i32* %13
br label %72
82: ; preds = %72
%83 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%84 = load i32*, i32** %6
%85 = load i32, i32* %7
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i32, i32* %84, i64 %86
%88 = load i32, i32* %11
%89 = load i32, i32* %7
%90 = sub nsw i32 %88, %89
%91 = call i32 @printvi(i32* %87, i32 %90)
%92 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%93 = load i32*, i32** %6
%94 = load i32, i32* %11
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i32, i32* %93, i64 %95
%97 = load i32, i32* %8
%98 = load i32, i32* %11
%99 = sub nsw i32 %97, %98
%100 = call i32 @printvi(i32* %96, i32 %99)
%101 = load i32*, i32** %6
%102 = load i32, i32* %7
%103 = load i32, i32* %11
%104 = load i32, i32* %8
%105 = load i32*, i32** %9
%106 = call i32 @mergei(i32* %101, i32 %102, i32 %103, i32 %104, i32* %105)
%107 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%108 = load i32*, i32** %9
%109 = load i32, i32* %7
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i32, i32* %108, i64 %110
%112 = load i32, i32* %8
%113 = load i32, i32* %7
%114 = sub nsw i32 %112, %113
%115 = call i32 @printvinl(i32* %111, i32 %114)
br label %116
116: ; preds = %82, %54
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"Sort: \00"
@.str.1 = [8 x i8] c"Merge: \00"
@.str.2 = [4 x i8] c" + \00"
@.str.3 = [5 x i8] c" -> \00"
define void @top_down_merge_sorti_impl(i32* %0, i32 %1, i32 %2, i32* %3, i32 %4) {
%6 = icmp eq i32* %0, null
%7 = icmp slt i32 %1, 0
%8 = or i1 %6, %7
%9 = icmp slt i32 %2, %1
%10 = or i1 %8, %9
%11 = icmp ne i32* %3, null
%12 = xor i1 %10, true
%13 = and i1 %11, %12
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
%16 = shl i32 %4, 2
%17 = icmp sgt i32 %4, 0
br i1 %17, label %18, label %25
18: ; preds = %5
%19 = call i32 @llvm.smax.i32(i32 %16, i32 1)
br label %20
20: ; preds = %18, %20
%21 = phi i32 [ %23, %20 ], [ 0, %18 ]
%22 = tail call i32 @putchar(i8 signext 32)
%23 = add nuw nsw i32 %21, 1
%24 = icmp eq i32 %23, %19
br i1 %24, label %25, label %20
25: ; preds = %20, %5
%26 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%27 = sext i32 %1 to i64
%28 = getelementptr inbounds i32, i32* %0, i64 %27
%29 = sub nsw i32 %2, %1
%30 = tail call i32 @printvinl(i32* %28, i32 %29)
%31 = icmp slt i32 %29, 2
br i1 %31, label %56, label %32
32: ; preds = %25
%33 = add nsw i32 %2, %1
%34 = sdiv i32 %33, 2
%35 = add nsw i32 %4, 1
tail call void @top_down_merge_sorti_impl(i32* %3, i32 %1, i32 %34, i32* %0, i32 %35)
tail call void @top_down_merge_sorti_impl(i32* %3, i32 %34, i32 %2, i32* %0, i32 %35)
br i1 %17, label %36, label %43
36: ; preds = %32
%37 = call i32 @llvm.smax.i32(i32 %16, i32 1)
br label %38
38: ; preds = %36, %38
%39 = phi i32 [ %41, %38 ], [ 0, %36 ]
%40 = tail call i32 @putchar(i8 signext 32)
%41 = add nuw nsw i32 %39, 1
%42 = icmp eq i32 %41, %37
br i1 %42, label %43, label %38
43: ; preds = %38, %32
%44 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%45 = sub nsw i32 %34, %1
%46 = tail call i32 @printvi(i32* %28, i32 %45)
%47 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%48 = sext i32 %34 to i64
%49 = getelementptr inbounds i32, i32* %0, i64 %48
%50 = sub nsw i32 %2, %34
%51 = tail call i32 @printvi(i32* %49, i32 %50)
%52 = tail call i32 @mergei(i32* %0, i32 %1, i32 %34, i32 %2, i32* %3)
%53 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%54 = getelementptr inbounds i32, i32* %3, i64 %27
%55 = tail call i32 @printvinl(i32* %54, i32 %29)
br label %56
56: ; preds = %25, %43
ret void
}