#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 const);
int strcasecmp(const char *str1, const char *str2) {
  unsigned const char *s1 = (unsigned const char *)str1;
  unsigned const char *s2 = (unsigned const char *)str2;
  while (*s1 && (tolower(*s1) == tolower(*s2))) {
    ++s1;
    ++s2;
  }
  return tolower(*s1) - tolower(*s2);
}


x86 assembly (clang, -O0):
<strcasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     116d <strcasecmp+0x5d>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    117d <strcasecmp+0x6d>
jmp    119a <strcasecmp+0x8a>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1130 <strcasecmp+0x20>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
sub    %ecx,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcasecmp>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    (%rdi),%al
test   %al,%al
je     1156 <strcasecmp+0x46>
mov    %rdi,%rbx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl %al,%edi
call   1030 <tolower@plt>
mov    %eax,%ebp
movzbl (%r14),%edi
call   1030 <tolower@plt>
cmp    %eax,%ebp
jne    115a <strcasecmp+0x4a>
add    $0x1,%r14
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <strcasecmp+0x20>
xor    %eax,%eax
jmp    115d <strcasecmp+0x4d>
mov    -0x1(%rbx),%al
movzbl %al,%edi
call   1030 <tolower@plt>
mov    %eax,%ebx
movzbl (%r14),%edi
call   1030 <tolower@plt>
sub    %eax,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @strcasecmp(i8* nocapture %0, i8* nocapture %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %20, label %5
5: ; preds = %2, %15
%6 = phi i8 [ %18, %15 ], [ %3, %2 ]
%7 = phi i8* [ %17, %15 ], [ %1, %2 ]
%8 = phi i8* [ %16, %15 ], [ %0, %2 ]
%9 = tail call i32 @tolower(i8 zeroext %6)
%10 = load i8, i8* %7
%11 = tail call i32 @tolower(i8 zeroext %10)
%12 = icmp eq i32 %9, %11
br i1 %12, label %15, label %13
13: ; preds = %5
%14 = load i8, i8* %8
br label %20
15: ; preds = %5
%16 = getelementptr inbounds i8, i8* %8, i64 1
%17 = getelementptr inbounds i8, i8* %7, i64 1
%18 = load i8, i8* %16
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %5
20: ; preds = %15, %13, %2
%21 = phi i8 [ 0, %2 ], [ %14, %13 ], [ 0, %15 ]
%22 = phi i8* [ %1, %2 ], [ %7, %13 ], [ %17, %15 ]
%23 = tail call i32 @tolower(i8 zeroext %21)
%24 = load i8, i8* %22
%25 = tail call i32 @tolower(i8 zeroext %24)
%26 = sub nsw i32 %23, %25
ret i32 %26
}