#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 strncasecmp(char const *, char const *, size_t);
int cmp_domains(size_t size_a, const void *a, size_t size_b, const void *b) {
  int result;
  if (size_a < size_b) {
    return -1;
  } else if (size_a > size_b) {
    return 1;
  } else {
    result = strncasecmp((const char *)a, (const char *)b, size_a);
    if (result > 0) {
      return 1;
    } else if (result < 0) {
      return -1;
    } else {
      return result;
    }
  }
}


x86 assembly (clang, -O0):
<cmp_domains>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1142 <cmp_domains+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a2 <cmp_domains+0x92>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    115c <cmp_domains+0x4c>
movl   $0x1,-0x4(%rbp)
jmp    11a2 <cmp_domains+0x92>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <strncasecmp@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    1186 <cmp_domains+0x76>
movl   $0x1,-0x4(%rbp)
jmp    11a2 <cmp_domains+0x92>
cmpl   $0x0,-0x2c(%rbp)
jge    119c <cmp_domains+0x8c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a2 <cmp_domains+0x92>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmp_domains>:
push   %rbx
mov    $0xffffffff,%ebx
cmp    %rdx,%rdi
jb     113b <cmp_domains+0x2b>
mov    $0x1,%ebx
ja     113b <cmp_domains+0x2b>
mov    %rdi,%rax
mov    %rsi,%rdi
mov    %rcx,%rsi
mov    %rax,%rdx
call   1030 <strncasecmp@plt>
test   %eax,%eax
jg     113b <cmp_domains+0x2b>
neg    %eax
sbb    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @cmp_domains(i64 %0, i8* %1, i64 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
store i64 %0, i64* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i8* %3, i8** %9
%11 = load i64, i64* %6
%12 = load i64, i64* %8
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %4
store i32 -1, i32* %5
br label %34
15: ; preds = %4
%16 = load i64, i64* %6
%17 = load i64, i64* %8
%18 = icmp ugt i64 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 1, i32* %5
br label %34
20: ; preds = %15
%21 = load i8*, i8** %7
%22 = load i8*, i8** %9
%23 = load i64, i64* %6
%24 = call i32 @strncasecmp(i8* %21, i8* %22, i64 %23)
store i32 %24, i32* %10
%25 = load i32, i32* %10
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %20
store i32 1, i32* %5
br label %34
28: ; preds = %20
%29 = load i32, i32* %10
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %28
store i32 -1, i32* %5
br label %34
32: ; preds = %28
%33 = load i32, i32* %10
store i32 %33, i32* %5
br label %34
34: ; preds = %32, %31, %27, %19, %14
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
define i32 @cmp_domains(i64 %0, i8* nocapture %1, i64 %2, i8* nocapture %3) {
%5 = icmp ult i64 %0, %2
br i1 %5, label %14, label %6
6: ; preds = %4
%7 = icmp ugt i64 %0, %2
br i1 %7, label %14, label %8
8: ; preds = %6
%9 = tail call i32 @strncasecmp(i8* %1, i8* %3, i64 %0)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = icmp ne i32 %9, 0
%13 = sext i1 %12 to i32
br label %14
14: ; preds = %11, %8, %6, %4
%15 = phi i32 [ -1, %4 ], [ 1, %6 ], [ 1, %8 ], [ %13, %11 ]
ret i32 %15
}