#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*/ copy_array(void *, void *, int, int, int);
int /*<<< orphan*/ merge(void *, int, int, int, void *, int,
                         int (*)(void *, void *));
int min(int, int);
void m_split_sort_d2t(void *a, void *b, int asize, int esize,
                      int compare(void *key1, void *key2)) {
  int iBegin;
  int iMiddle;
  int iEnd;
  int width;
  for (width = 1; width < asize; width = width * 2) {
    for (int i = 0; i < asize; i = i + 2 * width) {
      iBegin = i;
      iMiddle = min(i + width - 1, asize - 1);
      iEnd = min(i + 2 * width - 1, asize - 1);
      merge(a, iBegin, iMiddle, iEnd, b, esize, compare);
      copy_array(a, b, iBegin, iEnd, esize);
    }
  }
}


x86 assembly (clang, -O0):
<m_split_sort_d2t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1208 <m_split_sort_d2t+0xd8>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f5 <m_split_sort_d2t+0xc5>
mov    -0x34(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x34(%rbp),%edi
add    -0x30(%rbp),%edi
sub    $0x1,%edi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
call   1030 <min@plt>
mov    %eax,-0x28(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%eax
shl    $0x1,%eax
add    %eax,%edi
sub    $0x1,%edi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
call   1030 <min@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9d
mov    -0x20(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <merge@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1050 <copy_array@plt>
mov    -0x34(%rbp),%eax
mov    -0x30(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x34(%rbp)
jmp    1164 <m_split_sort_d2t+0x34>
jmp    11fa <m_split_sort_d2t+0xca>
mov    -0x30(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1151 <m_split_sort_d2t+0x21>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m_split_sort_d2t>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,0x20(%rsp)
cmp    $0x2,%edx
jl     1225 <m_split_sort_d2t+0xf5>
mov    %ecx,%r13d
mov    %rsi,%rbx
mov    %rdi,%r15
lea    -0x1(%rdx),%ebp
mov    $0x1,%eax
mov    %rax,0x8(%rsp)
mov    %rdx,0x18(%rsp)
mov    %ecx,0x10(%rsp)
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rcx
lea    -0x1(%rcx),%eax
mov    %rax,0x30(%rsp)
mov    %ecx,%eax
add    %ecx,%ecx
mov    %rcx,0x8(%rsp)
add    %eax,%eax
add    $0xffffffff,%eax
mov    %rax,0x28(%rsp)
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x30(%rsp),%rax
lea    (%rax,%r14,1),%edi
mov    %ebp,%esi
call   1030 <min@plt>
mov    %eax,%r13d
mov    0x8(%rsp),%rax
add    %r14d,%eax
mov    %eax,0x14(%rsp)
mov    0x28(%rsp),%rax
lea    (%rax,%r14,1),%edi
mov    %ebp,%esi
call   1030 <min@plt>
mov    %eax,%r12d
mov    0x20(%rsp),%rax
mov    %rax,(%rsp)
mov    %r15,%rdi
mov    %r14d,%esi
mov    %r13d,%edx
mov    0x10(%rsp),%r13d
mov    %r12d,%ecx
mov    %rbx,%r8
mov    %r13d,%r9d
call   1040 <merge@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
mov    %r12d,%ecx
mov    %r13d,%r8d
call   1050 <copy_array@plt>
mov    0x18(%rsp),%rdx
mov    0x14(%rsp),%eax
mov    %eax,%r14d
cmp    %edx,%eax
jl     11a0 <m_split_sort_d2t+0x70>
cmp    %edx,0x8(%rsp)
jl     1170 <m_split_sort_d2t+0x40>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @m_split_sort_d2t(i8* %0, i8* %1, i32 %2, i32 %3, i32 (i8*, i8*)* %4) {
%6 = icmp sgt i32 %2, 1
br i1 %6, label %7, label %25
7: ; preds = %5
%8 = add nsw i32 %2, -1
br label %9
9: ; preds = %13, %7
%10 = phi i32 [ 1, %7 ], [ %12, %13 ]
%11 = add i32 %10, -1
%12 = shl nsw i32 %10, 1
br label %15
13: ; preds = %15
%14 = icmp slt i32 %12, %2
br i1 %14, label %9, label %25
15: ; preds = %9, %15
%16 = phi i32 [ 0, %9 ], [ %19, %15 ]
%17 = add i32 %11, %16
%18 = tail call i32 @min(i32 %17, i32 %8)
%19 = add nsw i32 %16, %12
%20 = add nsw i32 %19, -1
%21 = tail call i32 @min(i32 %20, i32 %8)
%22 = tail call i32 @merge(i8* %0, i32 %16, i32 %18, i32 %21, i8* %1, i32 %3, i32 (i8*, i8*)* %4)
%23 = tail call i32 @copy_array(i8* %0, i8* %1, i32 %16, i32 %21, i32 %3)
%24 = icmp slt i32 %19, %2
br i1 %24, label %15, label %13
25: ; preds = %13, %5
ret void
}