#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, int);
void merge_sort(int A[50000], int B[50000], int left, int right) {
  if (right - left > 1) {
    int mid = (left + right) >> 1;
    merge_sort(A, B, left, mid);
    merge_sort(A, B, mid, right);
    merge(A, B, left, mid, right);
  }
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
cmp    $0x1,%eax
jle    118e <merge_sort+0x6e>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1030 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
mov    %ecx,%eax
sub    %edx,%eax
cmp    $0x1,%eax
jle    1173 <merge_sort+0x53>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r12
lea    (%r14,%rbx,1),%ebp
sar    %ebp
mov    %ebp,%ecx
call   1040 <merge_sort@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1040 <merge_sort@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r14d,%r8d
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <merge@plt>
ret

LLVM IR (-O0):
define void @merge_sort(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* %8
%11 = load i32, i32* %7
%12 = sub nsw i32 %10, %11
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %33
14: ; preds = %4
%15 = load i32, i32* %7
%16 = load i32, i32* %8
%17 = add nsw i32 %15, %16
%18 = ashr i32 %17, 1
store i32 %18, i32* %9
%19 = load i32*, i32** %5
%20 = load i32*, i32** %6
%21 = load i32, i32* %7
%22 = load i32, i32* %9
%23 = load i32*, i32** %5
%24 = load i32*, i32** %6
%25 = load i32, i32* %9
%26 = load i32, i32* %8
%27 = load i32*, i32** %5
%28 = load i32*, i32** %6
%29 = load i32, i32* %7
%30 = load i32, i32* %9
%31 = load i32, i32* %8
%32 = call i32 @merge(i32* %27, i32* %28, i32 %29, i32 %30, i32 %31)
br label %33
33: ; preds = %14, %4
ret void
}

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