#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(int *, int *, int, int, int);
void __msort(int origin[], int swap[], int start, int end) {
  int m;
  int temp[1000 + 1];
  if (start == end) {
    swap[start] = origin[start];
    return;
  }
  m = (start + end) / 2;
  __msort(origin, temp, start, m);
  __msort(origin, temp, m + 1, end);
  __merge(temp, swap, start, m, end);
}


x86 assembly (clang, -O0):
<__msort>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1160 <__msort+0x40>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11ba <__msort+0x9a>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0xfc0(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1030 <__msort@plt>
mov    -0x8(%rbp),%rdi
lea    -0xfc0(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
call   1030 <__msort@plt>
lea    -0xfc0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1040 <__merge@plt>
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__msort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xfa8,%rsp
mov    %edx,%r13d
mov    %rsi,%r14
mov    %rdi,%r12
cmp    %ecx,%edx
jne    114b <__msort+0x2b>
movslq %r13d,%rax
mov    (%r12,%rax,4),%ecx
mov    %ecx,(%r14,%rax,4)
jmp    1192 <__msort+0x72>
mov    %ecx,%r15d
lea    (%r15,%r13,1),%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
mov    %rsp,%rbp
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
mov    %ebx,%ecx
call   1030 <__msort@plt>
lea    0x1(%rbx),%edx
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r15d,%ecx
call   1030 <__msort@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r13d,%edx
mov    %ebx,%ecx
mov    %r15d,%r8d
call   1040 <__merge@plt>
add    $0xfa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @__msort(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [1001 x i32]
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32, i32* %7
%12 = load i32, i32* %8
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %24
14: ; preds = %4
%15 = load i32*, i32** %5
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = load i32*, i32** %6
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
store i32 %19, i32* %23
br label %44
24: ; preds = %4
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = add nsw i32 %25, %26
%28 = sdiv i32 %27, 2
store i32 %28, i32* %9
%29 = load i32*, i32** %5
%30 = getelementptr inbounds [1001 x i32], [1001 x i32]* %10, i64 0, i64 0
%31 = load i32, i32* %7
%32 = load i32, i32* %9
%33 = load i32*, i32** %5
%34 = getelementptr inbounds [1001 x i32], [1001 x i32]* %10, i64 0, i64 0
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
%37 = load i32, i32* %8
%38 = getelementptr inbounds [1001 x i32], [1001 x i32]* %10, i64 0, i64 0
%39 = load i32*, i32** %6
%40 = load i32, i32* %7
%41 = load i32, i32* %9
%42 = load i32, i32* %8
%43 = call i32 @__merge(i32* %38, i32* %39, i32 %40, i32 %41, i32 %42)
br label %44
44: ; preds = %24, %14
ret void
}

LLVM IR (-O2):
define void @__msort(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca [1001 x i32]
%6 = bitcast [1001 x i32]* %5 to i8*
%7 = icmp eq i32 %2, %3
br i1 %7, label %8, label %13
8: ; preds = %4
%9 = sext i32 %2 to i64
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = load i32, i32* %10
%12 = getelementptr inbounds i32, i32* %1, i64 %9
store i32 %11, i32* %12
br label %19
13: ; preds = %4
%14 = add nsw i32 %3, %2
%15 = sdiv i32 %14, 2
%16 = getelementptr inbounds [1001 x i32], [1001 x i32]* %5, i64 0, i64 0
%17 = add nsw i32 %15, 1
%18 = call i32 @__merge(i32* %16, i32* %1, i32 %2, i32 %15, i32 %3)
br label %19
19: ; preds = %13, %8
ret void
}