#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, char *);
int *merge_sort(int a[], int p, int r, char *text) {
  if (p < r) {
    int q = (p + r) / 2;
    merge_sort(a, p, q, "first");
    merge_sort(a, (q + 1), r, "second");
    merge(a, p, q, r, text);
  }
  return a;
}


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    %rcx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1198 <merge_sort+0x78>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe9c(%rip),%rcx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
lea    0xe89(%rip),%rcx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%r8
call   1030 <merge@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r15
cmp    %edx,%esi
jge    117f <merge_sort+0x5f>
mov    %rcx,%r14
mov    %edx,%r12d
mov    %esi,%r13d
lea    (%r12,%r13,1),%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
lea    0xeb3(%rip),%rcx
mov    %r15,%rdi
mov    %ebx,%edx
call   1040 <merge_sort@plt>
lea    0x1(%rbx),%esi
lea    0xea5(%rip),%rcx
mov    %r15,%rdi
mov    %r12d,%edx
call   1040 <merge_sort@plt>
mov    %r15,%rdi
mov    %r13d,%esi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    %r14,%r8
call   1030 <merge@plt>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"first\00"
@.str.1 = [7 x i8] c"second\00"
define i32* @merge_sort(i32* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%10 = load i32, i32* %6
%11 = load i32, i32* %7
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %33
13: ; preds = %4
%14 = load i32, i32* %6
%15 = load i32, i32* %7
%16 = add nsw i32 %14, %15
%17 = sdiv i32 %16, 2
store i32 %17, i32* %9
%18 = load i32*, i32** %5
%19 = load i32, i32* %6
%20 = load i32, i32* %9
%21 = call i32* @merge_sort(i32* %18, i32 %19, i32 %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%22 = load i32*, i32** %5
%23 = load i32, i32* %9
%24 = add nsw i32 %23, 1
%25 = load i32, i32* %7
%26 = call i32* @merge_sort(i32* %22, i32 %24, i32 %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32*, i32** %5
%28 = load i32, i32* %6
%29 = load i32, i32* %9
%30 = load i32, i32* %7
%31 = load i8*, i8** %8
%32 = call i32 @merge(i32* %27, i32 %28, i32 %29, i32 %30, i8* %31)
br label %33
33: ; preds = %13, %4
%34 = load i32*, i32** %5
ret i32* %34
}

LLVM IR (-O2):
@.str = [6 x i8] c"first\00"
@.str.1 = [7 x i8] c"second\00"
define i32* @merge_sort(i32* returned %0, i32 %1, i32 %2, i8* %3) {
%5 = icmp slt i32 %1, %2
br i1 %5, label %7, label %6
6: ; preds = %4, %7
ret i32* %0
7: ; preds = %4
%8 = add nsw i32 %2, %1
%9 = sdiv i32 %8, 2
%10 = tail call i32* @merge_sort(i32* %0, i32 %1, i32 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = add nsw i32 %9, 1
%12 = tail call i32* @merge_sort(i32* %0, i32 %11, i32 %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @merge(i32* %0, i32 %1, i32 %9, i32 %2, i8* %3)
br label %6
}