#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);
int /*<<< orphan*/ printf(char *, int, int);
void mergesort(int *a, int low, int high) {
  if (high > low) {
    printf("mergesorta,%d,%d\n", low, high);
    mergesort(a, low, (low + high) / 2);
    mergesort(a, (low + high) / 2 + 1, high);
    merge(a, low, (low + high) / 2, (low + high) / 2 + 1, high);
  }
}


x86 assembly (clang, -O0):
<mergesort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    11d2 <mergesort+0xa2>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
call   1050 <mergesort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1050 <mergesort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x14(%rbp),%edx
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%r8d
call   1040 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergesort>:
cmp    %esi,%edx
jle    1195 <mergesort+0x65>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,%r15
lea    0xeb4(%rip),%rdi
call   1030 <printf@plt>
lea    (%r14,%r12,1),%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
mov    %r15,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
call   1050 <mergesort@plt>
lea    0x1(%rbx),%ebp
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1050 <mergesort@plt>
mov    %r15,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r14d,%r8d
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <merge@plt>
ret

LLVM IR (-O0):
@.str = [18 x i8] c"mergesorta,%d,%d\0A\00"
define void @mergesort(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = load i32, i32* %5
%9 = icmp sgt i32 %7, %8
br i1 %9, label %10, label %40
10: ; preds = %3
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
%14 = load i32*, i32** %4
%15 = load i32, i32* %5
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = add nsw i32 %16, %17
%19 = sdiv i32 %18, 2
%20 = load i32*, i32** %4
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = add nsw i32 %21, %22
%24 = sdiv i32 %23, 2
%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* %5
%30 = load i32, i32* %6
%31 = add nsw i32 %29, %30
%32 = sdiv i32 %31, 2
%33 = load i32, i32* %5
%34 = load i32, i32* %6
%35 = add nsw i32 %33, %34
%36 = sdiv i32 %35, 2
%37 = add nsw i32 %36, 1
%38 = load i32, i32* %6
%39 = call i32 @merge(i32* %27, i32 %28, i32 %32, i32 %37, i32 %38)
br label %40
40: ; preds = %10, %3
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"mergesorta,%d,%d\0A\00"
define void @mergesort(i32* %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, %1
br i1 %4, label %6, label %5
5: ; preds = %3, %6
ret void
6: ; preds = %3
%7 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%8 = add nsw i32 %2, %1
%9 = sdiv i32 %8, 2
tail call void @mergesort(i32* %0, i32 %1, i32 %9)
%10 = add nsw i32 %9, 1
tail call void @mergesort(i32* %0, i32 %10, i32 %2)
%11 = tail call i32 @merge(i32* %0, i32 %1, i32 %9, i32 %10, i32 %2)
br label %5
}