#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(void *, void *, void *, size_t,
                         int (*)(void const *, void const *));
void sort_merge(void *low, void *high, size_t width,
                int (*comp)(const void *, const void *)) {
  if (low < high) {
    size_t length = (char *)high - (char *)low + width;
    int n = length / width;
    void *mid = (char *)low + n / 2 * width;
    sort_merge(low, mid, width, comp);
    sort_merge(mid, high, width, comp);
    merge(low, mid, high, width, comp);
  }
}


x86 assembly (clang, -O0):
<sort_merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11d3 <sort_merge+0xb3>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
imul   -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <sort_merge@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <sort_merge@plt>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1040 <merge@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort_merge>:
cmp    %rsi,%rdi
jae    1156 <sort_merge+0x36>
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rsi,%rax
sub    %rdi,%rax
add    %rdx,%rax
mov    %rax,%rcx
or     %rdx,%rcx
shr    $0x20,%rcx
je     1157 <sort_merge+0x37>
xor    %edx,%edx
div    %r13
jmp    115c <sort_merge+0x3c>
ret
xor    %edx,%edx
div    %r13d
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rbx
imul   %r13,%rbx
add    %r12,%rbx
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r14,%rcx
call   1030 <sort_merge@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
mov    %r14,%rcx
call   1030 <sort_merge@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r13,%rcx
mov    %r14,%r8
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <merge@plt>

LLVM IR (-O0):
define void @sort_merge(i8* %0, i8* %1, i64 %2, i32 (i8*, i8*)* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32 (i8*, i8*)*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 (i8*, i8*)* %3, i32 (i8*, i8*)** %8
%12 = load i8*, i8** %5
%13 = load i8*, i8** %6
%14 = icmp ult i8* %12, %13
br i1 %14, label %15, label %48
15: ; preds = %4
%16 = load i8*, i8** %6
%17 = load i8*, i8** %5
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = load i64, i64* %7
%22 = add i64 %20, %21
store i64 %22, i64* %9
%23 = load i64, i64* %9
%24 = load i64, i64* %7
%25 = udiv i64 %23, %24
%26 = trunc i64 %25 to i32
store i32 %26, i32* %10
%27 = load i8*, i8** %5
%28 = load i32, i32* %10
%29 = sdiv i32 %28, 2
%30 = sext i32 %29 to i64
%31 = load i64, i64* %7
%32 = mul i64 %30, %31
%33 = getelementptr inbounds i8, i8* %27, i64 %32
store i8* %33, i8** %11
%34 = load i8*, i8** %5
%35 = load i8*, i8** %11
%36 = load i64, i64* %7
%37 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %8
%38 = load i8*, i8** %11
%39 = load i8*, i8** %6
%40 = load i64, i64* %7
%41 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %8
%42 = load i8*, i8** %5
%43 = load i8*, i8** %11
%44 = load i8*, i8** %6
%45 = load i64, i64* %7
%46 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %8
%47 = call i32 @merge(i8* %42, i8* %43, i8* %44, i64 %45, i32 (i8*, i8*)* %46)
br label %48
48: ; preds = %15, %4
ret void
}

LLVM IR (-O2):
define void @sort_merge(i8* %0, i8* %1, i64 %2, i32 (i8*, i8*)* %3) {
%5 = icmp ult i8* %0, %1
br i1 %5, label %7, label %6
6: ; preds = %4, %7
ret void
7: ; preds = %4
%8 = ptrtoint i8* %1 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 %8, %9
%11 = add i64 %10, %2
%12 = udiv i64 %11, %2
%13 = trunc i64 %12 to i32
%14 = sdiv i32 %13, 2
%15 = sext i32 %14 to i64
%16 = mul i64 %15, %2
%17 = getelementptr inbounds i8, i8* %0, i64 %16
tail call void @sort_merge(i8* %0, i8* %17, i64 %2, i32 (i8*, i8*)* %3)
tail call void @sort_merge(i8* %17, i8* %1, i64 %2, i32 (i8*, i8*)* %3)
%18 = tail call i32 @merge(i8* %0, i8* %17, i8* %1, i64 %2, i32 (i8*, i8*)* %3)
br label %6
}