#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 */
scalar_t__ atoi(char *);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ print_array(int *, size_t);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ split_n_sort(int *, size_t);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Give me the initial array\n");
    return 1;
  }
  int *unsorted_array = malloc((argc - 1) * sizeof(int));
  for (int i = 1, j = 0; i < argc; i++, j++) {
    unsorted_array[j] = (int)atoi(argv[i]);
  }
  size_t len_of_unsorted_array = argc - 1;
  split_n_sort(unsorted_array, len_of_unsorted_array);
  print_array(unsorted_array, len_of_unsorted_array);
  free(unsorted_array);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1198 <main+0x38>
lea    0xe79(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1234 <main+0xd4>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11fe <main+0x9e>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <atoi@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11bd <main+0x5d>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <split_n_sort@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <print_array@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     1180 <main+0x20>
lea    0xe8c(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    11d7 <main+0x77>
mov    %rsi,%r14
lea    -0x1(%rdi),%r15d
lea    -0x4(,%rdi,4),%edi
call   1070 <malloc@plt>
mov    %rax,%r12
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x8(%r14,%rbx,8),%rdi
call   1080 <atoi@plt>
mov    %eax,(%r12,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11a0 <main+0x40>
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <split_n_sort@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <print_array@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Give me the initial array\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
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %54
14: ; preds = %2
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 4
%19 = trunc i64 %18 to i32
%20 = call i32* @malloc(i32 %19)
store i32* %20, i32** %6
store i32 1, i32* %7
store i32 0, i32* %8
br label %21
21: ; preds = %37, %14
%22 = load i32, i32* %7
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %42
25: ; preds = %21
%26 = load i8**, i8*** %5
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = call i64 @atoi(i8* %30)
%32 = trunc i64 %31 to i32
%33 = load i32*, i32** %6
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
store i32 %32, i32* %36
br label %37
37: ; preds = %25
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %21
42: ; preds = %21
%43 = load i32, i32* %4
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
store i64 %45, i64* %9
%46 = load i32*, i32** %6
%47 = load i64, i64* %9
%48 = call i32 @split_n_sort(i32* %46, i64 %47)
%49 = load i32*, i32** %6
%50 = load i64, i64* %9
%51 = call i32 @print_array(i32* %49, i64 %50)
%52 = load i32*, i32** %6
%53 = call i32 @free(i32* %52)
store i32 0, i32* %3
br label %54
54: ; preds = %42, %12
%55 = load i32, i32* %3
ret i32 %55
}

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