#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 */
void str_optimized_bubble_sort(char **array, size_t count,
                               int (*comp)(const char *, const char *)) {
  size_t i = 0;
  char t = 1;
  size_t current = 0;
  size_t next;
  size_t end;
  char *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):
<str_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)
movb   $0x1,-0x21(%rbp)
movq   $0x0,-0x30(%rbp)
cmpb   $0x0,-0x21(%rbp)
je     11f2 <str_optimized_bubble_sort+0xf2>
movb   $0x0,-0x21(%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    11e1 <str_optimized_bubble_sort+0xe1>
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    11cb <str_optimized_bubble_sort+0xcb>
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)
movb   $0x1,-0x21(%rbp)
jmp    11d0 <str_optimized_bubble_sort+0xd0>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    114e <str_optimized_bubble_sort+0x4e>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1128 <str_optimized_bubble_sort+0x28>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_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    112e <str_optimized_bubble_sort+0x2e>
nopl   (%rax)
mov    0x10(%rsp),%rax
add    $0x1,%rax
test   %bpl,%bpl
je     1182 <str_optimized_bubble_sort+0x82>
mov    %rax,%r13
not    %r13
add    0x8(%rsp),%r13
je     1182 <str_optimized_bubble_sort+0x82>
mov    %rax,0x10(%rsp)
xor    %ebp,%ebp
xor    %r14d,%r14d
jmp    1158 <str_optimized_bubble_sort+0x58>
nopw   0x0(%rax,%rax,1)
mov    %r12,%r14
cmp    %r13,%r12
jae    1120 <str_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 <str_optimized_bubble_sort+0x50>
movdqu (%rbx,%r14,8),%xmm0
pshufd $0x4e,%xmm0,%xmm0
movdqu %xmm0,(%rbx,%r14,8)
mov    $0x1,%bpl
jmp    1150 <str_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 @str_optimized_bubble_sort(i8** %0, i64 %1, i32 (i8*, i8*)* %2) {
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i32 (i8*, i8*)*
%7 = alloca i64
%8 = alloca i8
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
store i8** %0, i8*** %4
store i64 %1, i64* %5
store i32 (i8*, i8*)* %2, i32 (i8*, i8*)** %6
store i64 0, i64* %7
store i8 1, i8* %8
store i64 0, i64* %9
br label %13
13: ; preds = %59, %3
%14 = load i8, i8* %8
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %62
16: ; preds = %13
store i8 0, i8* %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 (i8*, i8*)*, i32 (i8*, i8*)** %6
%29 = load i8**, i8*** %4
%30 = load i64, i64* %9
%31 = getelementptr inbounds i8*, i8** %29, i64 %30
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %4
%34 = load i64, i64* %10
%35 = getelementptr inbounds i8*, i8** %33, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 %28(i8* %32, i8* %36)
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %55
39: ; preds = %25
%40 = load i8**, i8*** %4
%41 = load i64, i64* %9
%42 = getelementptr inbounds i8*, i8** %40, i64 %41
%43 = load i8*, i8** %42
store i8* %43, i8** %12
%44 = load i8**, i8*** %4
%45 = load i64, i64* %10
%46 = getelementptr inbounds i8*, i8** %44, i64 %45
%47 = load i8*, i8** %46
%48 = load i8**, i8*** %4
%49 = load i64, i64* %9
%50 = getelementptr inbounds i8*, i8** %48, i64 %49
store i8* %47, i8** %50
%51 = load i8*, i8** %12
%52 = load i8**, i8*** %4
%53 = load i64, i64* %10
%54 = getelementptr inbounds i8*, i8** %52, i64 %53
store i8* %51, i8** %54
store i8 1, i8* %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 @str_optimized_bubble_sort(i8** nocapture %0, i64 %1, i32 (i8*, i8*)* 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 i8 [ %25, %24 ], [ 0, %4 ]
%11 = phi i64 [ %12, %24 ], [ 0, %4 ]
%12 = add nuw i64 %11, 1
%13 = getelementptr inbounds i8*, i8** %0, i64 %11
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %0, i64 %12
%16 = load i8*, i8** %15
%17 = tail call i32 %2(i8* %14, i8* %16)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %9
%20 = bitcast i8** %13 to <2 x i8*>*
%21 = load <2 x i8*>, <2 x i8*>* %20
%22 = shufflevector <2 x i8*> %21, <2 x i8*> poison, <2 x i32> <i32 1, i32 0>
%23 = bitcast i8** %13 to <2 x i8*>*
store <2 x i8*> %22, <2 x i8*>* %23
br label %24
24: ; preds = %9, %19
%25 = phi i8 [ 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 i8 %25, 0
br i1 %29, label %30, label %4
30: ; preds = %4, %27
ret void
}