#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 */
typedef int wchar_t;

/* Variables and functions */
void wstr_optimized_bubble_sort(wchar_t **array, size_t count,
                                int (*comp)(const wchar_t *, const wchar_t *)) {
  size_t i = 0;
  wchar_t t = 1;
  size_t current = 0;
  size_t next;
  size_t end;
  wchar_t *tmp;
  while (t) {
    t = 0;
    end = count - i - 1;
    for (current = 0; current < end; ++current) {
      next = current + 1;
      if (comp(array[current], array[next]) > 0) {
        tmp = array[current];
        array[current] = array[next];
        array[next] = tmp;
        t = 1;
      }
    }
    i += 1;
  }
}


x86 assembly (clang, -O0):
<wstr_optimized_bubble_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11fb <wstr_optimized_bubble_sort+0xfb>
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
sub    -0x20(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x40(%rbp),%rax
jae    11ea <wstr_optimized_bubble_sort+0xea>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x30(%rbp),%rdx
mov    (%rcx,%rdx,8),%rdi
mov    -0x8(%rbp),%rcx
mov    -0x38(%rbp),%rdx
mov    (%rcx,%rdx,8),%rsi
call   *%rax
cmp    $0x0,%eax
jle    11d4 <wstr_optimized_bubble_sort+0xd4>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x48(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x1,-0x24(%rbp)
jmp    11d9 <wstr_optimized_bubble_sort+0xd9>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1154 <wstr_optimized_bubble_sort+0x54>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112b <wstr_optimized_bubble_sort+0x2b>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wstr_optimized_bubble_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,0x8(%rsp)
mov    %rdi,%rbx
xor    %eax,%eax
jmp    112d <wstr_optimized_bubble_sort+0x2d>
nopl   (%rax)
mov    0x10(%rsp),%rax
add    $0x1,%rax
test   %ebp,%ebp
je     1184 <wstr_optimized_bubble_sort+0x84>
mov    %rax,%r13
not    %r13
add    0x8(%rsp),%r13
je     1184 <wstr_optimized_bubble_sort+0x84>
mov    %rax,0x10(%rsp)
xor    %ebp,%ebp
xor    %r14d,%r14d
jmp    1158 <wstr_optimized_bubble_sort+0x58>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%r14
cmp    %r13,%r12
jae    1120 <wstr_optimized_bubble_sort+0x20>
lea    0x1(%r14),%r12
mov    (%rbx,%r14,8),%rdi
mov    0x8(%rbx,%r14,8),%rsi
call   *%r15
test   %eax,%eax
jle    1150 <wstr_optimized_bubble_sort+0x50>
movdqu (%rbx,%r14,8),%xmm0
pshufd $0x4e,%xmm0,%xmm0
movdqu %xmm0,(%rbx,%r14,8)
mov    $0x1,%ebp
jmp    1150 <wstr_optimized_bubble_sort+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @wstr_optimized_bubble_sort(i32** nocapture %0, i64 %1, i32 (i32*, i32*)* nocapture %2) {
br label %4
4: ; preds = %3, %27
%5 = phi i64 [ 0, %3 ], [ %28, %27 ]
%6 = xor i64 %5, -1
%7 = add i64 %6, %1
%8 = icmp eq i64 %7, 0
br i1 %8, label %30, label %9
9: ; preds = %4, %24
%10 = phi i32 [ %25, %24 ], [ 0, %4 ]
%11 = phi i64 [ %12, %24 ], [ 0, %4 ]
%12 = add nuw i64 %11, 1
%13 = getelementptr inbounds i32*, i32** %0, i64 %11
%14 = load i32*, i32** %13
%15 = getelementptr inbounds i32*, i32** %0, i64 %12
%16 = load i32*, i32** %15
%17 = tail call i32 %2(i32* %14, i32* %16)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %9
%20 = bitcast i32** %13 to <2 x i32*>*
%21 = load <2 x i32*>, <2 x i32*>* %20
%22 = shufflevector <2 x i32*> %21, <2 x i32*> poison, <2 x i32> <i32 1, i32 0>
%23 = bitcast i32** %13 to <2 x i32*>*
store <2 x i32*> %22, <2 x i32*>* %23
br label %24
24: ; preds = %9, %19
%25 = phi i32 [ 1, %19 ], [ %10, %9 ]
%26 = icmp ult i64 %12, %7
br i1 %26, label %9, label %27
27: ; preds = %24
%28 = add i64 %5, 1
%29 = icmp eq i32 %25, 0
br i1 %29, label %30, label %4
30: ; preds = %4, %27
ret void
}