#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 atoi(int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ mergesort(int *, int);
int /*<<< orphan*/ print_array(int *, int);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  int i = 0;
  int length = argc - 1;
  int *array = malloc(sizeof(int) * length);
  argv++;
  while (i < length) {
    array[i++] = atoi(*(argv++));
  }
  printf("Original:\n");
  print_array(array, length);
  mergesort(array, length);
  printf("Sorted:\n");
  print_array(array, length);
  free(array);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11e6 <main+0x86>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rax
mov    %eax,%edi
call   1080 <atoi@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11a5 <main+0x45>
lea    0xe13(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1040 <print_array@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1070 <mergesort@plt>
lea    0xdfa(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1040 <print_array@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %edi,%r15d
lea    -0x1(%r15),%r14d
lea    -0x4(,%r15,4),%edi
ff
call   1060 <malloc@plt>
mov    %rax,%r12
cmp    $0x2,%r15d
jl     11a7 <main+0x47>
mov    %r14d,%ebx
xor    %ebp,%ebp
mov    0x8(%r13,%rbp,8),%edi
call   1080 <atoi@plt>
mov    %eax,(%r12,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1190 <main+0x30>
lea    0xe52(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
mov    %r14d,%esi
call   1050 <print_array@plt>
mov    %r12,%rdi
mov    %r14d,%esi
call   1070 <mergesort@plt>
lea    0xe3a(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
mov    %r14d,%esi
call   1050 <print_array@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@str = [10 x i8] c"Original:\00"
@str.2 = [8 x i8] c"Sorted:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add nsw i32 %0, -1
%4 = shl i32 %3, 2
%5 = tail call i32* @malloc(i32 %4)
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %20
7: ; preds = %2
%8 = zext i32 %3 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %17, %9 ]
%11 = phi i8** [ %1, %7 ], [ %12, %9 ]
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = ptrtoint i8* %13 to i64
%15 = trunc i64 %14 to i32
%16 = tail call i32 @atoi(i32 %15)
%17 = add nuw nsw i64 %10, 1
%18 = getelementptr inbounds i32, i32* %5, i64 %10
store i32 %16, i32* %18
%19 = icmp eq i64 %17, %8
br i1 %19, label %20, label %9
20: ; preds = %9, %2
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%22 = tail call i32 @print_array(i32* %5, i32 %3)
%23 = tail call i32 @mergesort(i32* %5, i32 %3)
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.2, i64 0, i64 0))
%25 = tail call i32 @print_array(i32* %5, i32 %3)
%26 = tail call i32 @free(i32* %5)
ret i32 0
}