#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*/ insertionSort(int *, int, int);
int /*<<< orphan*/ merge(int *, int, int, int);
int minimum(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n;
  printf("Enter number of elements in your array: ");
  scanf("%d", &n);
  int array[n];
  printf("Enter your array: ");
  for (int i = 0; i < n; i++)
    scanf("%d", &array[i]);
  printf("Unsorted Array : \n");
  for (int i = 0; i < n; i++)
    printf("%d  ", array[i]);
  printf("\n");
  int size, left, mid, right, Limit = 32;
  for (int i = 0; i < n; i += Limit)
    insertionSort(array, i, minimum((i + 31), (n - 1)));
  for (size = Limit; size < n; size = 2 * size) {
    for (left = 0; left < n; left += 2 * size) {
      mid = left + size - 1;
      right = minimum((left + 2 * size - 1), (n - 1));
      merge(array, left, mid, right);
    }
  }
  printf("Sorted Array : \n");
  for (int i = 0; i < n; i++)
    printf("%d  ", array[i]);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ee <main+0x9e>
mov    -0x48(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe4e(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b9 <main+0x69>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1236 <main+0xe6>
mov    -0x48(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1203 <main+0xb3>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x20,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1291 <main+0x141>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%edi
add    $0x1f,%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1030 <minimum@plt>
mov    -0x48(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    %eax,%edx
call   1060 <insertionSort@plt>
mov    -0x34(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    1252 <main+0x102>
mov    -0x34(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1314 <main+0x1c4>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1301 <main+0x1b1>
mov    -0x28(%rbp),%eax
add    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
add    %eax,%edi
sub    $0x1,%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1030 <minimum@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
call   1050 <merge@plt>
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    12aa <main+0x15a>
jmp    1306 <main+0x1b6>
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1297 <main+0x147>
lea    0xd3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    135c <main+0x20c>
mov    -0x48(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1329 <main+0x1d9>
lea    0xd03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe93(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1090 <scanf@plt>
mov    %rsp,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe6a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    11fc <main+0x8c>
xor    %r14d,%r14d
lea    0xe50(%rip),%r15
mov    %r12,%rbx
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
add    $0x1,%r14
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r14
jl     11e0 <main+0x70>
lea    0xe41(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    123b <main+0xcb>
lea    0xe2a(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     1220 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x2c(%rbp),%esi
test   %esi,%esi
jle    1301 <main+0x191>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1f(%rbx),%edi
add    $0xffffffff,%esi
call   1050 <minimum@plt>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1080 <insertionSort@plt>
add    $0x20,%ebx
mov    -0x2c(%rbp),%esi
cmp    %esi,%ebx
jl     1260 <main+0xf0>
cmp    $0x21,%esi
jl     1301 <main+0x191>
mov    $0x20,%ecx
mov    %r12,-0x38(%rbp)
jmp    12a6 <main+0x136>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %ecx,%ecx
cmp    %esi,%ecx
jge    1301 <main+0x191>
test   %esi,%esi
jle    12a0 <main+0x130>
lea    -0x1(%rcx),%eax
mov    %rax,-0x48(%rbp)
mov    %ecx,%eax
add    %ecx,%ecx
lea    (%rax,%rax,1),%r14d
add    $0xffffffff,%r14d
xor    %ebx,%ebx
nop
mov    -0x48(%rbp),%rax
lea    (%rax,%rbx,1),%r15d
lea    (%rbx,%rcx,1),%r13d
lea    (%r14,%rbx,1),%edi
add    $0xffffffff,%esi
mov    %rcx,%r12
call   1050 <minimum@plt>
mov    -0x38(%rbp),%rdi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %eax,%ecx
call   1070 <merge@plt>
mov    %r12,%rcx
mov    -0x2c(%rbp),%esi
mov    %r13d,%ebx
cmp    %esi,%r13d
jl     12c0 <main+0x150>
mov    -0x38(%rbp),%r12
cmp    %esi,%ecx
jl     12a6 <main+0x136>
lea    0xd4e(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    133b <main+0x1cb>
lea    0xd25(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     1320 <main+0x1b0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x40(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Enter number of elements in your array: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"Enter your array: \00"
@.str.3 = [19 x i8] c"Unsorted Array : \0A\00"
@.str.4 = [5 x i8] c"%d \00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [17 x i8] c"Sorted Array : \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %1
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%16 = load i32, i32* %2
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %3
%19 = alloca i32, i64 %17
store i64 %17, i64* %4
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %5
br label %21
21: ; preds = %30, %0
%22 = load i32, i32* %5
%23 = load i32, i32* %2
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %21
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %19, i64 %27
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %28)
br label %30
30: ; preds = %25
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %21
33: ; preds = %21
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %35
35: ; preds = %45, %33
%36 = load i32, i32* %6
%37 = load i32, i32* %2
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %48
39: ; preds = %35
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %19, i64 %41
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %39
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %35
48: ; preds = %35
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 32, i32* %11
store i32 0, i32* %12
br label %50
50: ; preds = %62, %48
%51 = load i32, i32* %12
%52 = load i32, i32* %2
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %66
54: ; preds = %50
%55 = load i32, i32* %12
%56 = load i32, i32* %12
%57 = add nsw i32 %56, 31
%58 = load i32, i32* %2
%59 = sub nsw i32 %58, 1
%60 = call i32 @minimum(i32 %57, i32 %59)
%61 = call i32 @insertionSort(i32* %19, i32 %55, i32 %60)
br label %62
62: ; preds = %54
%63 = load i32, i32* %11
%64 = load i32, i32* %12
%65 = add nsw i32 %64, %63
store i32 %65, i32* %12
br label %50
66: ; preds = %50
%67 = load i32, i32* %11
store i32 %67, i32* %7
br label %68
68: ; preds = %100, %66
%69 = load i32, i32* %7
%70 = load i32, i32* %2
%71 = icmp slt i32 %69, %70
br i1 %71, label %72, label %103
72: ; preds = %68
store i32 0, i32* %8
br label %73
73: ; preds = %94, %72
%74 = load i32, i32* %8
%75 = load i32, i32* %2
%76 = icmp slt i32 %74, %75
br i1 %76, label %77, label %99
77: ; preds = %73
%78 = load i32, i32* %8
%79 = load i32, i32* %7
%80 = add nsw i32 %78, %79
%81 = sub nsw i32 %80, 1
store i32 %81, i32* %9
%82 = load i32, i32* %8
%83 = load i32, i32* %7
%84 = mul nsw i32 2, %83
%85 = add nsw i32 %82, %84
%86 = sub nsw i32 %85, 1
%87 = load i32, i32* %2
%88 = sub nsw i32 %87, 1
%89 = call i32 @minimum(i32 %86, i32 %88)
store i32 %89, i32* %10
%90 = load i32, i32* %8
%91 = load i32, i32* %9
%92 = load i32, i32* %10
%93 = call i32 @merge(i32* %19, i32 %90, i32 %91, i32 %92)
br label %94
94: ; preds = %77
%95 = load i32, i32* %7
%96 = mul nsw i32 2, %95
%97 = load i32, i32* %8
%98 = add nsw i32 %97, %96
store i32 %98, i32* %8
br label %73
99: ; preds = %73
br label %100
100: ; preds = %99
%101 = load i32, i32* %7
%102 = mul nsw i32 2, %101
store i32 %102, i32* %7
br label %68
103: ; preds = %68
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %13
br label %105
105: ; preds = %115, %103
%106 = load i32, i32* %13
%107 = load i32, i32* %2
%108 = icmp slt i32 %106, %107
br i1 %108, label %109, label %118
109: ; preds = %105
%110 = load i32, i32* %13
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i32, i32* %19, i64 %111
%113 = load i32, i32* %112
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %113)
br label %115
115: ; preds = %109
%116 = load i32, i32* %13
%117 = add nsw i32 %116, 1
store i32 %117, i32* %13
br label %105
118: ; preds = %105
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
%120 = load i8*, i8** %3
%121 = load i32, i32* %1
ret i32 %121
}

LLVM IR (-O2):
@.str = [41 x i8] c"Enter number of elements in your array: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"Enter your array: \00"
@.str.4 = [5 x i8] c"%d \00"
@str = [18 x i8] c"Unsorted Array : \00"
@str.7 = [16 x i8] c"Sorted Array : \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
%8 = alloca i32, i64 %6
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %16, %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%14 = load i32, i32* %1
%15 = icmp sgt i32 %14, 0
br i1 %15, label %28, label %24
16: ; preds = %0, %16
%17 = phi i64 [ %20, %16 ], [ 0, %0 ]
%18 = getelementptr inbounds i32, i32* %8, i64 %17
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = add nuw nsw i64 %17, 1
%21 = load i32, i32* %1
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %16, label %12
24: ; preds = %28, %12
%25 = call i32 @putchar(i32 10)
%26 = load i32, i32* %1
%27 = icmp sgt i32 %26, 0
br i1 %27, label %39, label %73
28: ; preds = %12, %28
%29 = phi i64 [ %33, %28 ], [ 0, %12 ]
%30 = getelementptr inbounds i32, i32* %8, i64 %29
%31 = load i32, i32* %30
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = add nuw nsw i64 %29, 1
%34 = load i32, i32* %1
%35 = sext i32 %34 to i64
%36 = icmp slt i64 %33, %35
br i1 %36, label %28, label %24
37: ; preds = %39
%38 = icmp sgt i32 %47, 32
br i1 %38, label %49, label %73
39: ; preds = %24, %39
%40 = phi i32 [ %47, %39 ], [ %26, %24 ]
%41 = phi i32 [ %46, %39 ], [ 0, %24 ]
%42 = or i32 %41, 31
%43 = add nsw i32 %40, -1
%44 = call i32 @minimum(i32 %42, i32 %43)
%45 = call i32 @insertionSort(i32* %8, i32 %41, i32 %44)
%46 = add nuw nsw i32 %41, 32
%47 = load i32, i32* %1
%48 = icmp slt i32 %46, %47
br i1 %48, label %39, label %37
49: ; preds = %37, %69
%50 = phi i32 [ %71, %69 ], [ %47, %37 ]
%51 = phi i32 [ %70, %69 ], [ 32, %37 ]
%52 = icmp sgt i32 %50, 0
br i1 %52, label %55, label %53
53: ; preds = %49
%54 = shl nsw i32 %51, 1
br label %69
55: ; preds = %49
%56 = add i32 %51, -1
%57 = shl nsw i32 %51, 1
br label %58
58: ; preds = %55, %58
%59 = phi i32 [ %50, %55 ], [ %67, %58 ]
%60 = phi i32 [ 0, %55 ], [ %62, %58 ]
%61 = add i32 %56, %60
%62 = add nsw i32 %60, %57
%63 = add nsw i32 %62, -1
%64 = add nsw i32 %59, -1
%65 = call i32 @minimum(i32 %63, i32 %64)
%66 = call i32 @merge(i32* %8, i32 %60, i32 %61, i32 %65)
%67 = load i32, i32* %1
%68 = icmp slt i32 %62, %67
br i1 %68, label %58, label %69
69: ; preds = %58, %53
%70 = phi i32 [ %54, %53 ], [ %57, %58 ]
%71 = phi i32 [ %50, %53 ], [ %67, %58 ]
%72 = icmp slt i32 %70, %71
br i1 %72, label %49, label %73
73: ; preds = %69, %24, %37
%74 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
%75 = load i32, i32* %1
%76 = icmp sgt i32 %75, 0
br i1 %76, label %79, label %77
77: ; preds = %79, %73
%78 = call i32 @putchar(i32 10)
ret i32 0
79: ; preds = %73, %79
%80 = phi i64 [ %84, %79 ], [ 0, %73 ]
%81 = getelementptr inbounds i32, i32* %8, i64 %80
%82 = load i32, i32* %81
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %82)
%84 = add nuw nsw i64 %80, 1
%85 = load i32, i32* %1
%86 = sext i32 %85 to i64
%87 = icmp slt i64 %84, %86
br i1 %87, label %79, label %77
}