#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*/ copy(int *, int, int, int *);
int /*<<< orphan*/ display(int *, int);
int /*<<< orphan*/ merge(int *, int, int, int, int *);
int /*<<< orphan*/ printf(char *);
void split_merge(int a[], int start, int end, int b[]) {
  int mid = 0;
  printf("split_merge: a = ");
  display(a, end - start);
  if (end - start < 2) {
    printf("split_merge: already sorted\n");
    return;
  }
  mid = (end - start) / 2;
  split_merge(a, start, mid, b);
  split_merge(a, mid, end, b);
  merge(a, start, mid, end, b);
  copy(b, start, end, a);
}


x86 assembly (clang, -O0):
<split_merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
sub    -0xc(%rbp),%esi
call   1030 <display@plt>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0x2,%eax
jge    11a8 <split_merge+0x58>
lea    0xe74(%rip),%rdi
call   1040 <printf@plt>
jmp    1208 <split_merge+0xb8>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1060 <split_merge@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1060 <split_merge@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%r8
call   1070 <merge@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rcx
call   1050 <copy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_merge>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%rbx
lea    0xe85(%rip),%rdi
call   1050 <printf@plt>
mov    %r15d,%ebp
sub    %r12d,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <display@plt>
cmp    $0x1,%ebp
jg     11a9 <split_merge+0x49>
lea    0xe76(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
shr    %ebp
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1070 <split_merge@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %r14,%rcx
call   1070 <split_merge@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
mov    %r15d,%ecx
mov    %r14,%r8
call   1080 <merge@plt>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
mov    %rbx,%rcx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <copy@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"split_merge: a = \00"
@.str.1 = [29 x i8] c"split_merge: already sorted\0A\00"
define void @split_merge(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
store i32 0, i32* %9
%10 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%11 = load i32*, i32** %5
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = sub nsw i32 %12, %13
%15 = call i32 @display(i32* %11, i32 %14)
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = sub nsw i32 %16, %17
%19 = icmp slt i32 %18, 2
br i1 %19, label %20, label %22
20: ; preds = %4
%21 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %46
22: ; preds = %4
%23 = load i32, i32* %7
%24 = load i32, i32* %6
%25 = sub nsw i32 %23, %24
%26 = sdiv i32 %25, 2
store i32 %26, i32* %9
%27 = load i32*, i32** %5
%28 = load i32, i32* %6
%29 = load i32, i32* %9
%30 = load i32*, i32** %8
%31 = load i32*, i32** %5
%32 = load i32, i32* %9
%33 = load i32, i32* %7
%34 = load i32*, i32** %8
%35 = load i32*, i32** %5
%36 = load i32, i32* %6
%37 = load i32, i32* %9
%38 = load i32, i32* %7
%39 = load i32*, i32** %8
%40 = call i32 @merge(i32* %35, i32 %36, i32 %37, i32 %38, i32* %39)
%41 = load i32*, i32** %8
%42 = load i32, i32* %6
%43 = load i32, i32* %7
%44 = load i32*, i32** %5
%45 = call i32 @copy(i32* %41, i32 %42, i32 %43, i32* %44)
br label %46
46: ; preds = %22, %20
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"split_merge: a = \00"
@str = [28 x i8] c"split_merge: already sorted\00"
define void @split_merge(i32* %0, i32 %1, i32 %2, i32* %3) {
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = sub nsw i32 %2, %1
%7 = tail call i32 @display(i32* %0, i32 %6)
%8 = icmp slt i32 %6, 2
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %11
11: ; preds = %9, %12
ret void
12: ; preds = %4
%13 = lshr i32 %6, 1
tail call void @split_merge(i32* %0, i32 %1, i32 %13, i32* %3)
tail call void @split_merge(i32* %0, i32 %13, i32 %2, i32* %3)
%14 = tail call i32 @merge(i32* %0, i32 %1, i32 %13, i32 %2, i32* %3)
%15 = tail call i32 @copy(i32* %3, i32 %1, i32 %2, i32* %0)
br label %11
}