#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 const *, char const *, size_t);
int value_dict_default_cmp(const char *key1, size_t len1, const char *key2,
                           size_t len2) {
  size_t min_len = (len1 < len2) ? len1 : len2;
  int cmp;
  cmp = memcmp(key1, key2, min_len);
  if (cmp == 0 && len1 != len2)
    cmp = (len1 < len2) ? -1 : +1;
  return cmp;
}


x86 assembly (clang, -O0):
<value_dict_default_cmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1143 <value_dict_default_cmp+0x33>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    114b <value_dict_default_cmp+0x3b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <memcmp@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    119a <value_dict_default_cmp+0x8a>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     119a <value_dict_default_cmp+0x8a>
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rsi
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    %rsi,%rdx
cmovb  %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<value_dict_default_cmp>:
push   %rbx
xor    %r8d,%r8d
xor    %eax,%eax
cmp    %rcx,%rsi
cmovb  %rsi,%rcx
setae  %al
lea    -0x1(%rax,%rax,1),%ebx
cmove  %r8d,%ebx
mov    %rdx,%rsi
mov    %rcx,%rdx
call   1030 <memcmp@plt>
test   %eax,%eax
cmove  %ebx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @value_dict_default_cmp(i8* nocapture %0, i64 %1, i8* nocapture %2, i64 %3) {
%5 = icmp ult i64 %1, %3
%6 = select i1 %5, i64 %1, i64 %3
%7 = tail call i32 @memcmp(i8* %0, i8* %2, i64 %6)
%8 = icmp eq i32 %7, 0
%9 = icmp eq i64 %1, %3
%10 = select i1 %5, i32 -1, i32 1
%11 = select i1 %9, i32 0, i32 %10
%12 = select i1 %8, i32 %11, i32 %7
ret i32 %12
}