#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*/ assert_values(int *, int *, int);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ merge_sort(int *, int *, int);
int main(void) {
  int i;
  int arr[1000000], expected[1000000];
  int *res = (int *)malloc(1000000 * sizeof(int));
  for (i = 0; i < 1000000; ++i)
    expected[i] = i;
  for (i = 1000000 - 1; i >= 0; --i)
    arr[i] = i;
  merge_sort(res, arr, 1000000);
  assert_values(res, expected, 1000000);
  free(res);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7a1220,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3d0900,%edi
call   1050 <malloc@plt>
mov    %rax,-0x7a1218(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0xf4240,-0x8(%rbp)
jge    1193 <main+0x53>
mov    -0x8(%rbp),%ecx
movslq -0x8(%rbp),%rax
mov    %ecx,-0x7a1210(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116a <main+0x2a>
movl   $0xf423f,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11c0 <main+0x80>
mov    -0x8(%rbp),%ecx
movslq -0x8(%rbp),%rax
mov    %ecx,-0x3d0910(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    119a <main+0x5a>
mov    -0x7a1218(%rbp),%rdi
lea    -0x3d0910(%rbp),%rsi
mov    $0xf4240,%edx
call   1060 <merge_sort@plt>
mov    -0x7a1218(%rbp),%rdi
lea    -0x7a1210(%rbp),%rsi
mov    $0xf4240,%edx
call   1040 <assert_values@plt>
mov    -0x7a1218(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x7a1220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x7a1200,%rsp
mov    $0x3d0900,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movdqa 0xea3(%rip),%xmm0
mov    $0x24,%eax
movdqa 0xea5(%rip),%xmm8
movdqa 0xeac(%rip),%xmm9
movdqa 0xeb3(%rip),%xmm10
movdqa 0xeba(%rip),%xmm11
movdqa 0xec1(%rip),%xmm12
movdqa 0xec9(%rip),%xmm6
movdqa 0xed1(%rip),%xmm7
movdqa 0xed9(%rip),%xmm1
movdqa 0xee1(%rip),%xmm2
movdqa 0xee9(%rip),%xmm3
nopw   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm4
paddd  %xmm8,%xmm4
movdqa %xmm0,-0x90(%rsp,%rax,4)
ff ff
movdqa %xmm4,-0x80(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm9,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm10,%xmm5
movdqa %xmm4,-0x70(%rsp,%rax,4)
movdqa %xmm5,-0x60(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm11,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm12,%xmm5
movdqa %xmm4,-0x50(%rsp,%rax,4)
movdqa %xmm5,-0x40(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm6,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm7,%xmm5
movdqa %xmm4,-0x30(%rsp,%rax,4)
movdqa %xmm5,-0x20(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm1,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqa %xmm4,-0x10(%rsp,%rax,4)
movdqa %xmm5,(%rsp,%rax,4)
paddd  %xmm3,%xmm0
add    $0x28,%rax
cmp    $0xf4264,%rax
jne    11c0 <main+0x80>
movdqa 0xe49(%rip),%xmm0
mov    $0xf4240,%eax
movdqa 0xe4c(%rip),%xmm1
movdqa 0xe54(%rip),%xmm2
movdqa 0xe5c(%rip),%xmm3
movdqa 0xe64(%rip),%xmm4
nopl   0x0(%rax)
movdqa %xmm0,%xmm5
paddd  %xmm1,%xmm5
pshufd $0x1b,%xmm0,%xmm6
movdqa %xmm6,0x3d08f0(%rsp,%rax,4)
pshufd $0x1b,%xmm5,%xmm5
movdqa %xmm5,0x3d08e0(%rsp,%rax,4)
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqa %xmm0,%xmm6
paddd  %xmm3,%xmm6
pshufd $0x1b,%xmm5,%xmm5
movdqa %xmm5,0x3d08d0(%rsp,%rax,4)
pshufd $0x1b,%xmm6,%xmm5
movdqa %xmm5,0x3d08c0(%rsp,%rax,4)
paddd  %xmm4,%xmm0
add    $0xfffffffffffffff0,%rax
jne    1290 <main+0x150>
lea    0x3d0900(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xf4240,%edx
call   1060 <merge_sort@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xf4240,%edx
call   1040 <assert_values@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x7a1200,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1000000 x i32]
%4 = alloca [1000000 x i32]
%5 = alloca i32*
store i32 0, i32* %1
%6 = call i64 @malloc(i32 4000000)
%7 = inttoptr i64 %6 to i32*
store i32* %7, i32** %5
store i32 0, i32* %2
br label %8
8: ; preds = %16, %0
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 1000000
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i32, i32* %2
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %4, i64 0, i64 %14
store i32 %12, i32* %15
br label %16
16: ; preds = %11
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 1
store i32 %18, i32* %2
br label %8
19: ; preds = %8
store i32 999999, i32* %2
br label %20
20: ; preds = %28, %19
%21 = load i32, i32* %2
%22 = icmp sge i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i32, i32* %2
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %3, i64 0, i64 %26
store i32 %24, i32* %27
br label %28
28: ; preds = %23
%29 = load i32, i32* %2
%30 = add nsw i32 %29, -1
store i32 %30, i32* %2
br label %20
31: ; preds = %20
%32 = load i32*, i32** %5
%33 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %3, i64 0, i64 0
%34 = call i32 @merge_sort(i32* %32, i32* %33, i32 1000000)
%35 = load i32*, i32** %5
%36 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %4, i64 0, i64 0
%37 = call i32 @assert_values(i32* %35, i32* %36, i32 1000000)
%38 = load i32*, i32** %5
%39 = call i32 @free(i32* %38)
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [1000000 x i32]
%2 = alloca [1000000 x i32]
%3 = bitcast [1000000 x i32]* %1 to i8*
%4 = bitcast [1000000 x i32]* %2 to i8*
%5 = tail call i64 @malloc(i32 4000000)
br label %6
6: ; preds = %6, %0
%7 = phi i64 [ 0, %0 ], [ %42, %6 ]
%8 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %43, %6 ]
%9 = add <4 x i32> %8, <i32 4, i32 4, i32 4, i32 4>
%10 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 %7
%11 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> %8, <4 x i32>* %11
%12 = getelementptr inbounds i32, i32* %10, i64 4
%13 = bitcast i32* %12 to <4 x i32>*
store <4 x i32> %9, <4 x i32>* %13
%14 = add nuw nsw i64 %7, 8
%15 = add <4 x i32> %8, <i32 8, i32 8, i32 8, i32 8>
%16 = add <4 x i32> %8, <i32 12, i32 12, i32 12, i32 12>
%17 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 %14
%18 = bitcast i32* %17 to <4 x i32>*
store <4 x i32> %15, <4 x i32>* %18
%19 = getelementptr inbounds i32, i32* %17, i64 4
%20 = bitcast i32* %19 to <4 x i32>*
store <4 x i32> %16, <4 x i32>* %20
%21 = add nuw nsw i64 %7, 16
%22 = add <4 x i32> %8, <i32 16, i32 16, i32 16, i32 16>
%23 = add <4 x i32> %8, <i32 20, i32 20, i32 20, i32 20>
%24 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 %21
%25 = bitcast i32* %24 to <4 x i32>*
store <4 x i32> %22, <4 x i32>* %25
%26 = getelementptr inbounds i32, i32* %24, i64 4
%27 = bitcast i32* %26 to <4 x i32>*
store <4 x i32> %23, <4 x i32>* %27
%28 = add nuw nsw i64 %7, 24
%29 = add <4 x i32> %8, <i32 24, i32 24, i32 24, i32 24>
%30 = add <4 x i32> %8, <i32 28, i32 28, i32 28, i32 28>
%31 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 %28
%32 = bitcast i32* %31 to <4 x i32>*
store <4 x i32> %29, <4 x i32>* %32
%33 = getelementptr inbounds i32, i32* %31, i64 4
%34 = bitcast i32* %33 to <4 x i32>*
store <4 x i32> %30, <4 x i32>* %34
%35 = add nuw nsw i64 %7, 32
%36 = add <4 x i32> %8, <i32 32, i32 32, i32 32, i32 32>
%37 = add <4 x i32> %8, <i32 36, i32 36, i32 36, i32 36>
%38 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 %35
%39 = bitcast i32* %38 to <4 x i32>*
store <4 x i32> %36, <4 x i32>* %39
%40 = getelementptr inbounds i32, i32* %38, i64 4
%41 = bitcast i32* %40 to <4 x i32>*
store <4 x i32> %37, <4 x i32>* %41
%42 = add nuw nsw i64 %7, 40
%43 = add <4 x i32> %8, <i32 40, i32 40, i32 40, i32 40>
%44 = icmp eq i64 %42, 1000000
br i1 %44, label %45, label %6
45: ; preds = %6, %45
%46 = phi i64 [ %67, %45 ], [ 0, %6 ]
%47 = phi <4 x i32> [ %68, %45 ], [ <i32 999999, i32 999998, i32 999997, i32 999996>, %6 ]
%48 = sub nuw nsw i64 999999, %46
%49 = add <4 x i32> %47, <i32 -4, i32 -4, i32 -4, i32 -4>
%50 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 %48
%51 = shufflevector <4 x i32> %47, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
%52 = getelementptr inbounds i32, i32* %50, i64 -3
%53 = bitcast i32* %52 to <4 x i32>*
store <4 x i32> %51, <4 x i32>* %53
%54 = shufflevector <4 x i32> %49, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
%55 = getelementptr inbounds i32, i32* %50, i64 -7
%56 = bitcast i32* %55 to <4 x i32>*
store <4 x i32> %54, <4 x i32>* %56
%57 = add <4 x i32> %47, <i32 -8, i32 -8, i32 -8, i32 -8>
%58 = sub nsw i64 999991, %46
%59 = add <4 x i32> %47, <i32 -12, i32 -12, i32 -12, i32 -12>
%60 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 %58
%61 = shufflevector <4 x i32> %57, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
%62 = getelementptr inbounds i32, i32* %60, i64 -3
%63 = bitcast i32* %62 to <4 x i32>*
store <4 x i32> %61, <4 x i32>* %63
%64 = shufflevector <4 x i32> %59, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
%65 = getelementptr inbounds i32, i32* %60, i64 -7
%66 = bitcast i32* %65 to <4 x i32>*
store <4 x i32> %64, <4 x i32>* %66
%67 = add nuw nsw i64 %46, 16
%68 = add <4 x i32> %47, <i32 -16, i32 -16, i32 -16, i32 -16>
%69 = icmp eq i64 %67, 1000000
br i1 %69, label %70, label %45
70: ; preds = %45
%71 = inttoptr i64 %5 to i32*
%72 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 0
%73 = call i32 @merge_sort(i32* %71, i32* %72, i32 1000000)
%74 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 0
%75 = call i32 @assert_values(i32* %71, i32* %74, i32 1000000)
%76 = call i32 @free(i32* %71)
ret i32 0
}