#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 xstrncasecmp(const char *inLeftString, const char *inRightString,
                 size_t inMaxChars) {
  int result = 0;
  int leftChar, rightChar;
  do {
    leftChar = tolower(*inLeftString++);
    rightChar = tolower(*inRightString++);
    result = leftChar - rightChar;
  } while ((--inMaxChars != 0) && (leftChar != 0) && (result == 0));
  return result;
}


x86 assembly (clang, -O0):
<xstrncasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x25(%rbp)
je     119c <xstrncasecmp+0x8c>
xor    %eax,%eax
cmpl   $0x0,-0x20(%rbp)
mov    %al,-0x25(%rbp)
je     119c <xstrncasecmp+0x8c>
cmpl   $0x0,-0x1c(%rbp)
sete   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    112b <xstrncasecmp+0x1b>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstrncasecmp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
add    $0xffffffffffffffff,%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edi
call   1030 <tolower@plt>
mov    %eax,%ebp
movsbl (%r14,%rbx,1),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    %ebp,%eax
sub    %ecx,%eax
cmp    %rbx,%r12
je     115d <xstrncasecmp+0x4d>
test   %ebp,%ebp
je     115d <xstrncasecmp+0x4d>
add    $0x1,%rbx
test   %eax,%eax
je     1130 <xstrncasecmp+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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