#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__ toupper(int /*<<< orphan*/);
int strncasecmp(const char *s1, const char *s2, unsigned int sz) {
  for (; sz > 0; sz--)
    if (toupper(s1++) != toupper(s2++))
      return 1;
  return 0;
}


x86 assembly (clang, -O0):
<strncasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jbe    118c <strncasecmp+0x7c>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    %eax,%edi
call   1030 <toupper@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    %eax,%edi
call   1030 <toupper@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     1179 <strncasecmp+0x69>
movl   $0x1,-0x4(%rbp)
jmp    1193 <strncasecmp+0x83>
jmp    117e <strncasecmp+0x6e>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1123 <strncasecmp+0x13>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strncasecmp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r14d,%r14d
test   %edx,%edx
je     115a <strncasecmp+0x4a>
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%rbp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <toupper@plt>
mov    %rax,%r12
mov    %ebx,%edi
call   1030 <toupper@plt>
cmp    %rax,%r12
jne    1154 <strncasecmp+0x44>
add    $0x1,%ebx
add    $0x1,%ebp
add    $0xffffffff,%r15d
jne    1130 <strncasecmp+0x20>
jmp    115a <strncasecmp+0x4a>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
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
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
br label %8
8: ; preds = %23, %3
%9 = load i32, i32* %7
%10 = icmp ugt i32 %9, 0
br i1 %10, label %11, label %26
11: ; preds = %8
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %5
%14 = ptrtoint i8* %12 to i32
%15 = call i64 @toupper(i32 %14)
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %6
%18 = ptrtoint i8* %16 to i32
%19 = call i64 @toupper(i32 %18)
%20 = icmp ne i64 %15, %19
br i1 %20, label %21, label %22
21: ; preds = %11
store i32 1, i32* %4
br label %27
22: ; preds = %11
br label %23
23: ; preds = %22
%24 = load i32, i32* %7
%25 = add i32 %24, -1
store i32 %25, i32* %7
br label %8
26: ; preds = %8
store i32 0, i32* %4
br label %27
27: ; preds = %26, %21
%28 = load i32, i32* %4
ret i32 %28
}

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