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


x86 assembly (clang, -O0):
<strcasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movzbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jne    118f <strcasecmp+0x7f>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movzbl (%rax),%eax
cmp    $0x0,%eax
jne    118a <strcasecmp+0x7a>
movl   $0x0,-0x4(%rbp)
jmp    11c0 <strcasecmp+0xb0>
jmp    1130 <strcasecmp+0x20>
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
movzbl -0x1(%rax),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%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>
cmp    %eax,%ebp
jne    1149 <strcasecmp+0x39>
cmpb   $0x0,(%r15,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1120 <strcasecmp+0x10>
xor    %ebp,%ebp
jmp    1161 <strcasecmp+0x51>
movzbl (%r15,%rbx,1),%edi
call   1030 <tolower@plt>
mov    %eax,%ebp
movzbl (%r14,%rbx,1),%edi
call   1030 <tolower@plt>
sub    %eax,%ebp
mov    %ebp,%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 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
store i8* %8, i8** %6
%9 = load i8*, i8** %5
store i8* %9, i8** %7
br label %10
10: ; preds = %26, %2
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = call i32 @tolower(i8 zeroext %12)
%14 = load i8*, i8** %7
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %7
%16 = load i8, i8* %14
%17 = call i32 @tolower(i8 zeroext %16)
%18 = icmp eq i32 %13, %17
br i1 %18, label %19, label %27
19: ; preds = %10
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %6
%22 = load i8, i8* %20
%23 = zext i8 %22 to i32
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %19
store i32 0, i32* %3
br label %36
26: ; preds = %19
br label %10
27: ; preds = %10
%28 = load i8*, i8** %6
%29 = load i8, i8* %28
%30 = call i32 @tolower(i8 zeroext %29)
%31 = load i8*, i8** %7
%32 = getelementptr inbounds i8, i8* %31, i32 -1
store i8* %32, i8** %7
%33 = load i8, i8* %32
%34 = call i32 @tolower(i8 zeroext %33)
%35 = sub nsw i32 %30, %34
store i32 %35, i32* %3
br label %36
36: ; preds = %27, %25
%37 = load i32, i32* %3
ret i32 %37
}

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