#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 */
char jam_toupper(char);
int jam_strnicmp(char *left, char *right, int count) {
  int result = 0;
  char l, r;
  do {
    l = jam_toupper(*left);
    r = jam_toupper(*right);
    result = l - r;
    ++left;
    ++right;
    --count;
  } while ((result == 0) && (count > 0) && (l != '\0') && (r != '\0'));
  return (result);
}


x86 assembly (clang, -O0):
<jam_strnicmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <jam_toupper@plt>
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <jam_toupper@plt>
mov    %al,-0x1a(%rbp)
movsbl -0x19(%rbp),%eax
movsbl -0x1a(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x1b(%rbp)
jne    11b3 <jam_strnicmp+0xa3>
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x1b(%rbp)
jle    11b3 <jam_strnicmp+0xa3>
movsbl -0x19(%rbp),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1b(%rbp)
je     11b3 <jam_strnicmp+0xa3>
movsbl -0x1a(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1b(%rbp)
mov    -0x1b(%rbp),%al
test   $0x1,%al
jne    112a <jam_strnicmp+0x1a>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jam_strnicmp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%r15,%rbp,1),%edi
call   1030 <jam_toupper@plt>
mov    %eax,%ebx
movsbl (%r14,%rbp,1),%edi
call   1030 <jam_toupper@plt>
mov    %eax,%ecx
movsbl %bl,%eax
movsbl %cl,%edx
sub    %edx,%eax
jne    1168 <jam_strnicmp+0x58>
cmp    $0x2,%r12d
jl     1168 <jam_strnicmp+0x58>
test   %bl,%bl
je     1168 <jam_strnicmp+0x58>
add    $0xffffffff,%r12d
add    $0x1,%rbp
test   %cl,%cl
jne    1130 <jam_strnicmp+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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