#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 (*comp)(const void *, const void *)) {
  char *p, *max;
  while (hi > lo) {
    max = lo;
    for (p = lo + width; p <= hi; p += width)
      if (comp(p, max) > 0)
        max = p;
    swap(max, hi, width);
    hi -= width;
  }
}


x86 assembly (clang, -O0):
<shortsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    11be <shortsort+0xae>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     1192 <shortsort+0x82>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   *%rax
cmp    $0x0,%eax
jle    1178 <shortsort+0x68>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    117d <shortsort+0x6d>
mov    -0x14(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    114b <shortsort+0x3b>
mov    -0x30(%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    1127 <shortsort+0x17>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shortsort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,0x4(%rsp)
cmp    %rdi,%rsi
jbe    11a0 <shortsort+0x90>
mov    %rcx,%r12
mov    %rsi,%r13
mov    %rdi,%r15
mov    0x4(%rsp),%r14d
lea    (%rdi,%r14,1),%rax
mov    %rax,0x8(%rsp)
mov    %r14,%rax
neg    %rax
mov    %rax,0x10(%rsp)
jmp    1166 <shortsort+0x56>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rsi
mov    0x4(%rsp),%edx
call   1030 <swap@plt>
add    0x10(%rsp),%r13
cmp    %r15,%r13
jbe    11a0 <shortsort+0x90>
mov    %r15,%rdi
cmp    %r13,0x8(%rsp)
ja     1150 <shortsort+0x40>
mov    0x8(%rsp),%rbx
mov    %r15,%rbp
jmp    118b <shortsort+0x7b>
nopw   0x0(%rax,%rax,1)
add    %r14,%rbx
mov    %rdi,%rbp
cmp    %r13,%rbx
ja     1150 <shortsort+0x40>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   *%r12
mov    %rbx,%rdi
test   %eax,%eax
jg     1180 <shortsort+0x70>
mov    %rbp,%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, i32 %2, i32 (i8*, i8*)* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32 (i8*, i8*)*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 (i8*, i8*)* %3, i32 (i8*, i8*)** %8
br label %11
11: ; preds = %39, %4
%12 = load i8*, i8** %6
%13 = load i8*, i8** %5
%14 = icmp ugt i8* %12, %13
br i1 %14, label %15, label %49
15: ; preds = %11
%16 = load i8*, i8** %5
store i8* %16, i8** %10
%17 = load i8*, i8** %5
%18 = load i32, i32* %7
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
store i8* %20, i8** %9
br label %21
21: ; preds = %34, %15
%22 = load i8*, i8** %9
%23 = load i8*, i8** %6
%24 = icmp ule i8* %22, %23
br i1 %24, label %25, label %39
25: ; preds = %21
%26 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %8
%27 = load i8*, i8** %9
%28 = load i8*, i8** %10
%29 = call i32 %26(i8* %27, i8* %28)
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = load i8*, i8** %9
store i8* %32, i8** %10
br label %33
33: ; preds = %31, %25
br label %34
34: ; preds = %33
%35 = load i32, i32* %7
%36 = load i8*, i8** %9
%37 = zext i32 %35 to i64
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8* %38, i8** %9
br label %21
39: ; preds = %21
%40 = load i8*, i8** %10
%41 = load i8*, i8** %6
%42 = load i32, i32* %7
%43 = call i32 @swap(i8* %40, i8* %41, i32 %42)
%44 = load i32, i32* %7
%45 = load i8*, i8** %6
%46 = zext i32 %44 to i64
%47 = sub i64 0, %46
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8* %48, i8** %6
br label %11
49: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @shortsort(i8* %0, i8* %1, i32 %2, i32 (i8*, i8*)* nocapture %3) {
%5 = icmp ugt i8* %1, %0
br i1 %5, label %6, label %26
6: ; preds = %4
%7 = zext i32 %2 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = sub nsw i64 0, %7
br label %10
10: ; preds = %6, %21
%11 = phi i8* [ %1, %6 ], [ %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)
%17 = icmp sgt i32 %16, 0
%18 = select i1 %17, i8* %14, i8* %15
%19 = getelementptr inbounds i8, i8* %14, i64 %7
%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, i32 %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, %4
ret void
}