#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 lowercase(int /*<<< orphan*/);
int mg_strcasecmp(const char *s1, const char *s2) {
  int diff;
  do {
    diff = lowercase(s1++) - lowercase(s2++);
  } while (diff == 0 && s1[-1] != '\0');
  return (diff);
}


x86 assembly (clang, -O0):
<mg_strcasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    %eax,%edi
call   1030 <lowercase@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    %eax,%edi
call   1030 <lowercase@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x19(%rbp)
jne    1179 <mg_strcasecmp+0x69>
mov    -0x8(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1120 <mg_strcasecmp+0x10>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mg_strcasecmp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdi,%r15
mov    %ebx,%edi
call   1030 <lowercase@plt>
mov    %eax,%ebp
mov    %r14d,%edi
call   1030 <lowercase@plt>
sub    %eax,%ebp
jne    1146 <mg_strcasecmp+0x36>
add    $0x1,%r14d
add    $0x1,%ebx
cmpb   $0x0,(%r15)
lea    0x1(%r15),%r15
jne    1120 <mg_strcasecmp+0x10>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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