#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__ isupper(char const);
int tolower(char const);
int clp_string_cmp(const void *lhs, const void *rhs) {
  const char *l = (const char *)lhs;
  const char *r = (const char *)rhs;
  int lc = tolower(*l);
  int rc = tolower(*r);
  if (lc == rc) {
    return (isupper(*l) ? -1 : 1);
  }
  return (lc - rc);
}


x86 assembly (clang, -O0):
<clp_string_cmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jne    1192 <clp_string_cmp+0x72>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isupper@plt>
mov    %rax,%rdx
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    119b <clp_string_cmp+0x7b>
mov    -0x2c(%rbp),%eax
sub    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clp_string_cmp>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
movsbl (%rdi),%edi
call   1030 <tolower@plt>
mov    %eax,%ebx
movsbl (%r15),%edi
call   1030 <tolower@plt>
sub    %eax,%ebx
jne    1153 <clp_string_cmp+0x33>
movsbl (%r14),%edi
call   1040 <isupper@plt>
neg    %rax
sbb    %ebx,%ebx
or     $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @clp_string_cmp(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
store i8* %10, i8** %6
%11 = load i8*, i8** %5
store i8* %11, i8** %7
%12 = load i8*, i8** %6
%13 = load i8, i8* %12
%14 = call i32 @tolower(i8 signext %13)
store i32 %14, i32* %8
%15 = load i8*, i8** %7
%16 = load i8, i8* %15
%17 = call i32 @tolower(i8 signext %16)
store i32 %17, i32* %9
%18 = load i32, i32* %8
%19 = load i32, i32* %9
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %28
21: ; preds = %2
%22 = load i8*, i8** %6
%23 = load i8, i8* %22
%24 = call i64 @isupper(i8 signext %23)
%25 = icmp ne i64 %24, 0
%26 = zext i1 %25 to i64
%27 = select i1 %25, i32 -1, i32 1
store i32 %27, i32* %3
br label %32
28: ; preds = %2
%29 = load i32, i32* %8
%30 = load i32, i32* %9
%31 = sub nsw i32 %29, %30
store i32 %31, i32* %3
br label %32
32: ; preds = %28, %21
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @clp_string_cmp(i8* nocapture %0, i8* nocapture %1) {
%3 = load i8, i8* %0
%4 = tail call i32 @tolower(i8 signext %3)
%5 = load i8, i8* %1
%6 = tail call i32 @tolower(i8 signext %5)
%7 = icmp eq i32 %4, %6
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i8, i8* %0
%10 = tail call i64 @isupper(i8 signext %9)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i32 1, i32 -1
br label %15
13: ; preds = %2
%14 = sub nsw i32 %4, %6
br label %15
15: ; preds = %13, %8
%16 = phi i32 [ %12, %8 ], [ %14, %13 ]
ret i32 %16
}