#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*/ mergeAscending(int *, int *, int, int, int);
int /*<<< orphan*/ mergeDescending(int *, int *, int, int, int);
void splitAndMerge(int *tmp, int *array, int begin, int end, int asc) {
  int median;
  if (end - begin >= 1) {
    median = (begin + end) / 2;
    splitAndMerge(array, tmp, begin, median, asc);
    splitAndMerge(array, tmp, median + 1, end, asc);
    if (asc >= 1) {
      mergeAscending(tmp, array, begin, median, end);
    } else {
      mergeDescending(tmp, array, begin, median, end);
    }
  }
}


x86 assembly (clang, -O0):
<splitAndMerge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
cmp    $0x1,%eax
jl     11dd <splitAndMerge+0xad>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1040 <splitAndMerge@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1040 <splitAndMerge@plt>
cmpl   $0x1,-0x1c(%rbp)
jl     11c1 <splitAndMerge+0x91>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1030 <mergeAscending@plt>
jmp    11d8 <splitAndMerge+0xa8>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1050 <mergeDescending@plt>
jmp    11dd <splitAndMerge+0xad>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<splitAndMerge>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %edx,%ecx
jle    11a0 <splitAndMerge+0x70>
mov    %r8d,%r13d
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r12
lea    (%r14,%rbx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %rsi,%rdi
mov    %r12,%rsi
mov    %ebp,%ecx
call   1040 <splitAndMerge@plt>
lea    0x1(%rbp),%edx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14d,%ecx
mov    %r13d,%r8d
call   1040 <splitAndMerge@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r14d,%r8d
add    $0x8,%rsp
test   %r13d,%r13d
jle    11af <splitAndMerge+0x7f>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <mergeAscending@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <mergeDescending@plt>

LLVM IR (-O0):
define void @splitAndMerge(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
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
%12 = load i32, i32* %9
%13 = load i32, i32* %8
%14 = sub nsw i32 %12, %13
%15 = icmp sge i32 %14, 1
br i1 %15, label %16, label %49
16: ; preds = %5
%17 = load i32, i32* %8
%18 = load i32, i32* %9
%19 = add nsw i32 %17, %18
%20 = sdiv i32 %19, 2
store i32 %20, i32* %11
%21 = load i32*, i32** %7
%22 = load i32*, i32** %6
%23 = load i32, i32* %8
%24 = load i32, i32* %11
%25 = load i32, i32* %10
%26 = load i32*, i32** %7
%27 = load i32*, i32** %6
%28 = load i32, i32* %11
%29 = add nsw i32 %28, 1
%30 = load i32, i32* %9
%31 = load i32, i32* %10
%32 = load i32, i32* %10
%33 = icmp sge i32 %32, 1
br i1 %33, label %34, label %41
34: ; preds = %16
%35 = load i32*, i32** %6
%36 = load i32*, i32** %7
%37 = load i32, i32* %8
%38 = load i32, i32* %11
%39 = load i32, i32* %9
%40 = call i32 @mergeAscending(i32* %35, i32* %36, i32 %37, i32 %38, i32 %39)
br label %48
41: ; preds = %16
%42 = load i32*, i32** %6
%43 = load i32*, i32** %7
%44 = load i32, i32* %8
%45 = load i32, i32* %11
%46 = load i32, i32* %9
%47 = call i32 @mergeDescending(i32* %42, i32* %43, i32 %44, i32 %45, i32 %46)
br label %48
48: ; preds = %41, %34
br label %49
49: ; preds = %48, %5
ret void
}

LLVM IR (-O2):
define void @splitAndMerge(i32* %0, i32* %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp sgt i32 %3, %2
br i1 %6, label %7, label %16
7: ; preds = %5
%8 = add nsw i32 %3, %2
%9 = sdiv i32 %8, 2
tail call void @splitAndMerge(i32* %1, i32* %0, i32 %2, i32 %9, i32 %4)
%10 = add nsw i32 %9, 1
tail call void @splitAndMerge(i32* %1, i32* %0, i32 %10, i32 %3, i32 %4)
%11 = icmp sgt i32 %4, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @mergeAscending(i32* %0, i32* %1, i32 %2, i32 %9, i32 %3)
br label %16
14: ; preds = %7
%15 = tail call i32 @mergeDescending(i32* %0, i32* %1, i32 %2, i32 %9, i32 %3)
br label %16
16: ; preds = %12, %14, %5
ret void
}