#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 memcmp(char *, char *, size_t);
int sp_compare_lexicographically(char *a, size_t asz, char *b, size_t bsz,
                                 void *arg) {
  register int rc = memcmp(a, b, ((asz) < (bsz) ? (asz) : (bsz)));
  if (0 == rc) {
    if (asz == bsz)
      return 0;
    return asz > bsz ? 1 : -1;
  }
  return (rc > 0 ? 1 : -1);
}


x86 assembly (clang, -O0):
<sp_compare_lexicographically>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1157 <sp_compare_lexicographically+0x47>
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    115f <sp_compare_lexicographically+0x4f>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rdx
call   1030 <memcmp@plt>
mov    %eax,-0x34(%rbp)
xor    %eax,%eax
cmp    -0x34(%rbp),%eax
jne    11b8 <sp_compare_lexicographically+0xa8>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    1198 <sp_compare_lexicographically+0x88>
movl   $0x0,-0x4(%rbp)
jmp    11ce <sp_compare_lexicographically+0xbe>
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rsi
mov    $0xffffffff,%eax
mov    $0x1,%ecx
cmp    %rsi,%rdx
cmova  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11ce <sp_compare_lexicographically+0xbe>
mov    -0x34(%rbp),%edx
mov    $0xffffffff,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovg  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sp_compare_lexicographically>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rsi,%rbx
cmp    %rcx,%rsi
mov    %rcx,%rax
cmovb  %rsi,%rax
mov    %rdx,%rsi
mov    %rax,%rdx
call   1030 <memcmp@plt>
test   %eax,%eax
je     1138 <sp_compare_lexicographically+0x28>
setg   %al
jmp    1142 <sp_compare_lexicographically+0x32>
xor    %eax,%eax
cmp    %r14,%rbx
je     114a <sp_compare_lexicographically+0x3a>
seta   %al
movzbl %al,%eax
add    %eax,%eax
add    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @sp_compare_lexicographically(i8* %0, i64 %1, i8* %2, i64 %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %7
store i64 %1, i64* %8
store i8* %2, i8** %9
store i64 %3, i64* %10
store i8* %4, i8** %11
%13 = load i8*, i8** %7
%14 = load i8*, i8** %9
%15 = load i64, i64* %8
%16 = load i64, i64* %10
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %5
%19 = load i64, i64* %8
br label %22
20: ; preds = %5
%21 = load i64, i64* %10
br label %22
22: ; preds = %20, %18
%23 = phi i64 [ %19, %18 ], [ %21, %20 ]
%24 = call i32 @memcmp(i8* %13, i8* %14, i64 %23)
store i32 %24, i32* %12
%25 = load i32, i32* %12
%26 = icmp eq i32 0, %25
br i1 %26, label %27, label %38
27: ; preds = %22
%28 = load i64, i64* %8
%29 = load i64, i64* %10
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 0, i32* %6
br label %43
32: ; preds = %27
%33 = load i64, i64* %8
%34 = load i64, i64* %10
%35 = icmp ugt i64 %33, %34
%36 = zext i1 %35 to i64
%37 = select i1 %35, i32 1, i32 -1
store i32 %37, i32* %6
br label %43
38: ; preds = %22
%39 = load i32, i32* %12
%40 = icmp sgt i32 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i32 1, i32 -1
store i32 %42, i32* %6
br label %43
43: ; preds = %38, %32, %31
%44 = load i32, i32* %6
ret i32 %44
}

LLVM IR (-O2):
define i32 @sp_compare_lexicographically(i8* nocapture %0, i64 %1, i8* nocapture %2, i64 %3, i8* nocapture readnone %4) {
%6 = icmp ult i64 %1, %3
%7 = select i1 %6, i64 %1, i64 %3
%8 = tail call i32 @memcmp(i8* %0, i8* %2, i64 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %5
%11 = icmp eq i64 %1, %3
br i1 %11, label %18, label %12
12: ; preds = %10
%13 = icmp ugt i64 %1, %3
%14 = select i1 %13, i32 1, i32 -1
br label %18
15: ; preds = %5
%16 = icmp slt i32 %8, 1
%17 = select i1 %16, i32 -1, i32 1
br label %18
18: ; preds = %10, %15, %12
%19 = phi i32 [ %14, %12 ], [ %17, %15 ], [ 0, %10 ]
ret i32 %19
}