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


x86 assembly (clang, -O0):
<optimizedBubbleSortX2>:
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)
movb   $0x1,-0x29(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpb   $0x0,-0x29(%rbp)
je     11db <optimizedBubbleSortX2+0xcb>
movb   $0x0,-0x29(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    -0x28(%rbp),%rcx
sub    $0x1,%rcx
imul   -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x48(%rbp),%rax
jae    11ca <optimizedBubbleSortX2+0xba>
mov    -0x38(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   *%rax
cmp    $0x0,%eax
jle    11b4 <optimizedBubbleSortX2+0xa4>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <swap_xor@plt>
movb   $0x1,-0x29(%rbp)
jmp    11b9 <optimizedBubbleSortX2+0xa9>
mov    -0x18(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    116e <optimizedBubbleSortX2+0x5e>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    113c <optimizedBubbleSortX2+0x2c>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<optimizedBubbleSortX2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,0x8(%rsp)
mov    %rdi,%rbp
xor    %eax,%eax
mov    %rdi,(%rsp)
jmp    1152 <optimizedBubbleSortX2+0x42>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%rsp),%rax
add    $0x1,%rax
test   %r12b,%r12b
mov    (%rsp),%rbp
je     11ae <optimizedBubbleSortX2+0x9e>
mov    %rax,%r15
not    %r15
add    0x8(%rsp),%r15
imul   %r13,%r15
add    %rbp,%r15
cmp    %rbp,%r15
jbe    11ae <optimizedBubbleSortX2+0x9e>
mov    %rax,0x10(%rsp)
xor    %r12d,%r12d
jmp    1188 <optimizedBubbleSortX2+0x78>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rbp
cmp    %r15,%rbx
jae    1140 <optimizedBubbleSortX2+0x30>
mov    %rbp,%rbx
add    %r13,%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   *%r14
test   %eax,%eax
jle    1180 <optimizedBubbleSortX2+0x70>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1030 <swap_xor@plt>
mov    $0x1,%r12b
jmp    1180 <optimizedBubbleSortX2+0x70>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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