#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(void const *, void const *, size_t);
int qtreetbl_byte_cmp(const void *name1, size_t namesize1, const void *name2,
                      size_t namesize2) {
  size_t minsize = (namesize1 < namesize2) ? namesize1 : namesize2;
  int cmp = memcmp(name1, name2, minsize);
  if (cmp != 0 || namesize1 == namesize2)
    return cmp;
  return (namesize1 < namesize2) ? -1 : +1;
}


x86 assembly (clang, -O0):
<qtreetbl_byte_cmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1143 <qtreetbl_byte_cmp+0x33>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    114b <qtreetbl_byte_cmp+0x3b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <memcmp@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    117f <qtreetbl_byte_cmp+0x6f>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    118a <qtreetbl_byte_cmp+0x7a>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a5 <qtreetbl_byte_cmp+0x95>
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rsi
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    %rsi,%rdx
cmovb  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qtreetbl_byte_cmp>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rsi,%r15
xor    %ebx,%ebx
cmp    %rcx,%rsi
setae  %bl
mov    %rcx,%rax
cmovb  %rsi,%rax
mov    %rdx,%rsi
mov    %rax,%rdx
call   1030 <memcmp@plt>
test   %eax,%eax
lea    -0x1(%rbx,%rbx,1),%ecx
cmovne %eax,%ecx
cmp    %r14,%r15
cmovne %ecx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @qtreetbl_byte_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 ne i32 %7, 0
%9 = icmp eq i64 %1, %3
%10 = or i1 %9, %8
%11 = select i1 %5, i32 -1, i32 1
%12 = select i1 %10, i32 %7, i32 %11
ret i32 %12
}