#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*/ mergesort_bottom_up(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ print_list(int *, int);
int /*<<< orphan*/ printf(char *);
int rand();
int main() {
  int l[42];
  int size = 42;
  int c;
  for (c = 0; c < size; c++)
    l[c] = rand() % 100;
  printf("out of order:\n");
  print_list(l, size);
  mergesort(l, 0, size - 1);
  printf("in order mergesort:\n");
  print_list(l, size);
  for (c = 0; c < size; c++)
    l[c] = rand() % 100;
  printf("\nout of order:\n");
  print_list(l, size);
  mergesort_bottom_up(l, 0, size - 1);
  printf("in order bottom-up mergesort:\n");
  print_list(l, size);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2a,-0xb4(%rbp)
movl   $0x0,-0xb8(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0xb4(%rbp),%eax
jge    11b9 <main+0x69>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
movslq -0xb8(%rbp),%rax
mov    %edx,-0xb0(%rbp,%rax,4)
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    1176 <main+0x26>
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
lea    -0xb0(%rbp),%rdi
mov    -0xb4(%rbp),%esi
call   1030 <print_list@plt>
lea    -0xb0(%rbp),%rdi
mov    -0xb4(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1060 <mergesort@plt>
lea    0xe0b(%rip),%rdi
call   1040 <printf@plt>
lea    -0xb0(%rbp),%rdi
mov    -0xb4(%rbp),%esi
call   1030 <print_list@plt>
movl   $0x0,-0xb8(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0xb4(%rbp),%eax
jge    1259 <main+0x109>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
movslq -0xb8(%rbp),%rax
mov    %edx,-0xb0(%rbp,%rax,4)
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    1216 <main+0xc6>
lea    0xdb5(%rip),%rdi
call   1040 <printf@plt>
lea    -0xb0(%rbp),%rdi
mov    -0xb4(%rbp),%esi
call   1030 <print_list@plt>
lea    -0xb0(%rbp),%rdi
mov    -0xb4(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1050 <mergesort_bottom_up@plt>
lea    0xd90(%rip),%rdi
call   1040 <printf@plt>
lea    -0xb0(%rbp),%rdi
mov    -0xb4(%rbp),%esi
call   1030 <print_list@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xb0,%rsp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x2a,%rbx
jne    1160 <main+0x10>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x2a,%esi
call   1040 <print_list@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x29,%edx
call   1060 <mergesort@plt>
lea    0xe3f(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x2a,%esi
call   1040 <print_list@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x2a,%rbx
jne    11e0 <main+0x90>
lea    0xdfe(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x2a,%esi
call   1040 <print_list@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x29,%edx
call   1050 <mergesort_bottom_up@plt>
lea    0xde2(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x2a,%esi
call   1040 <print_list@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"out of order:\0A\00"
@.str.1 = [21 x i8] c"in order mergesort:\0A\00"
@.str.2 = [16 x i8] c"\0Aout of order:\0A\00"
@.str.3 = [31 x i8] c"in order bottom-up mergesort:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [42 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 42, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %15, %0
%6 = load i32, i32* %4
%7 = load i32, i32* %3
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %18
9: ; preds = %5
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 100
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [42 x i32], [42 x i32]* %2, i64 0, i64 %13
store i32 %11, i32* %14
br label %15
15: ; preds = %9
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %5
18: ; preds = %5
%19 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%20 = getelementptr inbounds [42 x i32], [42 x i32]* %2, i64 0, i64 0
%21 = load i32, i32* %3
%22 = call i32 @print_list(i32* %20, i32 %21)
%23 = getelementptr inbounds [42 x i32], [42 x i32]* %2, i64 0, i64 0
%24 = load i32, i32* %3
%25 = sub nsw i32 %24, 1
%26 = call i32 @mergesort(i32* %23, i32 0, i32 %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%28 = getelementptr inbounds [42 x i32], [42 x i32]* %2, i64 0, i64 0
%29 = load i32, i32* %3
%30 = call i32 @print_list(i32* %28, i32 %29)
store i32 0, i32* %4
br label %31
31: ; preds = %41, %18
%32 = load i32, i32* %4
%33 = load i32, i32* %3
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %44
35: ; preds = %31
%36 = call i32 (...) @rand()
%37 = srem i32 %36, 100
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [42 x i32], [42 x i32]* %2, i64 0, i64 %39
store i32 %37, i32* %40
br label %41
41: ; preds = %35
%42 = load i32, i32* %4
%43 = add nsw i32 %42, 1
store i32 %43, i32* %4
br label %31
44: ; preds = %31
%45 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%46 = getelementptr inbounds [42 x i32], [42 x i32]* %2, i64 0, i64 0
%47 = load i32, i32* %3
%48 = call i32 @print_list(i32* %46, i32 %47)
%49 = getelementptr inbounds [42 x i32], [42 x i32]* %2, i64 0, i64 0
%50 = load i32, i32* %3
%51 = sub nsw i32 %50, 1
%52 = call i32 @mergesort_bottom_up(i32* %49, i32 0, i32 %51)
%53 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%54 = getelementptr inbounds [42 x i32], [42 x i32]* %2, i64 0, i64 0
%55 = load i32, i32* %3
%56 = call i32 @print_list(i32* %54, i32 %55)
ret i32 0
}

LLVM IR (-O2):
@str = [14 x i8] c"out of order:\00"
@str.4 = [20 x i8] c"in order mergesort:\00"
@str.5 = [15 x i8] c"\0Aout of order:\00"
@str.6 = [30 x i8] c"in order bottom-up mergesort:\00"
define i32 @main() {
%1 = alloca [42 x i32]
%2 = bitcast [42 x i32]* %1 to i8*
br label %3
3: ; preds = %0, %3
%4 = phi i64 [ 0, %0 ], [ %8, %3 ]
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 100
%7 = getelementptr inbounds [42 x i32], [42 x i32]* %1, i64 0, i64 %4
store i32 %6, i32* %7
%8 = add nuw nsw i64 %4, 1
%9 = icmp eq i64 %8, 42
br i1 %9, label %10, label %3
10: ; preds = %3
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%12 = getelementptr inbounds [42 x i32], [42 x i32]* %1, i64 0, i64 0
%13 = call i32 @print_list(i32* %12, i32 42)
%14 = call i32 @mergesort(i32* %12, i32 0, i32 41)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0))
%16 = call i32 @print_list(i32* %12, i32 42)
br label %17
17: ; preds = %10, %17
%18 = phi i64 [ 0, %10 ], [ %22, %17 ]
%19 = call i32 (...) @rand()
%20 = srem i32 %19, 100
%21 = getelementptr inbounds [42 x i32], [42 x i32]* %1, i64 0, i64 %18
store i32 %20, i32* %21
%22 = add nuw nsw i64 %18, 1
%23 = icmp eq i64 %22, 42
br i1 %23, label %24, label %17
24: ; preds = %17
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.5, i64 0, i64 0))
%26 = call i32 @print_list(i32* %12, i32 42)
%27 = call i32 @mergesort_bottom_up(i32* %12, i32 0, i32 41)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.6, i64 0, i64 0))
%29 = call i32 @print_list(i32* %12, i32 42)
ret i32 0
}