#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*/ memcpy(void *, void *, size_t);
void two_sort(void *base, void *tmp, size_t width,
              int (*compar)(const void *, const void *)) {
  if (compar(base, base + width) > 0) {
    memcpy(tmp, base, width);
    memcpy(base, base + width, width);
    memcpy(base + width, tmp, width);
  }
}


x86 assembly (clang, -O0):
<two_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x18(%rbp),%rsi
call   *%rax
cmp    $0x0,%eax
jle    117e <two_sort+0x6e>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<two_sort>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
lea    (%rdi,%rdx,1),%r15
mov    %r15,%rsi
call   *%rcx
test   %eax,%eax
jle    1163 <two_sort+0x53>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1030 <memcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <memcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <memcpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @two_sort(i8* %0, i8* %1, i64 %2, i32 (i8*, i8*)* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32 (i8*, 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
%9 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %8
%10 = load i8*, i8** %5
%11 = load i8*, i8** %5
%12 = load i64, i64* %7
%13 = getelementptr i8, i8* %11, i64 %12
%14 = call i32 %9(i8* %10, i8* %13)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %33
16: ; preds = %4
%17 = load i8*, i8** %6
%18 = load i8*, i8** %5
%19 = load i64, i64* %7
%20 = call i32 @memcpy(i8* %17, i8* %18, i64 %19)
%21 = load i8*, i8** %5
%22 = load i8*, i8** %5
%23 = load i64, i64* %7
%24 = getelementptr i8, i8* %22, i64 %23
%25 = load i64, i64* %7
%26 = call i32 @memcpy(i8* %21, i8* %24, i64 %25)
%27 = load i8*, i8** %5
%28 = load i64, i64* %7
%29 = getelementptr i8, i8* %27, i64 %28
%30 = load i8*, i8** %6
%31 = load i64, i64* %7
%32 = call i32 @memcpy(i8* %29, i8* %30, i64 %31)
br label %33
33: ; preds = %16, %4
ret void
}

LLVM IR (-O2):
define void @two_sort(i8* %0, i8* %1, i64 %2, i32 (i8*, i8*)* nocapture %3) {
%5 = getelementptr i8, i8* %0, i64 %2
%6 = tail call i32 %3(i8* %0, i8* %5)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = tail call i32 @memcpy(i8* %1, i8* %0, i64 %2)
%10 = tail call i32 @memcpy(i8* %0, i8* %5, i64 %2)
%11 = tail call i32 @memcpy(i8* %5, i8* %1, i64 %2)
br label %12
12: ; preds = %8, %4
ret void
}