#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, int *);
void merge_sort(int *A, int n, int *A2) {
  if (n < 2)
    return;
  int m = 0.5 * n;
  merge_sort(A, m, A2);
  merge_sort(A + m, n - m, A2 + m);
  merge(A, n, m, A2);
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    1142 <merge_sort+0x22>
jmp    11a6 <merge_sort+0x86>
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xeb1(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0xc(%rbp),%esi
sub    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1030 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
cmp    $0x1,%esi
jg     1126 <merge_sort+0x6>
ret
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r12
cvtsi2sd %esi,%xmm0
mulsd  0xebe(%rip),%xmm0
cvttsd2si %xmm0,%r15d
mov    %r15d,%esi
call   1040 <merge_sort@plt>
movslq %r15d,%rbx
lea    (%r12,%rbx,4),%rdi
mov    %ebp,%esi
sub    %ebx,%esi
lea    (%r14,%rbx,4),%rdx
call   1040 <merge_sort@plt>
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r14,%rcx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <merge@plt>

LLVM IR (-O0):
define void @merge_sort(i32* %0, i32 %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %11
10: ; preds = %3
br label %35
11: ; preds = %3
%12 = load i32, i32* %5
%13 = sitofp i32 %12 to double
%14 = fmul double 5.000000e-01, %13
%15 = fptosi double %14 to i32
store i32 %15, i32* %7
%16 = load i32*, i32** %4
%17 = load i32, i32* %7
%18 = load i32*, i32** %6
%19 = load i32*, i32** %4
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %5
%24 = load i32, i32* %7
%25 = sub nsw i32 %23, %24
%26 = load i32*, i32** %6
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32*, i32** %4
%31 = load i32, i32* %5
%32 = load i32, i32* %7
%33 = load i32*, i32** %6
%34 = call i32 @merge(i32* %30, i32 %31, i32 %32, i32* %33)
br label %35
35: ; preds = %11, %10
ret void
}

LLVM IR (-O2):
define void @merge_sort(i32* %0, i32 %1, i32* %2) {
%4 = icmp slt i32 %1, 2
br i1 %4, label %5, label %6
5: ; preds = %3, %6
ret void
6: ; preds = %3
%7 = sitofp i32 %1 to double
%8 = fmul double %7, 5.000000e-01
%9 = fptosi double %8 to i32
tail call void @merge_sort(i32* %0, i32 %9, i32* %2)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %0, i64 %10
%12 = sub nsw i32 %1, %9
%13 = getelementptr inbounds i32, i32* %2, i64 %10
tail call void @merge_sort(i32* %11, i32 %12, i32* %13)
%14 = tail call i32 @merge(i32* %0, i32 %1, i32 %9, i32* %2)
br label %5
}