#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 */
scalar_t__ strncmp(char *, char *, int);
size_t strnlen(char *, int);
int compareKeys(char *key1, char *key2) {
  size_t l1 = strnlen(key1, 255), l2 = strnlen(key2, 255);
  if (l1 > l2)
    return 0;
  else if (l1 < l2)
    return 1;
  else
    return strncmp(key1, key2, 255) < 0;
}


x86 assembly (clang, -O0):
<compareKeys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xff,%esi
call   1040 <strnlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0xff,%esi
call   1040 <strnlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    116e <compareKeys+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    11a9 <compareKeys+0x89>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1188 <compareKeys+0x68>
movl   $0x1,-0x4(%rbp)
jmp    11a9 <compareKeys+0x89>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xff,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compareKeys>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0xff,%esi
call   1040 <strnlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0xff,%esi
call   1040 <strnlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rbx
ja     116a <compareKeys+0x4a>
mov    $0x1,%eax
jb     116a <compareKeys+0x4a>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0xff,%edx
call   1030 <strncmp@plt>
shr    $0x3f,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @compareKeys(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i64 @strnlen(i8* %8, i32 255)
store i64 %9, i64* %6
%10 = load i8*, i8** %5
%11 = call i64 @strnlen(i8* %10, i32 255)
store i64 %11, i64* %7
%12 = load i64, i64* %6
%13 = load i64, i64* %7
%14 = icmp ugt i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 0, i32* %3
br label %27
16: ; preds = %2
%17 = load i64, i64* %6
%18 = load i64, i64* %7
%19 = icmp ult i64 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 1, i32* %3
br label %27
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = load i8*, i8** %5
%24 = call i64 @strncmp(i8* %22, i8* %23, i32 255)
%25 = icmp slt i64 %24, 0
%26 = zext i1 %25 to i32
store i32 %26, i32* %3
br label %27
27: ; preds = %21, %20, %15
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
define i32 @compareKeys(i8* %0, i8* %1) {
%3 = tail call i64 @strnlen(i8* %0, i32 255)
%4 = tail call i64 @strnlen(i8* %1, i32 255)
%5 = icmp ugt i64 %3, %4
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = icmp ult i64 %3, %4
br i1 %7, label %12, label %8
8: ; preds = %6
%9 = tail call i64 @strncmp(i8* %0, i8* %1, i32 255)
%10 = lshr i64 %9, 63
%11 = trunc i64 %10 to i32
br label %12
12: ; preds = %6, %2, %8
%13 = phi i32 [ %11, %8 ], [ 0, %2 ], [ 1, %6 ]
ret i32 %13
}