int strings_order_imp(char *a, char *b, int (*callback)(char, char)) {
  assert(a);
  assert(b);
  assert(callback);
  unsigned int a_length = strings_length(a), b_length = strings_length(b);
  int callback_ret;
  for (unsigned int k = 0; k < a_length && k < b_length; k++) {
    callback_ret = callback(a[k], b[k]);
    if (callback_ret != 0)
      return callback_ret;
  }
  if (b_length > a_length)
    return -1;
  else if (a_length > b_length)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<strings_order_imp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1040 <assert@plt>
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1040 <assert@plt>
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1030 <strings_length@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1030 <strings_length@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%ecx
xor    %eax,%eax
cmp    -0x24(%rbp),%ecx
mov    %al,-0x31(%rbp)
jae    1195 <strings_order_imp+0x75>
mov    -0x30(%rbp),%eax
cmp    -0x28(%rbp),%eax
setb   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11a5 <strings_order_imp+0x85>
jmp    11f0 <strings_order_imp+0xd0>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x30(%rbp),%edx
mov    (%rcx,%rdx,1),%sil
mov    -0x18(%rbp),%rcx
mov    -0x30(%rbp),%edx
movsbl %sil,%edi
movsbl (%rcx,%rdx,1),%esi
call   *%rax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11dd <strings_order_imp+0xbd>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1227 <strings_order_imp+0x107>
jmp    11e2 <strings_order_imp+0xc2>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1178 <strings_order_imp+0x58>
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jbe    1208 <strings_order_imp+0xe8>
movl   $0xffffffff,-0x4(%rbp)
jmp    1227 <strings_order_imp+0x107>
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jbe    1220 <strings_order_imp+0x100>
movl   $0x1,-0x4(%rbp)
jmp    1227 <strings_order_imp+0x107>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strings_order_imp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <assert@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <assert@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <assert@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <strings_length@plt>
mov    %eax,%ebp
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <strings_length@plt>
mov    %eax,(%rsp)
mov    %ebp,0x4(%rsp)
test   %ebp,%ebp
je     11b4 <strings_order_imp+0x94>
cmpl   $0x0,(%rsp)
je     11b4 <strings_order_imp+0x94>
mov    (%rsp),%ebp
mov    0x4(%rsp),%r12d
mov    $0x1,%r13d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl -0x1(%rbx,%r13,1),%edi
movsbl -0x1(%r15,%r13,1),%esi
call   *%r14
test   %eax,%eax
jne    11c8 <strings_order_imp+0xa8>
cmp    %r12,%r13
jae    11b4 <strings_order_imp+0x94>
lea    0x1(%r13),%rax
cmp    %rbp,%r13
mov    %rax,%r13
jb     1190 <strings_order_imp+0x70>
mov    $0xffffffff,%eax
mov    (%rsp),%ecx
cmp    0x4(%rsp),%ecx
ja     11c8 <strings_order_imp+0xa8>
setb   %al
movzbl %al,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @strings_order_imp(i8* %0, i8* %1, i32 (i8, i8)* %2) {
%4 = tail call i32 (i8*, ...) bitcast (i32 (...)* @assert to i32 (i8*, ...)*)(i8* %0)
%5 = tail call i32 (i8*, ...) bitcast (i32 (...)* @assert to i32 (i8*, ...)*)(i8* %1)
%6 = tail call i32 (i32 (i8, i8)*, ...) bitcast (i32 (...)* @assert to i32 (i32 (i8, i8)*, ...)*)(i32 (i8, i8)* %2)
%7 = tail call i32 (i8*, ...) bitcast (i32 (...)* @strings_length to i32 (i8*, ...)*)(i8* %0)
%8 = tail call i32 (i8*, ...) bitcast (i32 (...)* @strings_length to i32 (i8*, ...)*)(i8* %1)
%9 = icmp ne i32 %7, 0
%10 = icmp ne i32 %8, 0
%11 = select i1 %9, i1 %10, i1 false
br i1 %11, label %12, label %28
12: ; preds = %3
%13 = zext i32 %8 to i64
%14 = zext i32 %7 to i64
br label %19
15: ; preds = %19
%16 = icmp ult i64 %27, %14
%17 = icmp ult i64 %27, %13
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %19, label %28
19: ; preds = %12, %15
%20 = phi i64 [ 0, %12 ], [ %27, %15 ]
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = load i8, i8* %21
%23 = getelementptr inbounds i8, i8* %1, i64 %20
%24 = load i8, i8* %23
%25 = tail call i32 %2(i8 signext %22, i8 signext %24)
%26 = icmp eq i32 %25, 0
%27 = add nuw nsw i64 %20, 1
br i1 %26, label %15, label %33
28: ; preds = %15, %3
%29 = icmp ugt i32 %8, %7
br i1 %29, label %33, label %30
30: ; preds = %28
%31 = icmp ugt i32 %7, %8
%32 = zext i1 %31 to i32
br label %33
33: ; preds = %19, %30, %28
%34 = phi i32 [ -1, %28 ], [ %32, %30 ], [ %25, %19 ]
ret i32 %34
}