#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 const tolower(char const);
int strncmp_lower_vs_anycase(const char *s, const char *t, size_t n) {
  int diff;
  while (n-- > 0 && (diff = *s - tolower(*t)) == 0 && *s)
    s++, t++;
  return diff;
}


x86 assembly (clang, -O0):
<strncmp_lower_vs_anycase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
mov    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1d(%rbp)
jbe    1181 <strncmp_lower_vs_anycase+0x71>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    -0x24(%rbp),%ecx
movsbl %al,%eax
sub    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
jne    1181 <strncmp_lower_vs_anycase+0x71>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1191 <strncmp_lower_vs_anycase+0x81>
jmp    11ae <strncmp_lower_vs_anycase+0x9e>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <strncmp_lower_vs_anycase+0x14>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

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

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

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