#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(unsigned char);
int strcasecmp(const char *s1, const char *s2) {
  int c1, c2;
  do {
    c1 = tolower((unsigned char)*s1++);
    c2 = tolower((unsigned char)*s2++);
  } while (c1 == c2 && c1 != 0);
  return c2 > c1 ? -1 : c1 > c2;
}


x86 assembly (clang, -O0):
<strcasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movzbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
xor    %eax,%eax
cmp    -0x18(%rbp),%ecx
mov    %al,-0x19(%rbp)
jne    116f <strcasecmp+0x5f>
cmpl   $0x0,-0x14(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1120 <strcasecmp+0x10>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1193 <strcasecmp+0x83>
mov    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    11a4 <strcasecmp+0x94>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcasecmp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
nop
movzbl (%r15,%rbx,1),%edi
call   1030 <tolower@plt>
mov    %eax,%ebp
movzbl (%r14,%rbx,1),%edi
call   1030 <tolower@plt>
test   %ebp,%ebp
je     1142 <strcasecmp+0x32>
add    $0x1,%rbx
cmp    %eax,%ebp
je     1120 <strcasecmp+0x10>
xor    %ecx,%ecx
cmp    %eax,%ebp
setg   %cl
mov    $0xffffffff,%eax
cmovge %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @strcasecmp(i8* nocapture %0, i8* nocapture %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i8* [ %1, %2 ], [ %9, %3 ]
%5 = phi i8* [ %0, %2 ], [ %6, %3 ]
%6 = getelementptr inbounds i8, i8* %5, i64 1
%7 = load i8, i8* %5
%8 = tail call i32 @tolower(i8 zeroext %7)
%9 = getelementptr inbounds i8, i8* %4, i64 1
%10 = load i8, i8* %4
%11 = tail call i32 @tolower(i8 zeroext %10)
%12 = icmp eq i32 %8, %11
%13 = icmp ne i32 %8, 0
%14 = and i1 %13, %12
br i1 %14, label %3, label %15
15: ; preds = %3
%16 = icmp sgt i32 %11, %8
%17 = icmp sgt i32 %8, %11
%18 = zext i1 %17 to i32
%19 = select i1 %16, i32 -1, i32 %18
ret i32 %19
}