#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 */
scalar_t__ tolower(char);
int noCaseStrncmp(char *s, char *t, int n) {
  for (n--; (tolower(*s) == tolower(*t)) && (n > 0); s++, t++, n--)
    if (*s == '\0')
      return 0;
  return (int)(tolower(*s) - tolower(*t));
}


x86 assembly (clang, -O0):
<noCaseStrncmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    -0x28(%rbp),%rcx
mov    %rax,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x1d(%rbp)
jne    1167 <noCaseStrncmp+0x57>
cmpl   $0x0,-0x1c(%rbp)
setg   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1177 <noCaseStrncmp+0x67>
jmp    11be <noCaseStrncmp+0xae>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1193 <noCaseStrncmp+0x83>
movl   $0x0,-0x4(%rbp)
jmp    11e7 <noCaseStrncmp+0xd7>
jmp    1198 <noCaseStrncmp+0x88>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    112c <noCaseStrncmp+0x1c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<noCaseStrncmp>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <tolower@plt>
mov    %rax,%r12
movsbl (%r15),%edi
call   1030 <tolower@plt>
cmp    %rax,%r12
jne    118a <noCaseStrncmp+0x7a>
cmp    $0x2,%r14d
jl     118a <noCaseStrncmp+0x7a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,(%rbx)
je     11a6 <noCaseStrncmp+0x96>
lea    0x1(%r15),%r13
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <tolower@plt>
mov    %rax,%r12
movsbl 0x1(%r15),%edi
call   1030 <tolower@plt>
cmp    %rax,%r12
jne    118d <noCaseStrncmp+0x7d>
lea    -0x1(%r14),%eax
mov    %r13,%r15
cmp    $0x2,%r14d
mov    %eax,%r14d
jg     1150 <noCaseStrncmp+0x40>
jmp    118d <noCaseStrncmp+0x7d>
mov    %r15,%r13
movsbl (%rbx),%edi
call   1030 <tolower@plt>
mov    %rax,%rbx
movsbl 0x0(%r13),%edi
call   1030 <tolower@plt>
sub    %eax,%ebx
jmp    11a8 <noCaseStrncmp+0x98>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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