#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__ errno;
int memcmp(char *, char *, size_t);
int memcoll(char *s1, size_t s1len, char *s2, size_t s2len) {
  int diff;
  diff = memcmp(s1, s2, s1len < s2len ? s1len : s2len);
  if (!diff)
    diff = s1len < s2len ? -1 : s1len != s2len;
  errno = 0;
  return diff;
}


x86 assembly (clang, -O0):
<memcoll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1153 <memcoll+0x43>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    115b <memcoll+0x4b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rdx
call   1030 <memcmp@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11ad <memcoll+0x9d>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1194 <memcoll+0x84>
mov    $0xffffffff,%eax
mov    %eax,-0x44(%rbp)
jmp    11a7 <memcoll+0x97>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e2c(%rip),%rax
movq   $0x0,(%rax)
mov    -0x24(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memcoll>:
push   %rbx
xor    %eax,%eax
cmp    %rcx,%rsi
cmovb  %rsi,%rcx
setne  %al
mov    $0xffffffff,%ebx
cmovae %eax,%ebx
mov    %rdx,%rsi
mov    %rcx,%rdx
call   1030 <memcmp@plt>
test   %eax,%eax
cmove  %ebx,%eax
mov    0x2ea4(%rip),%rcx
movq   $0x0,(%rcx)
pop    %rbx
ret

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

LLVM IR (-O2):
@errno = global i64 0
define i32 @memcoll(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 ne i64 %1, %3
%10 = zext i1 %9 to i32
%11 = select i1 %5, i32 -1, i32 %10
%12 = select i1 %8, i32 %11, i32 %7
store i64 0, i64* @errno
ret i32 %12
}