#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_xor(void *, void *, size_t);
void bubbleSortX(void *a, size_t count, size_t size,
                 int (*comp)(const void *, const void *)) {
  size_t i, j;
  const size_t j_temp = count - 1;
  for (i = 0; i < count; ++i) {
    for (j = j_temp; j > i; --j) {
      void *current = a + j * size;
      void *prev = current - size;
      if (comp(prev, current) > 0) {
        swap_xor(prev, current, size);
      }
    }
  }
}


x86 assembly (clang, -O0):
<bubbleSortX>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11d9 <bubbleSortX+0xc9>
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    11c3 <bubbleSortX+0xb3>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
imul   -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
xor    %ecx,%ecx
sub    -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   *%rax
cmp    $0x0,%eax
jle    11ad <bubbleSortX+0x9d>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <swap_xor@plt>
jmp    11b2 <bubbleSortX+0xa2>
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
jmp    1152 <bubbleSortX+0x42>
jmp    11c8 <bubbleSortX+0xb8>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    113c <bubbleSortX+0x2c>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bubbleSortX>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,(%rsp)
test   %rsi,%rsi
je     11ce <bubbleSortX+0xbe>
mov    %rcx,%r12
mov    (%rsp),%rcx
lea    -0x1(%rcx),%rdx
mov    0x10(%rsp),%rax
mov    %rax,%r14
neg    %r14
add    $0xfffffffffffffffe,%rcx
imul   %rax,%rcx
add    %rdi,%rcx
mov    %rcx,0x20(%rsp)
mov    %rdx,0x8(%rsp)
imul   %rdx,%rax
add    %rdi,%rax
mov    %rax,0x18(%rsp)
xor    %ebp,%ebp
jmp    117a <bubbleSortX+0x6a>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    (%rsp),%rbp
je     11ce <bubbleSortX+0xbe>
cmp    %rbp,0x8(%rsp)
jbe    1170 <bubbleSortX+0x60>
mov    0x18(%rsp),%r13
mov    0x20(%rsp),%rbx
mov    0x8(%rsp),%r15
jmp    11af <bubbleSortX+0x9f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xffffffffffffffff,%r15
add    %r14,%rbx
add    %r14,%r13
cmp    %rbp,%r15
jbe    1170 <bubbleSortX+0x60>
mov    %rbx,%rdi
mov    %r13,%rsi
call   *%r12
test   %eax,%eax
jle    11a0 <bubbleSortX+0x90>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    0x10(%rsp),%rdx
call   1030 <swap_xor@plt>
jmp    11a0 <bubbleSortX+0x90>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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