#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*/ mergesort(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
void main() {
  int n, i, a[20];
  printf("Enter the number of elements\n");
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    a[i] = rand() % 1000;
  printf("The array before sorting \n");
  for (i = 0; i < n; i++)
    printf("%d\t", a[i]);
  mergesort(a, 0, n - 1);
  printf("\nThe array after sorting\n");
  for (i = 0; i < n; i++)
    printf("%d\t", a[i]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec1(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119e <main+0x5e>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
movslq -0x8(%rbp),%rax
mov    %edx,-0x60(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116d <main+0x2d>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e3 <main+0xa3>
movslq -0x8(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b3 <main+0x73>
lea    -0x60(%rbp),%rdi
mov    -0x4(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1050 <mergesort@plt>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1239 <main+0xf9>
movslq -0x8(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1209 <main+0xc9>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
lea    0xe96(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11b7 <main+0x67>
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1180 <main+0x30>
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%edx
test   %edx,%edx
jle    11fc <main+0xac>
lea    0xe31(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rdx
cmp    %rdx,%rbx
jl     11e0 <main+0x90>
add    $0xffffffff,%edx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1060 <mergesort@plt>
lea    0xe2c(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    124c <main+0xfc>
lea    0xdde(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1230 <main+0xe0>
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Enter the number of elements\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"The array before sorting \0A\00"
@.str.3 = [4 x i8] c"%d\09\00"
@.str.4 = [26 x i8] c"\0AThe array after sorting\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [20 x i32]
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
store i32 0, i32* %2
br label %6
6: ; preds = %16, %0
%7 = load i32, i32* %2
%8 = load i32, i32* %1
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %19
10: ; preds = %6
%11 = call i32 (...) @rand()
%12 = srem i32 %11, 1000
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %14
store i32 %12, i32* %15
br label %16
16: ; preds = %10
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 1
store i32 %18, i32* %2
br label %6
19: ; preds = %6
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %21
21: ; preds = %31, %19
%22 = load i32, i32* %2
%23 = load i32, i32* %1
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %34
25: ; preds = %21
%26 = load i32, i32* %2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %25
%32 = load i32, i32* %2
%33 = add nsw i32 %32, 1
store i32 %33, i32* %2
br label %21
34: ; preds = %21
%35 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%36 = load i32, i32* %1
%37 = sub nsw i32 %36, 1
%38 = call i32 @mergesort(i32* %35, i32 0, i32 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %2
br label %40
40: ; preds = %50, %34
%41 = load i32, i32* %2
%42 = load i32, i32* %1
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %53
44: ; preds = %40
%45 = load i32, i32* %2
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %44
%51 = load i32, i32* %2
%52 = add nsw i32 %51, 1
store i32 %52, i32* %2
br label %40
53: ; preds = %40
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d\09\00"
@str = [29 x i8] c"Enter the number of elements\00"
@str.5 = [26 x i8] c"The array before sorting \00"
@str.6 = [25 x i8] c"\0AThe array after sorting\00"
define void @main() {
%1 = alloca i32
%2 = alloca [20 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [20 x i32]* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %0, %9
%10 = phi i64 [ %14, %9 ], [ 0, %0 ]
%11 = call i32 (...) @rand()
%12 = srem i32 %11, 1000
%13 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %10
store i32 %12, i32* %13
%14 = add nuw nsw i64 %10, 1
%15 = load i32, i32* %1
%16 = sext i32 %15 to i64
%17 = icmp slt i64 %14, %16
br i1 %17, label %9, label %18
18: ; preds = %9, %0
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.5, i64 0, i64 0))
%20 = load i32, i32* %1
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %18, %22
%23 = phi i64 [ %27, %22 ], [ 0, %18 ]
%24 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = add nuw nsw i64 %23, 1
%28 = load i32, i32* %1
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %27, %29
br i1 %30, label %22, label %31
31: ; preds = %22, %18
%32 = phi i32 [ %20, %18 ], [ %28, %22 ]
%33 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%34 = add nsw i32 %32, -1
%35 = call i32 @mergesort(i32* %33, i32 0, i32 %34)
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
%37 = load i32, i32* %1
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %48
39: ; preds = %31, %39
%40 = phi i64 [ %44, %39 ], [ 0, %31 ]
%41 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %42)
%44 = add nuw nsw i64 %40, 1
%45 = load i32, i32* %1
%46 = sext i32 %45 to i64
%47 = icmp slt i64 %44, %46
br i1 %47, label %39, label %48
48: ; preds = %39, %31
ret void
}