#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 tolower(char);
int compare(const void *left, const void *right) {
  char op1, op2;
  op1 = *(char *)left;
  op2 = *(char *)right;
  if (tolower(op1) != tolower(op2)) {
    return tolower(op1) - tolower(op2);
  } else {
    return op1 - op2;
  }
  return *(char *)left - *(char *)right;
}


x86 assembly (clang, -O0):
<compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1a(%rbp)
movsbl -0x19(%rbp),%edi
call   1030 <tolower@plt>
mov    %eax,-0x20(%rbp)
movsbl -0x1a(%rbp),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
je     1178 <compare+0x68>
movsbl -0x19(%rbp),%edi
call   1030 <tolower@plt>
mov    %eax,-0x24(%rbp)
movsbl -0x1a(%rbp),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1185 <compare+0x75>
movsbl -0x19(%rbp),%eax
movsbl -0x1a(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare>:
push   %rbp
push   %r14
push   %rbx
movsbl (%rdi),%ebx
movsbl (%rsi),%r14d
mov    %ebx,%edi
call   1030 <tolower@plt>
mov    %eax,%ebp
mov    %r14d,%edi
call   1030 <tolower@plt>
cmp    %eax,%ebp
jne    1135 <compare+0x25>
sub    %r14d,%ebx
jmp    1148 <compare+0x38>
mov    %ebx,%edi
call   1030 <tolower@plt>
mov    %eax,%ebx
mov    %r14d,%edi
call   1030 <tolower@plt>
sub    %eax,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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