#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 /*<<< orphan*/ printf(char *, ...);
void merge_sort(int data[], int first, int last) {
  int part = (first + last) / 2;
  if (first == last)
    return;
  merge_sort(data, first, part);
  merge_sort(data, part + 1, last);
  merge(data, first, part, last);
  int k = 0;
  for (k = 0; k <= last; k++) {
    printf("%d\t", data[k]);
  }
  printf("==============");
}


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
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    1164 <merge_sort+0x34>
jmp    11e6 <merge_sort+0xb6>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1050 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1040 <merge@plt>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11d8 <merge_sort+0xa8>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a5 <merge_sort+0x75>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
cmp    %edx,%esi
jne    1135 <merge_sort+0x5>
ret
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edx,%r13d
mov    %esi,%r15d
mov    %rdi,%r14
lea    (%r15,%r13,1),%eax
mov    %eax,%r12d
shr    $0x1f,%r12d
add    %eax,%r12d
sar    %r12d
mov    %r12d,%edx
call   1050 <merge_sort@plt>
lea    0x1(%r12),%esi
mov    %r14,%rdi
mov    %r13d,%edx
call   1050 <merge_sort@plt>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %r13d,%ecx
call   1040 <merge@plt>
test   %r13d,%r13d
js     11b7 <merge_sort+0x87>
add    $0x1,%r13d
lea    0xe6f(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11a0 <merge_sort+0x70>
lea    0xe46(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\09\00"
@.str.1 = [15 x i8] c"==============\00"
define void @merge_sort(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = add nsw i32 %9, %10
%12 = sdiv i32 %11, 2
store i32 %12, i32* %7
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %3
br label %46
17: ; preds = %3
%18 = load i32*, i32** %4
%19 = load i32, i32* %5
%20 = load i32, i32* %7
%21 = load i32*, i32** %4
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
%24 = load i32, i32* %6
%25 = load i32*, i32** %4
%26 = load i32, i32* %5
%27 = load i32, i32* %7
%28 = load i32, i32* %6
%29 = call i32 @merge(i32* %25, i32 %26, i32 %27, i32 %28)
store i32 0, i32* %8
store i32 0, i32* %8
br label %30
30: ; preds = %41, %17
%31 = load i32, i32* %8
%32 = load i32, i32* %6
%33 = icmp sle i32 %31, %32
br i1 %33, label %34, label %44
34: ; preds = %30
%35 = load i32*, i32** %4
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32, i32* %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %34
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %30
44: ; preds = %30
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %46
46: ; preds = %44, %16
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\09\00"
@.str.1 = [15 x i8] c"==============\00"
define void @merge_sort(i32* %0, i32 %1, i32 %2) {
%4 = add nsw i32 %2, %1
%5 = sdiv i32 %4, 2
%6 = icmp eq i32 %1, %2
br i1 %6, label %23, label %7
7: ; preds = %3
tail call void @merge_sort(i32* %0, i32 %1, i32 %5)
%8 = add nsw i32 %5, 1
tail call void @merge_sort(i32* %0, i32 %8, i32 %2)
%9 = tail call i32 @merge(i32* %0, i32 %1, i32 %5, i32 %2)
%10 = icmp slt i32 %2, 0
br i1 %10, label %21, label %11
11: ; preds = %7
%12 = add nuw i32 %2, 1
%13 = zext i32 %12 to i64
br label %14
14: ; preds = %11, %14
%15 = phi i64 [ 0, %11 ], [ %19, %14 ]
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = load i32, i32* %16
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = add nuw nsw i64 %15, 1
%20 = icmp eq i64 %19, %13
br i1 %20, label %21, label %14
21: ; preds = %14, %7
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %3, %21
ret void
}