#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 toupper(char const);
int fits_strncasecmp(const char *s1, const char *s2, size_t n) {
  char c1, c2;
  for (; n--;) {
    c1 = toupper(*s1);
    c2 = toupper(*s2);
    if (c1 < c2)
      return (-1);
    if (c1 > c2)
      return (1);
    if (c1 == 0)
      return (0);
    s1++;
    s2++;
  }
  return (0);
}


x86 assembly (clang, -O0):
<fits_strncasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
je     11c9 <fits_strncasecmp+0xb9>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,-0x21(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,-0x22(%rbp)
movsbl -0x21(%rbp),%eax
movsbl -0x22(%rbp),%ecx
cmp    %ecx,%eax
jge    1177 <fits_strncasecmp+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <fits_strncasecmp+0xc0>
movsbl -0x21(%rbp),%eax
movsbl -0x22(%rbp),%ecx
cmp    %ecx,%eax
jle    1193 <fits_strncasecmp+0x83>
movl   $0x1,-0x4(%rbp)
jmp    11d0 <fits_strncasecmp+0xc0>
movsbl -0x21(%rbp),%eax
cmp    $0x0,%eax
jne    11ac <fits_strncasecmp+0x9c>
movl   $0x0,-0x4(%rbp)
jmp    11d0 <fits_strncasecmp+0xc0>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1124 <fits_strncasecmp+0x14>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fits_strncasecmp>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdx,%rdx
je     1160 <fits_strncasecmp+0x50>
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
add    $0xffffffffffffffff,%r12
xor    %r13d,%r13d
xchg   %ax,%ax
movsbl (%r15,%r13,1),%edi
call   1030 <toupper@plt>
mov    %eax,%ebx
movsbl (%r14,%r13,1),%edi
call   1030 <toupper@plt>
cmp    %al,%bl
jl     1164 <fits_strncasecmp+0x54>
jg     116b <fits_strncasecmp+0x5b>
xor    %eax,%eax
test   %bl,%bl
je     1170 <fits_strncasecmp+0x60>
lea    0x1(%r13),%rcx
cmp    %r13,%r12
mov    %rcx,%r13
jne    1130 <fits_strncasecmp+0x20>
jmp    1170 <fits_strncasecmp+0x60>
xor    %eax,%eax
jmp    1170 <fits_strncasecmp+0x60>
mov    $0xffffffff,%eax
jmp    1170 <fits_strncasecmp+0x60>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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