#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_array(int *, int, int *, int);
void merge_sort(int *list, int list_size) {
  if (list_size > 1) {
    int *list1 = list;
    int list1_size = list_size / 2;
    int *list2 = list + list_size / 2;
    int list2_size = list_size - list1_size;
    merge_sort(list1, list1_size);
    merge_sort(list2, list2_size);
    merge_array(list1, list1_size, list2, list2_size);
  }
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jle    11aa <merge_sort+0x8a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <merge_sort@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1040 <merge_sort@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1030 <merge_array@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
cmp    $0x1,%esi
jle    116c <merge_sort+0x4c>
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
mov    %esi,%r15d
shr    %r15d
lea    (%rdi,%r15,4),%r12
sub    %r15d,%ebx
mov    %r15d,%esi
call   1040 <merge_sort@plt>
mov    %r12,%rdi
mov    %ebx,%esi
call   1040 <merge_sort@plt>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12,%rdx
mov    %ebx,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <merge_array@plt>
ret

LLVM IR (-O0):
define void @merge_sort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %32
11: ; preds = %2
%12 = load i32*, i32** %3
store i32* %12, i32** %5
%13 = load i32, i32* %4
%14 = sdiv i32 %13, 2
store i32 %14, i32* %6
%15 = load i32*, i32** %3
%16 = load i32, i32* %4
%17 = sdiv i32 %16, 2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %15, i64 %18
store i32* %19, i32** %7
%20 = load i32, i32* %4
%21 = load i32, i32* %6
%22 = sub nsw i32 %20, %21
store i32 %22, i32* %8
%23 = load i32*, i32** %5
%24 = load i32, i32* %6
%25 = load i32*, i32** %7
%26 = load i32, i32* %8
%27 = load i32*, i32** %5
%28 = load i32, i32* %6
%29 = load i32*, i32** %7
%30 = load i32, i32* %8
%31 = call i32 @merge_array(i32* %27, i32 %28, i32* %29, i32 %30)
br label %32
32: ; preds = %11, %2
ret void
}

LLVM IR (-O2):
define void @merge_sort(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %5, label %4
4: ; preds = %2, %5
ret void
5: ; preds = %2
%6 = lshr i32 %1, 1
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = sub nsw i32 %1, %6
tail call void @merge_sort(i32* %0, i32 %6)
tail call void @merge_sort(i32* %8, i32 %9)
%10 = tail call i32 @merge_array(i32* %0, i32 %6, i32* %8, i32 %9)
br label %4
}