#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 *v, int left, int right) {
  if (left < (right - 1)) {
    int mid = (left + right) / 2;
    _merge_sort(v, left, mid);
    _merge_sort(v, mid, right);
    _merge(v, left, right, mid);
  }
}


x86 assembly (clang, -O0):
<_merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1184 <_merge_sort+0x64>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <_merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <_merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1030 <_merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_merge_sort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
lea    -0x1(%r14),%eax
cmp    %esi,%eax
jle    1171 <_merge_sort+0x51>
mov    %esi,%ebx
mov    %rdi,%r15
lea    (%r14,%rbx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %ebp,%edx
call   1040 <_merge_sort@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1040 <_merge_sort@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <_merge@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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 = load i32, i32* %6
%10 = sub nsw i32 %9, 1
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %28
12: ; preds = %3
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = add nsw i32 %13, %14
%16 = sdiv i32 %15, 2
store i32 %16, i32* %7
%17 = load i32*, i32** %4
%18 = load i32, i32* %5
%19 = load i32, i32* %7
%20 = load i32*, i32** %4
%21 = load i32, i32* %7
%22 = load i32, i32* %6
%23 = load i32*, i32** %4
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = call i32 @_merge(i32* %23, i32 %24, i32 %25, i32 %26)
br label %28
28: ; preds = %12, %3
ret void
}

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