#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 */
unsigned char tolower(char const);
int local_strcasecmp(const char *s1, const char *s2) {
  unsigned char c1;
  unsigned char c2;
  do {
    c1 = tolower(*s1);
    c2 = tolower(*s2);
    if (!c1) {
      break;
    }
    ++s1;
    ++s2;
  } while (c1 == c2);
  return c1 - c2;
}


x86 assembly (clang, -O0):
<local_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    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %al,-0x12(%rbp)
cmpb   $0x0,-0x11(%rbp)
jne    114d <local_strcasecmp+0x3d>
jmp    1175 <local_strcasecmp+0x65>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
movzbl -0x11(%rbp),%eax
movzbl -0x12(%rbp),%ecx
cmp    %ecx,%eax
je     1120 <local_strcasecmp+0x10>
movzbl -0x11(%rbp),%eax
movzbl -0x12(%rbp),%ecx
sub    %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<local_strcasecmp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
nop
movsbl (%r15,%rbx,1),%edi
call   1030 <tolower@plt>
mov    %eax,%ebp
movsbl (%r14,%rbx,1),%edi
call   1030 <tolower@plt>
test   %bpl,%bpl
je     1144 <local_strcasecmp+0x34>
add    $0x1,%rbx
cmp    %al,%bpl
je     1120 <local_strcasecmp+0x10>
movzbl %bpl,%ecx
movzbl %al,%eax
sub    %eax,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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