#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(int);
int strcasecmp(const char *s1, const char *s2) {
  while (tolower((int)*s1) == tolower((int)*s2)) {
    if (*s1++ == '\0')
      return (0);
    s2++;
  }
  return (tolower((int)*s1) - tolower((int)*s2));
}


x86 assembly (clang, -O0):
<strcasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jne    1180 <strcasecmp+0x70>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    116f <strcasecmp+0x5f>
movl   $0x0,-0x4(%rbp)
jmp    11a5 <strcasecmp+0x95>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1120 <strcasecmp+0x10>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcasecmp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%bl
movsbl %bl,%edi
call   1030 <tolower@plt>
mov    %eax,%r12d
movsbl (%r14),%edi
call   1030 <tolower@plt>
cmp    %eax,%r12d
jne    1167 <strcasecmp+0x57>
mov    $0x1,%ebp
xchg   %ax,%ax
test   %bl,%bl
je     116c <strcasecmp+0x5c>
movzbl (%r15,%rbp,1),%ebx
movsbl %bl,%edi
call   1030 <tolower@plt>
mov    %eax,%r12d
movsbl (%r14,%rbp,1),%edi
call   1030 <tolower@plt>
add    $0x1,%rbp
cmp    %eax,%r12d
je     1140 <strcasecmp+0x30>
sub    %eax,%r12d
jmp    116f <strcasecmp+0x5f>
xor    %r12d,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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