#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 upcase(int /*<<< orphan*/);
int strncasecmp(char *s1, char *s2, int len) {
  char c1, c2;
  while (len-- > 0) {
    c1 = upcase(*s1++);
    c2 = upcase(*s2++);
    if (c1 < c2)
      return -1;
    if (c1 > c2)
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<strncasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
jle    11a8 <strncasecmp+0x98>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <upcase@plt>
mov    %al,-0x1d(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%edi
call   1030 <upcase@plt>
mov    %al,-0x1e(%rbp)
movsbl -0x1d(%rbp),%eax
movsbl -0x1e(%rbp),%ecx
cmp    %ecx,%eax
jge    1187 <strncasecmp+0x77>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <strncasecmp+0x9f>
movsbl -0x1d(%rbp),%eax
movsbl -0x1e(%rbp),%ecx
cmp    %ecx,%eax
jle    11a3 <strncasecmp+0x93>
movl   $0x1,-0x4(%rbp)
jmp    11af <strncasecmp+0x9f>
jmp    1123 <strncasecmp+0x13>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strncasecmp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r13d
mov    %rsi,%r15
mov    %rdi,%r12
xor    %r14d,%r14d
xor    %ebp,%ebp
nopl   0x0(%rax)
test   %r13d,%r13d
jle    1169 <strncasecmp+0x59>
movsbl (%r12,%rbp,1),%edi
call   1030 <upcase@plt>
mov    %eax,%ebx
movsbl (%r15,%rbp,1),%edi
call   1030 <upcase@plt>
cmp    %al,%bl
jl     1163 <strncasecmp+0x53>
add    $0x1,%rbp
add    $0xffffffff,%r13d
cmp    %al,%bl
jle    1130 <strncasecmp+0x20>
mov    $0x1,%r14d
jmp    1169 <strncasecmp+0x59>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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