#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*/ SwapInt(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ mergeInt(int *, int, int *, int, int *);
void mergeSortInt(int a[], int na) {
  if (na > 2) {
    int nb = na / 2;
    int nc = na - nb;
    int b[nb];
    int c[nc];
    memcpy(b, a, nb * sizeof(int));
    memcpy(c, a + nb, nc * sizeof(int));
    mergeSortInt(b, nb);
    mergeSortInt(c, nc);
    mergeInt(b, nb, c, nc, a);
  } else if (na == 2) {
    if (a[0] > a[1]) {
      SwapInt(a, 0, 1);
    }
  }
}


x86 assembly (clang, -O0):
<mergeSortInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jle    122a <mergeSortInt+0xea>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %ecx,%eax
sar    %eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1030 <mergeSortInt@plt>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <mergeSortInt@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%r8
call   1060 <mergeInt@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
jmp    1261 <mergeSortInt+0x121>
cmpl   $0x2,-0xc(%rbp)
jne    125c <mergeSortInt+0x11c>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
cmp    0x4(%rcx),%eax
jle    1257 <mergeSortInt+0x117>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1050 <SwapInt@plt>
jmp    125c <mergeSortInt+0x11c>
jmp    1261 <mergeSortInt+0x121>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergeSortInt>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
cmp    $0x3,%esi
jl     11e7 <mergeSortInt+0xa7>
mov    %rsp,-0x30(%rbp)
mov    %ebx,%r15d
shr    %r15d
sub    %r15d,%ebx
mov    %rsp,%r12
lea    0xf(,%r15,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xf(,%rbx,4),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r13
sub    %rax,%r13
mov    %r13,%rsp
lea    0x0(,%r15,4),%edx
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <memcpy@plt>
lea    (%r14,%r15,4),%rsi
lea    0x0(,%rbx,4),%edx
mov    %r13,%rdi
call   1040 <memcpy@plt>
mov    %r12,%rdi
mov    %r15d,%esi
call   1030 <mergeSortInt@plt>
mov    %r13,%rdi
mov    %ebx,%esi
call   1030 <mergeSortInt@plt>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r13,%rdx
mov    %ebx,%ecx
mov    %r14,%r8
call   1060 <mergeInt@plt>
mov    -0x30(%rbp),%rsp
jmp    1212 <mergeSortInt+0xd2>
cmp    $0x2,%ebx
jne    1212 <mergeSortInt+0xd2>
mov    (%r14),%eax
cmp    0x4(%r14),%eax
jle    1212 <mergeSortInt+0xd2>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1,%edx
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <SwapInt@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @mergeSortInt(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
store i32* %0, i32** %3
store i32 %1, i32* %4
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 2
br i1 %11, label %12, label %47
12: ; preds = %2
%13 = load i32, i32* %4
%14 = sdiv i32 %13, 2
store i32 %14, i32* %5
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = sub nsw i32 %15, %16
store i32 %17, i32* %6
%18 = load i32, i32* %5
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %7
%21 = alloca i32, i64 %19
store i64 %19, i64* %8
%22 = load i32, i32* %6
%23 = zext i32 %22 to i64
%24 = alloca i32, i64 %23
store i64 %23, i64* %9
%25 = load i32*, i32** %3
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 4
%29 = trunc i64 %28 to i32
%30 = call i32 @memcpy(i32* %21, i32* %25, i32 %29)
%31 = load i32*, i32** %3
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = mul i64 %36, 4
%38 = trunc i64 %37 to i32
%39 = call i32 @memcpy(i32* %24, i32* %34, i32 %38)
%40 = load i32, i32* %5
%41 = load i32, i32* %6
%42 = load i32, i32* %5
%43 = load i32, i32* %6
%44 = load i32*, i32** %3
%45 = call i32 @mergeInt(i32* %21, i32 %42, i32* %24, i32 %43, i32* %44)
%46 = load i8*, i8** %7
br label %63
47: ; preds = %2
%48 = load i32, i32* %4
%49 = icmp eq i32 %48, 2
br i1 %49, label %50, label %62
50: ; preds = %47
%51 = load i32*, i32** %3
%52 = getelementptr inbounds i32, i32* %51, i64 0
%53 = load i32, i32* %52
%54 = load i32*, i32** %3
%55 = getelementptr inbounds i32, i32* %54, i64 1
%56 = load i32, i32* %55
%57 = icmp sgt i32 %53, %56
br i1 %57, label %58, label %61
58: ; preds = %50
%59 = load i32*, i32** %3
%60 = call i32 @SwapInt(i32* %59, i32 0, i32 1)
br label %61
61: ; preds = %58, %50
br label %62
62: ; preds = %61, %47
br label %63
63: ; preds = %62, %12
ret void
}

LLVM IR (-O2):
define void @mergeSortInt(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 2
br i1 %3, label %4, label %18
4: ; preds = %2
%5 = lshr i32 %1, 1
%6 = sub nsw i32 %1, %5
%7 = zext i32 %5 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i32, i64 %7
%10 = zext i32 %6 to i64
%11 = alloca i32, i64 %10
%12 = shl nuw i32 %5, 2
%13 = call i32 @memcpy(i32* %9, i32* %0, i32 %12)
%14 = getelementptr inbounds i32, i32* %0, i64 %7
%15 = shl i32 %6, 2
%16 = call i32 @memcpy(i32* %11, i32* %14, i32 %15)
%17 = call i32 @mergeInt(i32* %9, i32 %5, i32* %11, i32 %6, i32* %0)
br label %27
18: ; preds = %2
%19 = icmp eq i32 %1, 2
br i1 %19, label %20, label %27
20: ; preds = %18
%21 = load i32, i32* %0
%22 = getelementptr inbounds i32, i32* %0, i64 1
%23 = load i32, i32* %22
%24 = icmp sgt i32 %21, %23
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = tail call i32 @SwapInt(i32* %0, i32 0, i32 1)
br label %27
27: ; preds = %18, %25, %20, %4
ret void
}