#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 *, int);
int cache_name_compare(const char *name1, int len1, const char *name2,
                       int len2) {
  int len = len1 < len2 ? len1 : len2;
  int cmp;
  cmp = memcmp(name1, name2, len);
  if (cmp)
    return cmp;
  if (len1 < len2)
    return -1;
  if (len1 > len2)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<cache_name_compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    113d <cache_name_compare+0x2d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1143 <cache_name_compare+0x33>
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1030 <memcmp@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1171 <cache_name_compare+0x61>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a8 <cache_name_compare+0x98>
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1189 <cache_name_compare+0x79>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a8 <cache_name_compare+0x98>
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jle    11a1 <cache_name_compare+0x91>
movl   $0x1,-0x4(%rbp)
jmp    11a8 <cache_name_compare+0x98>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cache_name_compare>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r14d
mov    %esi,%ebp
xor    %ebx,%ebx
cmp    %ecx,%esi
mov    %ecx,%eax
cmovl  %esi,%eax
setg   %bl
mov    %rdx,%rsi
mov    %eax,%edx
call   1030 <memcmp@plt>
cmp    $0x1,%eax
sbb    %ecx,%ecx
or     %eax,%ecx
test   %eax,%eax
cmovne %ecx,%ebx
cmp    %r14d,%ebp
cmovl  %ecx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @cache_name_compare(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp slt i32 %1, %3
%6 = select i1 %5, i32 %1, i32 %3
%7 = tail call i32 @memcmp(i8* %0, i8* %2, i32 %6)
%8 = icmp ne i32 %7, 0
%9 = or i1 %5, %8
%10 = select i1 %8, i32 %7, i32 -1
%11 = icmp sgt i32 %1, %3
%12 = zext i1 %11 to i32
%13 = select i1 %9, i32 %10, i32 %12
ret i32 %13
}