#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int *malloc(int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ mergeSort(int *, int /*<<< orphan*/, int, int *);
int /*<<< orphan*/ printf(char *, int);
int scanf(char *, int *);
int /*<<< orphan*/ stderr;
int strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  int *a;
  int *b;
  int n;
  if (argc < 2) {
    fprintf(stderr, "usage: %s num_points\n", argv[0]);
    return 1;
  }
  n = strtol(argv[1], NULL, 10);
  a = malloc(n * sizeof(int));
  b = malloc(n * sizeof(int));
  if (a == NULL || b == NULL) {
    fprintf(stderr, "couldn't allocate array of %d ints\n", n);
    return 1;
  }
  for (int i = 0; i < n; i++)
    if (scanf("%d", &a[i]) != 1) {
      fprintf(stderr, "missing/invalid data\n");
      return 1;
    }
  memcpy(b, a, n * sizeof(int));
  mergeSort(a, 0, n, b);
  for (int i = 0; i < n; i++)
    printf("%d\n", b[i]);
  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    11ba <main+0x4a>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    130a <main+0x19a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     120f <main+0x9f>
cmpq   $0x0,-0x20(%rbp)
jne    1235 <main+0xc5>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    130a <main+0x19a>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12a2 <main+0x132>
mov    -0x18(%rbp),%rsi
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xddc(%rip),%rdi
call   1090 <scanf@plt>
cmp    $0x1,%eax
je     128f <main+0x11f>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    130a <main+0x19a>
jmp    1294 <main+0x124>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    123c <main+0xcc>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
xor    %esi,%esi
call   1070 <mergeSort@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1303 <main+0x193>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd63(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12d2 <main+0x162>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
jg     11a2 <main+0x32>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe6a(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    12db <main+0x16b>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%r14d
lea    0x0(,%r14,4),%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1080 <malloc@plt>
test   %rbx,%rbx
je     1287 <main+0x117>
mov    %rax,%r15
test   %rax,%rax
je     1287 <main+0x117>
test   %r14d,%r14d
jle    12a3 <main+0x133>
mov    %ebp,0xc(%rsp)
mov    %r14,0x10(%rsp)
mov    %r14d,%r13d
lea    0x0(,%r13,4),%r14
xor    %r12d,%r12d
lea    0xe30(%rip),%rbp
nopw   0x0(%rax,%rax,1)
lea    (%rbx,%r12,1),%rsi
mov    %rbp,%rdi
call   1090 <scanf@plt>
cmp    $0x1,%eax
jne    12c4 <main+0x154>
add    $0x4,%r12
cmp    %r12,%r14
jne    1210 <main+0xa0>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    0xc(%rsp),%edx
call   1060 <memcpy@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    0x10(%rsp),%rbx
mov    %ebx,%edx
mov    %r15,%rcx
call   1070 <mergeSort@plt>
test   %ebx,%ebx
jle    12e0 <main+0x170>
xor    %ebp,%ebp
lea    0xdef(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1270 <main+0x100>
jmp    12e0 <main+0x170>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xd7f(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    12db <main+0x16b>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <memcpy@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14d,%edx
mov    %r15,%rcx
call   1070 <mergeSort@plt>
jmp    12e0 <main+0x170>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
lea    0xd69(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"usage: %s num_points\0A\00"
@.str.1 = [36 x i8] c"couldn't allocate array of %d ints\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [22 x i8] c"missing/invalid data\0A\00"
@.str.4 = [4 x i8] c"%d\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 i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %89
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strtol(i8* %22, i32* null, i32 10)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 4
%27 = trunc i64 %26 to i32
%28 = call i32* @malloc(i32 %27)
store i32* %28, i32** %6
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = mul i64 %30, 4
%32 = trunc i64 %31 to i32
%33 = call i32* @malloc(i32 %32)
store i32* %33, i32** %7
%34 = load i32*, i32** %6
%35 = icmp eq i32* %34, null
br i1 %35, label %39, label %36
36: ; preds = %19
%37 = load i32*, i32** %7
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %43
39: ; preds = %36, %19
%40 = load i32, i32* @stderr
%41 = load i32, i32* %8
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %41)
store i32 1, i32* %3
br label %89
43: ; preds = %36
store i32 0, i32* %9
br label %44
44: ; preds = %59, %43
%45 = load i32, i32* %9
%46 = load i32, i32* %8
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %62
48: ; preds = %44
%49 = load i32*, i32** %6
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
%53 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %52)
%54 = icmp ne i32 %53, 1
br i1 %54, label %55, label %58
55: ; preds = %48
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %89
58: ; preds = %48
br label %59
59: ; preds = %58
%60 = load i32, i32* %9
%61 = add nsw i32 %60, 1
store i32 %61, i32* %9
br label %44
62: ; preds = %44
%63 = load i32*, i32** %7
%64 = load i32*, i32** %6
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = mul i64 %66, 4
%68 = trunc i64 %67 to i32
%69 = call i32 @memcpy(i32* %63, i32* %64, i32 %68)
%70 = load i32*, i32** %6
%71 = load i32, i32* %8
%72 = load i32*, i32** %7
%73 = call i32 @mergeSort(i32* %70, i32 0, i32 %71, i32* %72)
store i32 0, i32* %10
br label %74
74: ; preds = %85, %62
%75 = load i32, i32* %10
%76 = load i32, i32* %8
%77 = icmp slt i32 %75, %76
br i1 %77, label %78, label %88
78: ; preds = %74
%79 = load i32*, i32** %7
%80 = load i32, i32* %10
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i32, i32* %79, i64 %81
%83 = load i32, i32* %82
%84 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %83)
br label %85
85: ; preds = %78
%86 = load i32, i32* %10
%87 = add nsw i32 %86, 1
store i32 %87, i32* %10
br label %74
88: ; preds = %74
store i32 0, i32* %3
br label %89
89: ; preds = %88, %55, %39, %13
%90 = load i32, i32* %3
ret i32 %90
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"usage: %s num_points\0A\00"
@.str.1 = [36 x i8] c"couldn't allocate array of %d ints\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [22 x i8] c"missing/invalid data\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %51
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @strtol(i8* nocapture %10, i32* null, i32 10)
%12 = shl i32 %11, 2
%13 = tail call i32* @malloc(i32 %12)
%14 = tail call i32* @malloc(i32 %12)
%15 = icmp eq i32* %13, null
%16 = icmp eq i32* %14, null
%17 = or i1 %15, %16
br i1 %17, label %22, label %18
18: ; preds = %8
%19 = icmp sgt i32 %11, 0
br i1 %19, label %20, label %48
20: ; preds = %18
%21 = zext i32 %11 to i64
br label %27
22: ; preds = %8
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %51
25: ; preds = %27
%26 = icmp eq i64 %32, %21
br i1 %26, label %36, label %27
27: ; preds = %20, %25
%28 = phi i64 [ 0, %20 ], [ %32, %25 ]
%29 = getelementptr inbounds i32, i32* %13, i64 %28
%30 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %29)
%31 = icmp eq i32 %30, 1
%32 = add nuw nsw i64 %28, 1
br i1 %31, label %25, label %33
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %51
36: ; preds = %25
%37 = tail call i32 @memcpy(i32* %14, i32* %13, i32 %12)
%38 = tail call i32 @mergeSort(i32* %13, i32 0, i32 %11, i32* %14)
br i1 %19, label %39, label %51
39: ; preds = %36
%40 = zext i32 %11 to i64
br label %41
41: ; preds = %39, %41
%42 = phi i64 [ 0, %39 ], [ %46, %41 ]
%43 = getelementptr inbounds i32, i32* %14, i64 %42
%44 = load i32, i32* %43
%45 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %44)
%46 = add nuw nsw i64 %42, 1
%47 = icmp eq i64 %46, %40
br i1 %47, label %51, label %41
48: ; preds = %18
%49 = tail call i32 @memcpy(i32* %14, i32* %13, i32 %12)
%50 = tail call i32 @mergeSort(i32* %13, i32 0, i32 %11, i32* %14)
br label %51
51: ; preds = %41, %48, %36, %33, %22, %4
%52 = phi i32 [ 1, %4 ], [ 1, %22 ], [ 1, %33 ], [ 0, %36 ], [ 0, %48 ], [ 0, %41 ]
ret i32 %52
}