#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ memmove(int *, int *, int);
int *merge(int *, int *, int, int);
int *merge_sort(int *data_set, int size) {
  if (size == 1)
    return data_set;
  int size_a = size / 2;
  int size_b = size - size_a;
  int *part_a = (int *)calloc(size_a, sizeof(int));
  int *part_b = (int *)calloc(size_b, sizeof(int));
  memmove(part_a, data_set, sizeof(int) * size_a);
  memmove(part_b, data_set + size_a, sizeof(int) * size_b);
  free(data_set);
  if (size == 2)
    return merge(part_a, part_b, size_a, size_b);
  else
    return merge(merge_sort(part_a, size_a), merge_sort(part_b, size_b), size_a,
                 size_b);
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1176 <merge_sort+0x26>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1249 <merge_sort+0xf9>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1070 <memmove@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1070 <memmove@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x2,-0x14(%rbp)
jne    1217 <merge_sort+0xc7>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1050 <merge@plt>
mov    %rax,-0x8(%rbp)
jmp    1249 <merge_sort+0xf9>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1060 <merge_sort@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <merge_sort@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rsi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1050 <merge@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
cmp    $0x1,%esi
jne    1178 <merge_sort+0x28>
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %esi,%ebp
mov    %esi,%ebx
shr    $0x1f,%ebx
add    %esi,%ebx
sar    %ebx
mov    %esi,%r14d
sub    %ebx,%r14d
mov    %ebx,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,%r13
mov    %r14d,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,0x10(%rsp)
movslq %ebx,%r12
lea    0x0(,%r12,4),%edx
mov    %r13,0x8(%rsp)
mov    %r13,%rdi
mov    %r15,%rsi
call   1070 <memmove@plt>
lea    (%r15,%r12,4),%rsi
mov    0x10(%rsp),%r12
lea    0x0(,%r14,4),%edx
mov    %r12,%rdi
call   1070 <memmove@plt>
mov    %r15,%rdi
call   1030 <free@plt>
cmp    $0x2,%ebp
jne    11f5 <merge_sort+0xa5>
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
jmp    1215 <merge_sort+0xc5>
mov    0x8(%rsp),%rdi
mov    %ebx,%esi
call   1060 <merge_sort@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %r14d,%esi
call   1060 <merge_sort@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %ebx,%edx
mov    %r14d,%ecx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <merge@plt>

LLVM IR (-O0):
define i32* @merge_sort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
store i32* %0, i32** %4
store i32 %1, i32* %5
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32*, i32** %4
store i32* %13, i32** %3
br label %63
14: ; preds = %2
%15 = load i32, i32* %5
%16 = sdiv i32 %15, 2
store i32 %16, i32* %6
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = sub nsw i32 %17, %18
store i32 %19, i32* %7
%20 = load i32, i32* %6
%21 = call i64 @calloc(i32 %20, i32 4)
%22 = inttoptr i64 %21 to i32*
store i32* %22, i32** %8
%23 = load i32, i32* %7
%24 = call i64 @calloc(i32 %23, i32 4)
%25 = inttoptr i64 %24 to i32*
store i32* %25, i32** %9
%26 = load i32*, i32** %8
%27 = load i32*, i32** %4
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = mul i64 4, %29
%31 = trunc i64 %30 to i32
%32 = call i32 @memmove(i32* %26, i32* %27, i32 %31)
%33 = load i32*, i32** %9
%34 = load i32*, i32** %4
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = mul i64 4, %39
%41 = trunc i64 %40 to i32
%42 = call i32 @memmove(i32* %33, i32* %37, i32 %41)
%43 = load i32*, i32** %4
%44 = call i32 @free(i32* %43)
%45 = load i32, i32* %5
%46 = icmp eq i32 %45, 2
br i1 %46, label %47, label %53
47: ; preds = %14
%48 = load i32*, i32** %8
%49 = load i32*, i32** %9
%50 = load i32, i32* %6
%51 = load i32, i32* %7
%52 = call i32* @merge(i32* %48, i32* %49, i32 %50, i32 %51)
store i32* %52, i32** %3
br label %63
53: ; preds = %14
%54 = load i32*, i32** %8
%55 = load i32, i32* %6
%56 = call i32* @merge_sort(i32* %54, i32 %55)
%57 = load i32*, i32** %9
%58 = load i32, i32* %7
%59 = call i32* @merge_sort(i32* %57, i32 %58)
%60 = load i32, i32* %6
%61 = load i32, i32* %7
%62 = call i32* @merge(i32* %56, i32* %59, i32 %60, i32 %61)
store i32* %62, i32** %3
br label %63
63: ; preds = %53, %47, %12
%64 = load i32*, i32** %3
ret i32* %64
}

LLVM IR (-O2):
define i32* @merge_sort(i32* %0, i32 %1) {
%3 = icmp eq i32 %1, 1
br i1 %3, label %21, label %4
4: ; preds = %2
%5 = sdiv i32 %1, 2
%6 = sub nsw i32 %1, %5
%7 = tail call i64 @calloc(i32 %5, i32 4)
%8 = inttoptr i64 %7 to i32*
%9 = tail call i64 @calloc(i32 %6, i32 4)
%10 = inttoptr i64 %9 to i32*
%11 = sext i32 %5 to i64
%12 = shl i32 %5, 2
%13 = tail call i32 @memmove(i32* %8, i32* %0, i32 %12)
%14 = getelementptr inbounds i32, i32* %0, i64 %11
%15 = shl i32 %6, 2
%16 = tail call i32 @memmove(i32* %10, i32* %14, i32 %15)
%17 = tail call i32 @free(i32* %0)
%18 = icmp eq i32 %1, 2
br i1 %18, label %19, label %23
19: ; preds = %4
%20 = tail call i32* @merge(i32* %8, i32* %10, i32 %5, i32 %6)
br label %21
21: ; preds = %2, %19, %23
%22 = phi i32* [ %26, %23 ], [ %0, %2 ], [ %20, %19 ]
ret i32* %22
23: ; preds = %4
%24 = tail call i32* @merge_sort(i32* %8, i32 %5)
%25 = tail call i32* @merge_sort(i32* %10, i32 %6)
%26 = tail call i32* @merge(i32* %24, i32* %25, i32 %5, i32 %6)
br label %21
}