#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 /*<<< orphan*/);
int str__memicmp(const char *str1, const char *str2, size_t length) {
  int result = 0;
  while ((length != 0) && (result == 0)) {
    result = tolower(*str1++) - tolower(*str2++);
    length--;
  }
  return result;
}


x86 assembly (clang, -O0):
<str__memicmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x1d(%rbp)
je     1145 <str__memicmp+0x35>
cmpl   $0x0,-0x1c(%rbp)
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1155 <str__memicmp+0x45>
jmp    11a1 <str__memicmp+0x91>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    112b <str__memicmp+0x1b>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str__memicmp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdx,%rdx
je     1157 <str__memicmp+0x47>
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
add    $0xffffffffffffffff,%r12
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl (%r15,%rbx,1),%edi
call   1030 <tolower@plt>
mov    %eax,%ebp
movsbl (%r14,%rbx,1),%edi
call   1030 <tolower@plt>
sub    %eax,%ebp
cmp    %rbx,%r12
je     1159 <str__memicmp+0x49>
add    $0x1,%rbx
test   %ebp,%ebp
je     1130 <str__memicmp+0x20>
jmp    1159 <str__memicmp+0x49>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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