#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 /*<<< orphan*/ _DIAGASSERT(int /*<<< orphan*/);
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;
  _DIAGASSERT(s1 != NULL);
  _DIAGASSERT(s2 != NULL);
  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)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <_DIAGASSERT@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <_DIAGASSERT@plt>
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   1040 <tolower@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movzbl (%rax),%edi
call   1040 <tolower@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jne    11c3 <strcasecmp+0xa3>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movzbl (%rax),%eax
cmp    $0x0,%eax
jne    11be <strcasecmp+0x9e>
movl   $0x0,-0x4(%rbp)
jmp    11f4 <strcasecmp+0xd4>
jmp    1164 <strcasecmp+0x44>
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   1040 <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   1040 <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    %edi,%edi
test   %r15,%r15
setne  %dil
call   1030 <_DIAGASSERT@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <_DIAGASSERT@plt>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%edi
call   1040 <tolower@plt>
mov    %eax,%ebp
movzbl (%r14,%rbx,1),%edi
call   1040 <tolower@plt>
cmp    %eax,%ebp
jne    1179 <strcasecmp+0x59>
cmpb   $0x0,(%r15,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1150 <strcasecmp+0x30>
xor    %ebp,%ebp
jmp    1191 <strcasecmp+0x71>
movzbl (%r15,%rbx,1),%edi
call   1040 <tolower@plt>
mov    %eax,%ebp
movzbl (%r14,%rbx,1),%edi
call   1040 <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
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
%12 = zext i1 %11 to i32
%13 = call i32 @_DIAGASSERT(i32 %12)
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
%16 = zext i1 %15 to i32
%17 = call i32 @_DIAGASSERT(i32 %16)
br label %18
18: ; preds = %34, %2
%19 = load i8*, i8** %6
%20 = load i8, i8* %19
%21 = call i32 @tolower(i8 zeroext %20)
%22 = load i8*, i8** %7
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %7
%24 = load i8, i8* %22
%25 = call i32 @tolower(i8 zeroext %24)
%26 = icmp eq i32 %21, %25
br i1 %26, label %27, label %35
27: ; preds = %18
%28 = load i8*, i8** %6
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %6
%30 = load i8, i8* %28
%31 = zext i8 %30 to i32
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27
store i32 0, i32* %3
br label %44
34: ; preds = %27
br label %18
35: ; preds = %18
%36 = load i8*, i8** %6
%37 = load i8, i8* %36
%38 = call i32 @tolower(i8 zeroext %37)
%39 = load i8*, i8** %7
%40 = getelementptr inbounds i8, i8* %39, i32 -1
store i8* %40, i8** %7
%41 = load i8, i8* %40
%42 = call i32 @tolower(i8 zeroext %41)
%43 = sub nsw i32 %38, %42
store i32 %43, i32* %3
br label %44
44: ; preds = %35, %33
%45 = load i32, i32* %3
ret i32 %45
}

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