#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ merge_sort(int *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int rand();
int merge_test(void) {
  uint32_t i, x[20];
  for (i = 0; i < 20; i++)
    x[i] = rand() % 20;
  puts("before sort:");
  for (i = 0; i < 20; i++)
    printf("%d ", x[i]);
  putchar('\n');
  merge_sort(x, 20);
  puts("after sort:");
  for (i = 0; i < 20; i++)
    printf("%d ", x[i]);
  putchar('\n');
  return 0;
}


x86 assembly (clang, -O0):
<merge_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x14,-0x4(%rbp)
jge    118e <merge_test+0x3e>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x14,%ecx
cltd
idiv   %ecx
movslq -0x4(%rbp),%rax
mov    %edx,-0x60(%rbp,%rax,4)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    115f <merge_test+0xf>
lea    0xe6b(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x14,-0x4(%rbp)
jge    11cd <merge_test+0x7d>
movslq -0x4(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xe53(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11a1 <merge_test+0x51>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    -0x60(%rbp),%rdi
mov    $0x14,%esi
call   1060 <merge_sort@plt>
lea    0xe25(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x14,-0x4(%rbp)
jge    1224 <merge_test+0xd4>
movslq -0x4(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xdfc(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11f8 <merge_test+0xa8>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_test>:
push   %rbx
sub    $0x50,%rsp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
shl    $0x2,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x14,%rbx
jne    1160 <merge_test+0x10>
lea    0xe67(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%esi
lea    0xe65(%rip),%rbx
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x20(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x24(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x28(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x2c(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x30(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x34(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x38(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x3c(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x40(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x44(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x48(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x4c(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rsp,%rdi
mov    $0x14,%esi
call   1060 <merge_sort@plt>
lea    0xd5f(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x20(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x24(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x28(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x2c(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x30(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x34(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x38(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x3c(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x40(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x44(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x48(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x4c(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"before sort:\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [12 x i8] c"after sort:\00"
define i32 @merge_test() {
%1 = alloca i32
%2 = alloca [20 x i32]
store i32 0, i32* %1
br label %3
3: ; preds = %12, %0
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 20
br i1 %5, label %6, label %15
6: ; preds = %3
%7 = call i32 (...) @rand()
%8 = srem i32 %7, 20
%9 = load i32, i32* %1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %10
store i32 %8, i32* %11
br label %12
12: ; preds = %6
%13 = load i32, i32* %1
%14 = add nsw i32 %13, 1
store i32 %14, i32* %1
br label %3
15: ; preds = %3
%16 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %17
17: ; preds = %26, %15
%18 = load i32, i32* %1
%19 = icmp slt i32 %18, 20
br i1 %19, label %20, label %29
20: ; preds = %17
%21 = load i32, i32* %1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %20
%27 = load i32, i32* %1
%28 = add nsw i32 %27, 1
store i32 %28, i32* %1
br label %17
29: ; preds = %17
%30 = call i32 @putchar(i8 signext 10)
%31 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%32 = call i32 @merge_sort(i32* %31, i32 20)
%33 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %34
34: ; preds = %43, %29
%35 = load i32, i32* %1
%36 = icmp slt i32 %35, 20
br i1 %36, label %37, label %46
37: ; preds = %34
%38 = load i32, i32* %1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %37
%44 = load i32, i32* %1
%45 = add nsw i32 %44, 1
store i32 %45, i32* %1
br label %34
46: ; preds = %34
%47 = call i32 @putchar(i8 signext 10)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"before sort:\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [12 x i8] c"after sort:\00"
define i32 @merge_test() {
%1 = alloca [20 x i32]
%2 = bitcast [20 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, 20
%7 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %4
store i32 %6, i32* %7
%8 = add nuw nsw i64 %4, 1
%9 = icmp eq i64 %8, 20
br i1 %9, label %10, label %3
10: ; preds = %3
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%13 = load i32, i32* %12
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 1
%16 = load i32, i32* %15
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 2
%19 = load i32, i32* %18
%20 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 3
%22 = load i32, i32* %21
%23 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 4
%25 = load i32, i32* %24
%26 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 5
%28 = load i32, i32* %27
%29 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 6
%31 = load i32, i32* %30
%32 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 7
%34 = load i32, i32* %33
%35 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 8
%37 = load i32, i32* %36
%38 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 9
%40 = load i32, i32* %39
%41 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 10
%43 = load i32, i32* %42
%44 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %43)
%45 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 11
%46 = load i32, i32* %45
%47 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 12
%49 = load i32, i32* %48
%50 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %49)
%51 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 13
%52 = load i32, i32* %51
%53 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %52)
%54 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 14
%55 = load i32, i32* %54
%56 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %55)
%57 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 15
%58 = load i32, i32* %57
%59 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %58)
%60 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 16
%61 = load i32, i32* %60
%62 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %61)
%63 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 17
%64 = load i32, i32* %63
%65 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %64)
%66 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 18
%67 = load i32, i32* %66
%68 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %67)
%69 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 19
%70 = load i32, i32* %69
%71 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %70)
%72 = tail call i32 @putchar(i8 signext 10)
%73 = call i32 @merge_sort(i32* %12, i32 20)
%74 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%75 = load i32, i32* %12
%76 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %75)
%77 = load i32, i32* %15
%78 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %77)
%79 = load i32, i32* %18
%80 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %79)
%81 = load i32, i32* %21
%82 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %81)
%83 = load i32, i32* %24
%84 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %83)
%85 = load i32, i32* %27
%86 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %85)
%87 = load i32, i32* %30
%88 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %87)
%89 = load i32, i32* %33
%90 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %89)
%91 = load i32, i32* %36
%92 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %91)
%93 = load i32, i32* %39
%94 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %93)
%95 = load i32, i32* %42
%96 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %95)
%97 = load i32, i32* %45
%98 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %97)
%99 = load i32, i32* %48
%100 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %99)
%101 = load i32, i32* %51
%102 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %101)
%103 = load i32, i32* %54
%104 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %103)
%105 = load i32, i32* %57
%106 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %105)
%107 = load i32, i32* %60
%108 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %107)
%109 = load i32, i32* %63
%110 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %109)
%111 = load i32, i32* %66
%112 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %111)
%113 = load i32, i32* %69
%114 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %113)
%115 = call i32 @putchar(i8 signext 10)
ret i32 0
}