#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 find_middle(int, int);
scalar_t__ is_sorted(int *, int, int);
int /*<<< orphan*/ merge(int *, int, int const, int);
void merge_sort_divide(register int *a, register int start, register int end) {
  if (start >= end || is_sorted(a, start, end))
    return;
  register const int middle = find_middle(start, end);
  merge_sort_divide(a, start, middle);
  merge_sort_divide(a, middle + 1, end);
  merge(a, start, middle, end);
}


x86 assembly (clang, -O0):
<merge_sort_divide>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1177 <merge_sort_divide+0x37>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <is_sorted@plt>
cmp    $0x0,%rax
je     117c <merge_sort_divide+0x3c>
jmp    11bd <merge_sort_divide+0x7d>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1060 <find_middle@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <merge_sort_divide@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <merge_sort_divide@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1050 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort_divide>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    %edx,%esi
jge    115c <merge_sort_divide+0x1c>
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r14
call   1030 <is_sorted@plt>
test   %rax,%rax
je     1167 <merge_sort_divide+0x27>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%edi
mov    %ebx,%esi
call   1060 <find_middle@plt>
mov    %eax,%r15d
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <merge_sort_divide@plt>
lea    0x1(%r15),%esi
mov    %r14,%rdi
mov    %ebx,%edx
call   1040 <merge_sort_divide@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %ebx,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <merge@plt>

LLVM IR (-O0):
define void @merge_sort_divide(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = load i32, i32* %6
%10 = icmp sge i32 %8, %9
br i1 %10, label %17, label %11
11: ; preds = %3
%12 = load i32*, i32** %4
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = call i64 @is_sorted(i32* %12, i32 %13, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %11, %3
br label %34
18: ; preds = %11
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = call i32 @find_middle(i32 %19, i32 %20)
store i32 %21, i32* %7
%22 = load i32*, i32** %4
%23 = load i32, i32* %5
%24 = load i32, i32* %7
%25 = load i32*, i32** %4
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
%28 = load i32, i32* %6
%29 = load i32*, i32** %4
%30 = load i32, i32* %5
%31 = load i32, i32* %7
%32 = load i32, i32* %6
%33 = call i32 @merge(i32* %29, i32 %30, i32 %31, i32 %32)
br label %34
34: ; preds = %18, %17
ret void
}

LLVM IR (-O2):
define void @merge_sort_divide(i32* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = tail call i64 @is_sorted(i32* %0, i32 %1, i32 %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %5, %3, %9
ret void
9: ; preds = %5
%10 = tail call i32 @find_middle(i32 %1, i32 %2)
tail call void @merge_sort_divide(i32* %0, i32 %1, i32 %10)
%11 = add nsw i32 %10, 1
tail call void @merge_sort_divide(i32* %0, i32 %11, i32 %2)
%12 = tail call i32 @merge(i32* %0, i32 %1, i32 %10, i32 %2)
br label %8
}