#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*/ swap(char *, char *, unsigned int);
void shortsort(char *lo, char *hi, unsigned width,
               int (*cmp)(const void *p1, const void *p2, long n, long offset),
               long n, long offset) {
  while (hi > lo) {
    char *max = lo;
    char *p;
    for (p = (lo + width); p <= hi; p += width) {
      if (cmp(p, max, n, offset) > 0) {
        max = p;
      }
    }
    swap(max, hi, width);
    hi -= width;
  }
}


x86 assembly (clang, -O0):
<shortsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    11ce <shortsort+0xbe>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     11a2 <shortsort+0x92>
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   *%rax
cmp    $0x0,%eax
jle    1188 <shortsort+0x78>
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    118d <shortsort+0x7d>
mov    -0x14(%rbp),%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
jmp    1153 <shortsort+0x43>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <swap@plt>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,%ecx
mov    %ecx,%edx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    112f <shortsort+0x1f>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shortsort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,0x20(%rsp)
mov    %edx,0x4(%rsp)
cmp    %rdi,%rsi
jbe    11b7 <shortsort+0xa7>
mov    %r8,%r15
mov    %rcx,%rbx
mov    %rsi,%rbp
mov    0x4(%rsp),%r14d
lea    (%rdi,%r14,1),%rax
mov    %rax,0x8(%rsp)
mov    %r14,%rax
neg    %rax
mov    %rax,0x18(%rsp)
mov    %rdi,0x10(%rsp)
jmp    117b <shortsort+0x6b>
nopl   0x0(%rax)
mov    %rbp,%rsi
mov    0x4(%rsp),%edx
call   1030 <swap@plt>
add    0x18(%rsp),%rbp
mov    0x10(%rsp),%rdi
cmp    %rdi,%rbp
jbe    11b7 <shortsort+0xa7>
cmp    %rbp,0x8(%rsp)
ja     1160 <shortsort+0x50>
mov    0x8(%rsp),%r12
mov    0x10(%rsp),%r13
jmp    119b <shortsort+0x8b>
xchg   %ax,%ax
add    %r14,%r12
mov    %rdi,%r13
cmp    %rbp,%r12
ja     1160 <shortsort+0x50>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
mov    0x20(%rsp),%rcx
call   *%rbx
mov    %r12,%rdi
test   %eax,%eax
jg     1190 <shortsort+0x80>
mov    %r13,%rdi
jmp    1190 <shortsort+0x80>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @shortsort(i8* %0, i8* %1, i32 %2, i32 (i8*, i8*, i64, i64)* %3, i64 %4, i64 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32 (i8*, i8*, i64, i64)*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 (i8*, i8*, i64, i64)* %3, i32 (i8*, i8*, i64, i64)** %10
store i64 %4, i64* %11
store i64 %5, i64* %12
br label %15
15: ; preds = %45, %6
%16 = load i8*, i8** %8
%17 = load i8*, i8** %7
%18 = icmp ugt i8* %16, %17
br i1 %18, label %19, label %55
19: ; preds = %15
%20 = load i8*, i8** %7
store i8* %20, i8** %13
%21 = load i8*, i8** %7
%22 = load i32, i32* %9
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8* %24, i8** %14
br label %25
25: ; preds = %40, %19
%26 = load i8*, i8** %14
%27 = load i8*, i8** %8
%28 = icmp ule i8* %26, %27
br i1 %28, label %29, label %45
29: ; preds = %25
%30 = load i32 (i8*, i8*, i64, i64)*, i32 (i8*, i8*, i64, i64)** %10
%31 = load i8*, i8** %14
%32 = load i8*, i8** %13
%33 = load i64, i64* %11
%34 = load i64, i64* %12
%35 = call i32 %30(i8* %31, i8* %32, i64 %33, i64 %34)
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %29
%38 = load i8*, i8** %14
store i8* %38, i8** %13
br label %39
39: ; preds = %37, %29
br label %40
40: ; preds = %39
%41 = load i32, i32* %9
%42 = load i8*, i8** %14
%43 = zext i32 %41 to i64
%44 = getelementptr inbounds i8, i8* %42, i64 %43
store i8* %44, i8** %14
br label %25
45: ; preds = %25
%46 = load i8*, i8** %13
%47 = load i8*, i8** %8
%48 = load i32, i32* %9
%49 = call i32 @swap(i8* %46, i8* %47, i32 %48)
%50 = load i32, i32* %9
%51 = load i8*, i8** %8
%52 = zext i32 %50 to i64
%53 = sub i64 0, %52
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8* %54, i8** %8
br label %15
55: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @shortsort(i8* %0, i8* %1, i32 %2, i32 (i8*, i8*, i64, i64)* nocapture %3, i64 %4, i64 %5) {
%7 = icmp ugt i8* %1, %0
br i1 %7, label %8, label %28
8: ; preds = %6
%9 = zext i32 %2 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = sub nsw i64 0, %9
br label %12
12: ; preds = %8, %23
%13 = phi i8* [ %1, %8 ], [ %26, %23 ]
%14 = icmp ugt i8* %10, %13
br i1 %14, label %23, label %15
15: ; preds = %12, %15
%16 = phi i8* [ %21, %15 ], [ %10, %12 ]
%17 = phi i8* [ %20, %15 ], [ %0, %12 ]
%18 = tail call i32 %3(i8* %16, i8* %17, i64 %4, i64 %5)
%19 = icmp sgt i32 %18, 0
%20 = select i1 %19, i8* %16, i8* %17
%21 = getelementptr inbounds i8, i8* %16, i64 %9
%22 = icmp ugt i8* %21, %13
br i1 %22, label %23, label %15
23: ; preds = %15, %12
%24 = phi i8* [ %0, %12 ], [ %20, %15 ]
%25 = tail call i32 @swap(i8* %24, i8* %13, i32 %2)
%26 = getelementptr inbounds i8, i8* %13, i64 %11
%27 = icmp ugt i8* %26, %0
br i1 %27, label %12, label %28
28: ; preds = %23, %6
ret void
}