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


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
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x15(%rbp)
je     115e <strcasecmp+0x4e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    116e <strcasecmp+0x5e>
jmp    118b <strcasecmp+0x7b>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1120 <strcasecmp+0x10>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
movzbl %al,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
movzbl %cl,%ecx
sub    %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcasecmp>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <tolower@plt>
test   %eax,%eax
je     1154 <strcasecmp+0x44>
mov    %eax,%ebp
nopl   0x0(%rax,%rax,1)
movsbl (%r14),%edi
call   1030 <tolower@plt>
cmp    %eax,%ebp
jne    1154 <strcasecmp+0x44>
add    $0x1,%r14
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <tolower@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1130 <strcasecmp+0x20>
movsbl (%rbx),%edi
call   1030 <tolower@plt>
movzbl %al,%ebx
movsbl (%r14),%edi
call   1030 <tolower@plt>
movzbl %al,%eax
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 i32
store i8* %0, i8** %3
store i8* %1, i8** %4
br label %6
6: ; preds = %19, %2
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = call i32 @tolower(i8 signext %8)
store i32 %9, i32* %5
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %6
%12 = load i32, i32* %5
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = call i32 @tolower(i8 signext %14)
%16 = icmp eq i32 %12, %15
br label %17
17: ; preds = %11, %6
%18 = phi i1 [ false, %6 ], [ %16, %11 ]
br i1 %18, label %19, label %24
19: ; preds = %17
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %3
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %4
br label %6
24: ; preds = %17
%25 = load i8*, i8** %3
%26 = load i8, i8* %25
%27 = call i32 @tolower(i8 signext %26)
%28 = trunc i32 %27 to i8
%29 = zext i8 %28 to i32
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = call i32 @tolower(i8 signext %31)
%33 = trunc i32 %32 to i8
%34 = zext i8 %33 to i32
%35 = sub nsw i32 %29, %34
ret i32 %35
}

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