#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);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
void Merge_Sort1(int A[], int N) {
  int *TmpA = (int *)malloc(N * sizeof(int));
  int length = 1;
  if (NULL == TmpA)
    exit(-1);
  else {
    while (length < N) {
      Merge_Pass(A, TmpA, N, length);
      length *= 2;
      Merge_Pass(TmpA, A, N, length);
      length *= 2;
    }
    free(TmpA);
  }
  return;
}


x86 assembly (clang, -O0):
<Merge_Sort1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    117f <Merge_Sort1+0x3f>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
jmp    1184 <Merge_Sort1+0x44>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11cd <Merge_Sort1+0x8d>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1050 <Merge_Pass@plt>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1050 <Merge_Pass@plt>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1184 <Merge_Sort1+0x44>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Merge_Sort1>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r12d
mov    %rdi,%r14
lea    0x0(,%r12,4),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     11ac <Merge_Sort1+0x6c>
mov    %rax,%r15
cmp    $0x2,%r12d
jl     1199 <Merge_Sort1+0x59>
mov    $0x1,%ebx
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
mov    %ebx,%ecx
call   1050 <Merge_Pass@plt>
lea    (%rbx,%rbx,1),%ecx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1050 <Merge_Pass@plt>
shl    $0x2,%ebx
cmp    %r12d,%ebx
jl     1170 <Merge_Sort1+0x30>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
define void @Merge_Sort1(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 4
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %5
store i32 1, i32* %6
%13 = load i32*, i32** %5
%14 = icmp eq i32* null, %13
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
br label %18
18: ; preds = %22, %17
%19 = load i32, i32* %6
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %37
22: ; preds = %18
%23 = load i32*, i32** %3
%24 = load i32*, i32** %5
%25 = load i32, i32* %4
%26 = load i32, i32* %6
%27 = call i32 @Merge_Pass(i32* %23, i32* %24, i32 %25, i32 %26)
%28 = load i32, i32* %6
%29 = mul nsw i32 %28, 2
store i32 %29, i32* %6
%30 = load i32*, i32** %5
%31 = load i32*, i32** %3
%32 = load i32, i32* %4
%33 = load i32, i32* %6
%34 = call i32 @Merge_Pass(i32* %30, i32* %31, i32 %32, i32 %33)
%35 = load i32, i32* %6
%36 = mul nsw i32 %35, 2
store i32 %36, i32* %6
br label %18
37: ; preds = %18
%38 = load i32*, i32** %5
%39 = call i32 @free(i32* %38)
br label %40
40: ; preds = %37
ret void
}

LLVM IR (-O2):
define void @Merge_Sort1(i32* %0, i32 %1) {
%3 = shl i32 %1, 2
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i32*
%6 = icmp eq i64 %4, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = icmp sgt i32 %1, 1
br i1 %8, label %11, label %18
9: ; preds = %2
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %7, %11
%12 = phi i32 [ %16, %11 ], [ 1, %7 ]
%13 = tail call i32 @Merge_Pass(i32* %0, i32* %5, i32 %1, i32 %12)
%14 = shl nuw nsw i32 %12, 1
%15 = tail call i32 @Merge_Pass(i32* %5, i32* %0, i32 %1, i32 %14)
%16 = shl nsw i32 %12, 2
%17 = icmp slt i32 %16, %1
br i1 %17, label %11, label %18
18: ; preds = %11, %7
%19 = tail call i32 @free(i32* %5)
ret void
}