#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(char const);
int mservcli_stricmp(const char *str1, const char *str2) {
  while (tolower(*str1) == tolower(*str2++)) {
    if (*str1++ == '\0')
      return 0;
  }
  return (tolower(*str1) - tolower(*--str2));
}


x86 assembly (clang, -O0):
<mservcli_stricmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jne    117f <mservcli_stricmp+0x6f>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    117a <mservcli_stricmp+0x6a>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <mservcli_stricmp+0xa0>
jmp    1120 <mservcli_stricmp+0x10>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movsbl -0x1(%rax),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mservcli_stricmp>:
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>
cmp    %eax,%ebp
jne    1149 <mservcli_stricmp+0x39>
cmpb   $0x0,(%r15,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1120 <mservcli_stricmp+0x10>
xor    %ebp,%ebp
jmp    1161 <mservcli_stricmp+0x51>
movsbl (%r15,%rbx,1),%edi
call   1030 <tolower@plt>
mov    %eax,%ebp
movsbl (%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 @mservcli_stricmp(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
br label %6
6: ; preds = %22, %2
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = call i32 @tolower(i8 signext %8)
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %5
%12 = load i8, i8* %10
%13 = call i32 @tolower(i8 signext %12)
%14 = icmp eq i32 %9, %13
br i1 %14, label %15, label %23
15: ; preds = %6
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %4
%18 = load i8, i8* %16
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 0, i32* %3
br label %32
22: ; preds = %15
br label %6
23: ; preds = %6
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = call i32 @tolower(i8 signext %25)
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 -1
store i8* %28, i8** %5
%29 = load i8, i8* %28
%30 = call i32 @tolower(i8 signext %29)
%31 = sub nsw i32 %26, %30
store i32 %31, i32* %3
br label %32
32: ; preds = %23, %21
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @mservcli_stricmp(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 signext %6)
%8 = load i8, i8* %5
%9 = tail call i32 @tolower(i8 signext %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 signext %17)
%19 = load i8, i8* %5
%20 = tail call i32 @tolower(i8 signext %19)
%21 = sub nsw i32 %18, %20
br label %22
22: ; preds = %11, %16
%23 = phi i32 [ %21, %16 ], [ 0, %11 ]
ret i32 %23
}