#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*/ merge(int *, int *, int);
void split_and_merge(int *tmp, int *src, int n) {
  if (n == 1) {
    return;
  }
  int first_half = n / 2;
  int last_half = first_half + n % 2;
  split_and_merge(tmp, src, first_half);
  split_and_merge(tmp, src + first_half, last_half);
  merge(tmp, src, n);
}


x86 assembly (clang, -O0):
<split_and_merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1142 <split_and_merge+0x22>
jmp    11a4 <split_and_merge+0x84>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <split_and_merge@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
call   1030 <split_and_merge@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_and_merge>:
cmp    $0x1,%edx
jne    1126 <split_and_merge+0x6>
ret
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%ebp
shr    $0x1f,%ebp
add    %edx,%ebp
mov    %ebp,%eax
and    $0xfffffffe,%eax
mov    %edx,%ebx
sub    %eax,%ebx
sar    %ebp
add    %ebp,%ebx
mov    %ebp,%edx
call   1030 <split_and_merge@plt>
movslq %ebp,%rax
lea    (%r14,%rax,4),%rsi
mov    %r15,%rdi
mov    %ebx,%edx
call   1030 <split_and_merge@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <merge@plt>

LLVM IR (-O0):
define void @split_and_merge(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %3
br label %32
12: ; preds = %3
%13 = load i32, i32* %6
%14 = sdiv i32 %13, 2
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = load i32, i32* %6
%17 = srem i32 %16, 2
%18 = add nsw i32 %15, %17
store i32 %18, i32* %8
%19 = load i32*, i32** %4
%20 = load i32*, i32** %5
%21 = load i32, i32* %7
%22 = load i32*, i32** %4
%23 = load i32*, i32** %5
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %8
%28 = load i32*, i32** %4
%29 = load i32*, i32** %5
%30 = load i32, i32* %6
%31 = call i32 @merge(i32* %28, i32* %29, i32 %30)
br label %32
32: ; preds = %12, %11
ret void
}

LLVM IR (-O2):
define void @split_and_merge(i32* %0, i32* %1, i32 %2) {
%4 = icmp eq i32 %2, 1
br i1 %4, label %5, label %6
5: ; preds = %3, %6
ret void
6: ; preds = %3
%7 = sdiv i32 %2, 2
%8 = srem i32 %2, 2
%9 = add nsw i32 %7, %8
tail call void @split_and_merge(i32* %0, i32* %1, i32 %7)
%10 = sext i32 %7 to i64
%11 = getelementptr inbounds i32, i32* %1, i64 %10
tail call void @split_and_merge(i32* %0, i32* %11, i32 %9)
%12 = tail call i32 @merge(i32* %0, i32* %1, i32 %2)
br label %5
}