#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 *);
void mergeSort(int tam, int *vetor) {
  int meio = tam / 2;
  int i = 0;
  if (tam < 2)
    return;
  int esq = meio;
  int dir = tam - meio;
  int vetEsquerdo[esq];
  int vetDireito[dir];
  for (i = 0; i < (meio); i++) {
    vetEsquerdo[i] = vetor[i];
  }
  for (i = meio; i < (tam); i++) {
    vetDireito[i - meio] = vetor[i];
  }
  mergeSort(esq, vetEsquerdo);
  mergeSort(dir, vetDireito);
  merge(vetEsquerdo, esq, vetDireito, dir, vetor);
}


x86 assembly (clang, -O0):
<mergeSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    1153 <mergeSort+0x33>
jmp    1253 <mergeSort+0x133>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e2 <mergeSort+0xc2>
mov    -0x48(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
mov    (%rcx,%rdx,4),%edx
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b2 <mergeSort+0x92>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    121d <mergeSort+0xfd>
mov    -0x40(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
mov    (%rcx,%rdx,4),%edx
mov    -0x18(%rbp),%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11e8 <mergeSort+0xc8>
mov    -0x48(%rbp),%rsi
mov    -0x1c(%rbp),%edi
call   1030 <mergeSort@plt>
mov    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%edi
call   1030 <mergeSort@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%r8
call   1040 <merge@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergeSort>:
cmp    $0x2,%edi
jl     1206 <mergeSort+0xd6>
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r12d
mov    %rsp,-0x38(%rbp)
mov    %edi,%ebx
shr    $0x1f,%ebx
add    %edi,%ebx
sar    %ebx
mov    %ebx,%eax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %edi,%eax
sub    %ebx,%eax
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r13
sub    %rax,%r13
mov    %r13,%rsp
lea    -0x1(%rbx),%eax
lea    0x4(,%rax,4),%rdx
mov    %r15,%rdi
mov    %rsi,-0x30(%rbp)
call   1030 <memcpy@plt>
mov    %r12d,%r14d
sub    %ebx,%r14d
jle    11cb <mergeSort+0x9b>
movslq %ebx,%rax
mov    -0x30(%rbp),%rcx
lea    (%rcx,%rax,4),%rsi
mov    %ebx,%eax
not    %eax
add    %r12d,%eax
lea    0x4(,%rax,4),%rdx
mov    %r13,%rdi
call   1030 <memcpy@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1040 <mergeSort@plt>
mov    %r14d,%edi
mov    %r13,%rsi
call   1040 <mergeSort@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r13,%rdx
mov    %r14d,%ecx
mov    -0x30(%rbp),%r8
call   1050 <merge@plt>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @mergeSort(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
store i32 %0, i32* %3
store i32* %1, i32** %4
%12 = load i32, i32* %3
%13 = sdiv i32 %12, 2
store i32 %13, i32* %5
store i32 0, i32* %6
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %17
16: ; preds = %2
br label %73
17: ; preds = %2
%18 = load i32, i32* %5
store i32 %18, i32* %7
%19 = load i32, i32* %3
%20 = load i32, i32* %5
%21 = sub nsw i32 %19, %20
store i32 %21, i32* %8
%22 = load i32, i32* %7
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %9
%25 = alloca i32, i64 %23
store i64 %23, i64* %10
%26 = load i32, i32* %8
%27 = zext i32 %26 to i64
%28 = alloca i32, i64 %27
store i64 %27, i64* %11
store i32 0, i32* %6
br label %29
29: ; preds = %42, %17
%30 = load i32, i32* %6
%31 = load i32, i32* %5
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %45
33: ; preds = %29
%34 = load i32*, i32** %4
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %25, i64 %40
store i32 %38, i32* %41
br label %42
42: ; preds = %33
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %29
45: ; preds = %29
%46 = load i32, i32* %5
store i32 %46, i32* %6
br label %47
47: ; preds = %62, %45
%48 = load i32, i32* %6
%49 = load i32, i32* %3
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %65
51: ; preds = %47
%52 = load i32*, i32** %4
%53 = load i32, i32* %6
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %52, i64 %54
%56 = load i32, i32* %55
%57 = load i32, i32* %6
%58 = load i32, i32* %5
%59 = sub nsw i32 %57, %58
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %28, i64 %60
store i32 %56, i32* %61
br label %62
62: ; preds = %51
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %47
65: ; preds = %47
%66 = load i32, i32* %7
%67 = load i32, i32* %8
%68 = load i32, i32* %7
%69 = load i32, i32* %8
%70 = load i32*, i32** %4
%71 = call i32 @merge(i32* %25, i32 %68, i32* %28, i32 %69, i32* %70)
%72 = load i8*, i8** %9
br label %73
73: ; preds = %65, %16
ret void
}

LLVM IR (-O2):
define void @mergeSort(i32 %0, i32* %1) {
%3 = sdiv i32 %0, 2
%4 = icmp slt i32 %0, 2
br i1 %4, label %31, label %5
5: ; preds = %2
%6 = bitcast i32* %1 to i8*
%7 = sub nsw i32 %0, %3
%8 = zext i32 %3 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i32, i64 %8
%11 = zext i32 %7 to i64
%12 = alloca i32, i64 %11
%13 = bitcast i32* %10 to i8*
%14 = add nsw i32 %3, -1
%15 = zext i32 %14 to i64
%16 = shl nuw nsw i64 %15, 2
%17 = add nuw nsw i64 %16, 4
%18 = icmp slt i32 %3, %0
br i1 %18, label %19, label %29
19: ; preds = %5
%20 = bitcast i32* %12 to i8*
%21 = sext i32 %3 to i64
%22 = getelementptr i32, i32* %1, i64 %21
%23 = bitcast i32* %22 to i8*
%24 = xor i32 %3, -1
%25 = add i32 %24, %0
%26 = zext i32 %25 to i64
%27 = shl nuw nsw i64 %26, 2
%28 = add nuw nsw i64 %27, 4
br label %29
29: ; preds = %19, %5
%30 = call i32 @merge(i32* %10, i32 %3, i32* %12, i32 %7, i32* %1)
br label %31
31: ; preds = %2, %29
ret void
}