#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*/ CopyArray(unsigned int *, int, int, unsigned int *);
int /*<<< orphan*/ TopDownMerge(unsigned int *, int, int, int, unsigned int *);
void TopDownSplitMerge(unsigned int A[], int iBegin, int iEnd,
                       unsigned int B[]) {
  int iMiddle;
  if (iEnd - iBegin < 2)
    return;
  iMiddle = (iEnd + iBegin) / 2;
  TopDownSplitMerge(A, iBegin, iMiddle, B);
  TopDownSplitMerge(A, iMiddle, iEnd, B);
  TopDownMerge(A, iBegin, iMiddle, iEnd, B);
  CopyArray(B, iBegin, iEnd, A);
}


x86 assembly (clang, -O0):
<TopDownSplitMerge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0x2,%eax
jge    115a <TopDownSplitMerge+0x2a>
jmp    11ba <TopDownSplitMerge+0x8a>
mov    -0x10(%rbp),%eax
add    -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   1030 <TopDownSplitMerge@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1030 <TopDownSplitMerge@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%r8
call   1050 <TopDownMerge@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rcx
call   1040 <CopyArray@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TopDownSplitMerge>:
mov    %edx,%eax
sub    %esi,%eax
cmp    $0x1,%eax
jg     113a <TopDownSplitMerge+0xa>
ret
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%r14
lea    (%r12,%rbx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %ebp,%edx
call   1030 <TopDownSplitMerge@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r15,%rcx
call   1030 <TopDownSplitMerge@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r12d,%ecx
mov    %r15,%r8
call   1050 <TopDownMerge@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r14,%rcx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <CopyArray@plt>

LLVM IR (-O0):
define void @TopDownSplitMerge(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
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = sub nsw i32 %10, %11
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %15
14: ; preds = %4
br label %39
15: ; preds = %4
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = add nsw i32 %16, %17
%19 = sdiv i32 %18, 2
store i32 %19, i32* %9
%20 = load i32*, i32** %5
%21 = load i32, i32* %6
%22 = load i32, i32* %9
%23 = load i32*, i32** %8
%24 = load i32*, i32** %5
%25 = load i32, i32* %9
%26 = load i32, i32* %7
%27 = load i32*, i32** %8
%28 = load i32*, i32** %5
%29 = load i32, i32* %6
%30 = load i32, i32* %9
%31 = load i32, i32* %7
%32 = load i32*, i32** %8
%33 = call i32 @TopDownMerge(i32* %28, i32 %29, i32 %30, i32 %31, i32* %32)
%34 = load i32*, i32** %8
%35 = load i32, i32* %6
%36 = load i32, i32* %7
%37 = load i32*, i32** %5
%38 = call i32 @CopyArray(i32* %34, i32 %35, i32 %36, i32* %37)
br label %39
39: ; preds = %15, %14
ret void
}

LLVM IR (-O2):
define void @TopDownSplitMerge(i32* %0, i32 %1, i32 %2, i32* %3) {
%5 = sub nsw i32 %2, %1
%6 = icmp slt i32 %5, 2
br i1 %6, label %7, label %8
7: ; preds = %4, %8
ret void
8: ; preds = %4
%9 = add nsw i32 %2, %1
%10 = sdiv i32 %9, 2
tail call void @TopDownSplitMerge(i32* %0, i32 %1, i32 %10, i32* %3)
tail call void @TopDownSplitMerge(i32* %0, i32 %10, i32 %2, i32* %3)
%11 = tail call i32 @TopDownMerge(i32* %0, i32 %1, i32 %10, i32 %2, i32* %3)
%12 = tail call i32 @CopyArray(i32* %3, i32 %1, i32 %2, i32* %0)
br label %7
}