#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 */
typedef int /*<<< orphan*/ int64_t;

/* Variables and functions */
int /*<<< orphan*/ merge(int /*<<< orphan*/ *, int /*<<< orphan*/ *, size_t,
                         size_t, size_t);
int /*<<< orphan*/ swap(int /*<<< orphan*/ **, int /*<<< orphan*/ **);
void split(int64_t *a, int64_t *b, size_t begin, size_t end, int threshold) {
  if (end - begin < 2)
    return;
  swap(&a, &b);
  size_t mid = (begin + end) / 2;
  split(a, b, begin, mid, threshold);
  split(a, b, mid, end, threshold);
  merge(a, b, begin, mid, end);
}


x86 assembly (clang, -O0):
<split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
cmp    $0x2,%rax
jae    1163 <split+0x33>
jmp    11cb <split+0x9b>
lea    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <swap@plt>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x24(%rbp),%r8d
call   1030 <split@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
call   1030 <split@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1040 <merge@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x10(%rsp)
mov    %rsi,0x8(%rsp)
mov    %rcx,%rax
sub    %rdx,%rax
cmp    $0x2,%rax
jb     11b7 <split+0x87>
mov    %r8d,%r15d
mov    %rcx,%r14
mov    %rdx,%rbx
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1050 <swap@plt>
lea    (%r14,%rbx,1),%rbp
shr    %rbp
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %r15d,%r8d
call   1030 <split@plt>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
mov    %r15d,%r8d
call   1030 <split@plt>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %r14,%r8
call   1040 <merge@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @split(i32* %0, i32* %1, i64 %2, i64 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i64
store i32* %0, i32** %6
store i32* %1, i32** %7
store i64 %2, i64* %8
store i64 %3, i64* %9
store i32 %4, i32* %10
%12 = load i64, i64* %9
%13 = load i64, i64* %8
%14 = sub i64 %12, %13
%15 = icmp ult i64 %14, 2
br i1 %15, label %16, label %17
16: ; preds = %5
br label %39
17: ; preds = %5
%18 = call i32 @swap(i32** %6, i32** %7)
%19 = load i64, i64* %8
%20 = load i64, i64* %9
%21 = add i64 %19, %20
%22 = udiv i64 %21, 2
store i64 %22, i64* %11
%23 = load i32*, i32** %6
%24 = load i32*, i32** %7
%25 = load i64, i64* %8
%26 = load i64, i64* %11
%27 = load i32, i32* %10
%28 = load i32*, i32** %6
%29 = load i32*, i32** %7
%30 = load i64, i64* %11
%31 = load i64, i64* %9
%32 = load i32, i32* %10
%33 = load i32*, i32** %6
%34 = load i32*, i32** %7
%35 = load i64, i64* %8
%36 = load i64, i64* %11
%37 = load i64, i64* %9
%38 = call i32 @merge(i32* %33, i32* %34, i64 %35, i64 %36, i64 %37)
br label %39
39: ; preds = %17, %16
ret void
}

LLVM IR (-O2):
define void @split(i32* %0, i32* %1, i64 %2, i64 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32*
store i32* %0, i32** %6
store i32* %1, i32** %7
%8 = sub i64 %3, %2
%9 = icmp ult i64 %8, 2
br i1 %9, label %21, label %10
10: ; preds = %5
%11 = call i32 @swap(i32** %6, i32** %7)
%12 = add i64 %3, %2
%13 = lshr i64 %12, 1
%14 = load i32*, i32** %6
%15 = load i32*, i32** %7
%16 = load i32*, i32** %6
%17 = load i32*, i32** %7
%18 = load i32*, i32** %6
%19 = load i32*, i32** %7
%20 = call i32 @merge(i32* %18, i32* %19, i64 %2, i64 %13, i64 %3)
br label %21
21: ; preds = %5, %10
ret void
}