#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 *, int);
void bsort(void *array, int len, int size,
           int (*compare)(const void *a, const void *b)) {
  int index = 0;
  do {
    char *a = (char *)array + index * size;
    char *b = a + size;
    int comparison = compare(a, b);
    if (comparison > 0) {
      _swap(a, b, size);
      index = 0;
      continue;
    }
    index++;
  } while (index < (len - 1));
}


x86 assembly (clang, -O0):
<bsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x10(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x10(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   *%rax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jle    1188 <bsort+0x78>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <_swap@plt>
movl   $0x0,-0x1c(%rbp)
jmp    1191 <bsort+0x81>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jl     112d <bsort+0x1d>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bsort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x10(%rsp)
mov    %edx,%r13d
mov    %esi,%r12d
mov    %rdi,0x8(%rsp)
movslq %edx,%r14
add    $0xffffffff,%r12d
xor    %r15d,%r15d
jmp    1149 <bsort+0x39>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r15d
cmp    %r12d,%r15d
jge    1180 <bsort+0x70>
mov    %r15d,%eax
imul   %r13d,%eax
movslq %eax,%rbx
add    0x8(%rsp),%rbx
lea    (%rbx,%r14,1),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   *0x10(%rsp)
test   %eax,%eax
jle    1140 <bsort+0x30>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
call   1030 <_swap@plt>
xor    %r15d,%r15d
cmp    %r12d,%r15d
jl     1149 <bsort+0x39>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @bsort(i8* %0, i32 %1, i32 %2, i32 (i8*, i8*)* nocapture %3) {
%5 = sext i32 %2 to i64
%6 = add nsw i32 %1, -1
br label %7
7: ; preds = %19, %4
%8 = phi i32 [ 0, %4 ], [ %20, %19 ]
%9 = mul nsw i32 %8, %2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = getelementptr inbounds i8, i8* %11, i64 %5
%13 = tail call i32 %3(i8* %11, i8* %12)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %7
%16 = tail call i32 @_swap(i8* %11, i8* %12, i32 %2)
br label %19
17: ; preds = %7
%18 = add nsw i32 %8, 1
br label %19
19: ; preds = %17, %15
%20 = phi i32 [ 0, %15 ], [ %18, %17 ]
%21 = icmp slt i32 %20, %6
br i1 %21, label %7, label %22
22: ; preds = %19
ret void
}