#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*/ merge_pass(int *, int *, int, int);
void merge_sort(int list[], int n) {
  int length = 0x01;
  int sort[(10)] = {0};
  while (length < n) {
    merge_pass(list, sort, n, length);
    length *= 2;
    merge_pass(sort, list, n, length);
    length *= 2;
  }
  return;
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118f <merge_sort+0x6f>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1040 <merge_pass@plt>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1040 <merge_pass@plt>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1146 <merge_sort+0x26>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movq   $0x0,0x20(%rsp)
cmp    $0x2,%esi
jl     1176 <merge_sort+0x66>
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0x1,%ebx
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1030 <merge_pass@plt>
lea    (%rbx,%rbx,1),%ecx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <merge_pass@plt>
shl    $0x2,%ebx
cmp    %ebp,%ebx
jl     1150 <merge_sort+0x40>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @merge_sort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x i32]
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 1, i32* %5
%7 = bitcast [10 x i32]* %6 to i8*
br label %8
8: ; preds = %12, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %27
12: ; preds = %8
%13 = load i32*, i32** %3
%14 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = call i32 @merge_pass(i32* %13, i32* %14, i32 %15, i32 %16)
%18 = load i32, i32* %5
%19 = mul nsw i32 %18, 2
store i32 %19, i32* %5
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%21 = load i32*, i32** %3
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = call i32 @merge_pass(i32* %20, i32* %21, i32 %22, i32 %23)
%25 = load i32, i32* %5
%26 = mul nsw i32 %25, 2
store i32 %26, i32* %5
br label %8
27: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @merge_sort(i32* %0, i32 %1) {
%3 = alloca [10 x i32]
%4 = bitcast [10 x i32]* %3 to i8*
%5 = icmp sgt i32 %1, 1
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
br label %8
8: ; preds = %6, %8
%9 = phi i32 [ 1, %6 ], [ %13, %8 ]
%10 = call i32 @merge_pass(i32* %0, i32* %7, i32 %1, i32 %9)
%11 = shl nuw nsw i32 %9, 1
%12 = call i32 @merge_pass(i32* %7, i32* %0, i32 %1, i32 %11)
%13 = shl nsw i32 %9, 2
%14 = icmp slt i32 %13, %1
br i1 %14, label %8, label %15
15: ; preds = %8, %2
ret void
}