#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 optimizedBubbleSortX(void *a, size_t count, size_t size,
                          int (*comp)(const void *, const void *)) {
  size_t i = 0;
  size_t j = 0;
  size_t temp = 0;
  char t = 1;
  void *current;
  void *next;
  while (t) {
    t = 0;
    temp = count - i - 1;
    for (j = 0; j < temp; ++j) {
      current = a + j * size;
      next = current + size;
      if (comp(current, next) > 0) {
        swap_xor(current, next, size);
        t = 1;
      }
    }
    i += 1;
  }
}


x86 assembly (clang, -O0):
<optimizedBubbleSortX>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movb   $0x1,-0x39(%rbp)
cmpb   $0x0,-0x39(%rbp)
je     11eb <optimizedBubbleSortX+0xdb>
movb   $0x0,-0x39(%rbp)
mov    -0x10(%rbp),%rax
sub    -0x28(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    11da <optimizedBubbleSortX+0xca>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
imul   -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   *%rax
cmp    $0x0,%eax
jle    11c4 <optimizedBubbleSortX+0xb4>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <swap_xor@plt>
movb   $0x1,-0x39(%rbp)
jmp    11c9 <optimizedBubbleSortX+0xb9>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    116a <optimizedBubbleSortX+0x5a>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1144 <optimizedBubbleSortX+0x34>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<optimizedBubbleSortX>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,0x20(%rsp)
mov    %rdx,%r13
mov    %rsi,0x10(%rsp)
mov    %rdi,0x8(%rsp)
xor    %eax,%eax
jmp    114e <optimizedBubbleSortX+0x3e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x18(%rsp),%rax
add    $0x1,%rax
test   %r14b,%r14b
je     11a3 <optimizedBubbleSortX+0x93>
mov    %rax,%r12
not    %r12
add    0x10(%rsp),%r12
je     11a3 <optimizedBubbleSortX+0x93>
mov    %rax,0x18(%rsp)
xor    %r15d,%r15d
mov    0x8(%rsp),%rbp
xor    %r14d,%r14d
jmp    117c <optimizedBubbleSortX+0x6c>
nopl   (%rax)
add    $0x1,%r15
mov    %rbx,%rbp
cmp    %r12,%r15
jae    1140 <optimizedBubbleSortX+0x30>
mov    %rbp,%rbx
add    %r13,%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   *0x20(%rsp)
test   %eax,%eax
jle    1170 <optimizedBubbleSortX+0x60>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1030 <swap_xor@plt>
mov    $0x1,%r14b
jmp    1170 <optimizedBubbleSortX+0x60>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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