#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 *, unsigned int, int, unsigned int);
void merge_sort(int array[], unsigned int first, unsigned int last) {
  int mid = 0;
  if (first < last) {
    mid = ((first & last) + ((first ^ last) >> 1));
    merge_sort(array, first, mid);
    merge_sort(array, mid + 1, last);
    merge(array, first, mid, last);
  }
}


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)
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    118c <merge_sort+0x6c>
mov    -0xc(%rbp),%eax
and    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
xor    -0x10(%rbp),%ecx
shr    $0x1,%ecx
add    %ecx,%eax
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
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1030 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
cmp    %edx,%esi
jae    117f <merge_sort+0x5f>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r13d
mov    %esi,%ebp
mov    %rdi,%r14
mov    %edx,%r12d
and    %esi,%r12d
mov    %edx,%ebx
xor    %esi,%ebx
shr    %ebx
lea    (%rbx,%r12,1),%r15d
mov    %r15d,%edx
call   1040 <merge_sort@plt>
lea    (%rbx,%r12,1),%esi
add    $0x1,%esi
mov    %r14,%rdi
mov    %r13d,%edx
call   1040 <merge_sort@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %r13d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <merge@plt>
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
store i32 0, i32* %7
%8 = load i32, i32* %5
%9 = load i32, i32* %6
%10 = icmp ult i32 %8, %9
br i1 %10, label %11, label %32
11: ; preds = %3
%12 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = and i32 %12, %13
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = xor i32 %15, %16
%18 = lshr i32 %17, 1
%19 = add i32 %14, %18
store i32 %19, i32* %7
%20 = load i32*, i32** %4
%21 = load i32, i32* %5
%22 = load i32, i32* %7
%23 = load i32*, i32** %4
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
%26 = load i32, i32* %6
%27 = load i32*, i32** %4
%28 = load i32, i32* %5
%29 = load i32, i32* %7
%30 = load i32, i32* %6
%31 = call i32 @merge(i32* %27, i32 %28, i32 %29, i32 %30)
br label %32
32: ; preds = %11, %3
ret void
}

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