#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*/ my_merge(char *, int, int, int, char *, int *);
void my_mergesort(char *arr, int start, int end, char buf[100],
                  int *total_inv) {
  if (end - start == 1) {
    return;
  }
  if (start < end) {
    int mid = start + (end - start) / 2;
    my_mergesort(arr, start, mid, buf, total_inv);
    my_mergesort(arr, mid, end, buf, total_inv);
    my_merge(arr, start, mid, end, buf, total_inv);
  }
}


x86 assembly (clang, -O0):
<my_mergesort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0x1,%eax
jne    114e <my_mergesort+0x2e>
jmp    11c0 <my_mergesort+0xa0>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11c0 <my_mergesort+0xa0>
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1040 <my_mergesort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1040 <my_mergesort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
call   1030 <my_merge@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_mergesort>:
mov    %edx,%eax
sub    %esi,%eax
jle    118c <my_mergesort+0x6c>
cmp    $0x1,%eax
je     118c <my_mergesort+0x6c>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %edx,%r13d
mov    %esi,%ebx
mov    %rdi,%r12
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
add    %esi,%ebp
mov    %ebp,%edx
call   1040 <my_mergesort@plt>
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r13d,%edx
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <my_mergesort@plt>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r13d,%ecx
mov    %r15,%r8
mov    %r14,%r9
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <my_merge@plt>
ret

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

LLVM IR (-O2):
define void @my_mergesort(i8* %0, i32 %1, i32 %2, i8* %3, i32* %4) {
%6 = sub nsw i32 %2, %1
%7 = icmp ne i32 %6, 1
%8 = icmp sgt i32 %2, %1
%9 = and i1 %8, %7
br i1 %9, label %11, label %10
10: ; preds = %5, %11
ret void
11: ; preds = %5
%12 = sdiv i32 %6, 2
%13 = add nsw i32 %12, %1
tail call void @my_mergesort(i8* %0, i32 %1, i32 %13, i8* %3, i32* %4)
tail call void @my_mergesort(i8* %0, i32 %13, i32 %2, i8* %3, i32* %4)
%14 = tail call i32 @my_merge(i8* %0, i32 %1, i32 %13, i32 %2, i8* %3, i32* %4)
br label %10
}