#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) {
  const unsigned char *us1 = (const unsigned char *)s1,
                      *us2 = (const unsigned char *)s2;
  while (tolower((int)*us1) == tolower((int)*us2++))
    if (*us1++ == '\0')
      return (0);
  return (tolower((int)*us1) - tolower((int)*--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   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
movzbl (%r15,%rbx,1),%r12d
movzbl %r12b,%edi
call   1030 <tolower@plt>
mov    %eax,%ebp
movzbl (%r14,%rbx,1),%edi
call   1030 <tolower@plt>
sub    %eax,%ebp
jne    1149 <strcasecmp+0x39>
add    $0x1,%rbx
test   %r12b,%r12b
jne    1120 <strcasecmp+0x10>
xor    %ebp,%ebp
mov    %ebp,%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*
%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 = %28, %2
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = call i32 @tolower(i32 %13)
%15 = load i8*, i8** %7
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %7
%17 = load i8, i8* %15
%18 = zext i8 %17 to i32
%19 = call i32 @tolower(i32 %18)
%20 = icmp eq i32 %14, %19
br i1 %20, label %21, label %29
21: ; preds = %10
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %6
%24 = load i8, i8* %22
%25 = zext i8 %24 to i32
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 0, i32* %3
br label %40
28: ; preds = %21
br label %10
29: ; preds = %10
%30 = load i8*, i8** %6
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = call i32 @tolower(i32 %32)
%34 = load i8*, i8** %7
%35 = getelementptr inbounds i8, i8* %34, i32 -1
store i8* %35, i8** %7
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = call i32 @tolower(i32 %37)
%39 = sub nsw i32 %33, %38
store i32 %39, i32* %3
br label %40
40: ; preds = %29, %27
%41 = load i32, i32* %3
ret i32 %41
}

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