#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 strcasecmp(char *, char *);
int KeyCompareString(void *left, void *right) {
  int res;
  char *l, *r;
  if (!left || !right) {
    return (0);
  }
  l = *(char **)left;
  r = *(char **)right;
  res = strcasecmp(l, r);
  if (res > 1) {
    res = 1;
  } else if (res < -1) {
    res = -1;
  }
  return (res);
}


x86 assembly (clang, -O0):
<KeyCompareString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1136 <KeyCompareString+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1142 <KeyCompareString+0x32>
movl   $0x0,-0x4(%rbp)
jmp    119a <KeyCompareString+0x8a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <strcasecmp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jle    117e <KeyCompareString+0x6e>
movl   $0x1,-0x1c(%rbp)
jmp    1194 <KeyCompareString+0x84>
cmpl   $0xffffffff,-0x1c(%rbp)
jge    118f <KeyCompareString+0x7f>
movl   $0xffffffff,-0x1c(%rbp)
jmp    1194 <KeyCompareString+0x84>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<KeyCompareString>:
xor    %eax,%eax
test   %rdi,%rdi
je     1140 <KeyCompareString+0x30>
test   %rsi,%rsi
je     1140 <KeyCompareString+0x30>
push   %rax
mov    (%rdi),%rdi
mov    (%rsi),%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
mov    $0xffffffff,%ecx
cmovns %eax,%ecx
test   %ecx,%ecx
mov    $0x1,%eax
cmovle %ecx,%eax
add    $0x8,%rsp
ret

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

LLVM IR (-O2):
define i32 @KeyCompareString(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %16
6: ; preds = %2
%7 = bitcast i8* %0 to i8**
%8 = load i8*, i8** %7
%9 = bitcast i8* %1 to i8**
%10 = load i8*, i8** %9
%11 = tail call i32 @strcasecmp(i8* %8, i8* %10)
%12 = icmp sgt i32 %11, -1
%13 = select i1 %12, i32 %11, i32 -1
%14 = icmp slt i32 %13, 1
%15 = select i1 %14, i32 %13, i32 1
br label %16
16: ; preds = %2, %6
%17 = phi i32 [ %15, %6 ], [ 0, %2 ]
ret i32 %17
}