#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 *, size_t);
void shortsort(char *lo, char *hi, size_t width,
               int (*comp)(const void *, const void *, void *ExtraArgs),
               void *ExtraArgs) {
  char *p, *max;
  while (hi > lo) {
    max = lo;
    for (p = lo + width; p <= hi; p += width)
      if (comp(p, max, ExtraArgs) > 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    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    11bf <shortsort+0xaf>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     1195 <shortsort+0x85>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   *%rax
cmp    $0x0,%eax
jle    117f <shortsort+0x6f>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1184 <shortsort+0x74>
mov    -0x18(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    114e <shortsort+0x3e>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <swap@plt>
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    112c <shortsort+0x1c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shortsort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    %rdi,%rsi
jbe    11a3 <shortsort+0x93>
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
lea    (%rdi,%rdx,1),%rax
mov    %rax,(%rsp)
mov    %rdx,%rax
neg    %rax
mov    %rax,0x10(%rsp)
mov    %rdi,0x8(%rsp)
jmp    116a <shortsort+0x5a>
nopl   (%rax)
mov    %rbx,%rsi
mov    %r12,%rdx
call   1030 <swap@plt>
add    0x10(%rsp),%rbx
mov    0x8(%rsp),%rdi
cmp    %rdi,%rbx
jbe    11a3 <shortsort+0x93>
cmp    %rbx,(%rsp)
ja     1150 <shortsort+0x40>
mov    (%rsp),%rbp
mov    0x8(%rsp),%r13
jmp    118b <shortsort+0x7b>
nopl   0x0(%rax,%rax,1)
add    %r12,%rbp
mov    %rdi,%r13
cmp    %rbx,%rbp
ja     1150 <shortsort+0x40>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   *%r15
mov    %rbp,%rdi
test   %eax,%eax
jg     1180 <shortsort+0x70>
mov    %r13,%rdi
jmp    1180 <shortsort+0x70>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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