#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 */
typedef int /*<<< orphan*/ wchar_t;

/* Variables and functions */
int towlower(int /*<<< orphan*/);
int wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n) {
  int d = 0;
  for (; n != 0; n--) {
    const int c1 = towlower(*s1++);
    const int c2 = towlower(*s2++);
    if (((d = c1 - c2) != 0) || (c2 == '\0'))
      break;
  }
  return d;
}


x86 assembly (clang, -O0):
<wcsncasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119f <wcsncasecmp+0x8f>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%edi
call   1030 <towlower@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%edi
call   1030 <towlower@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    1184 <wcsncasecmp+0x74>
cmpl   $0x0,-0x24(%rbp)
jne    1189 <wcsncasecmp+0x79>
jmp    119f <wcsncasecmp+0x8f>
jmp    118e <wcsncasecmp+0x7e>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    112b <wcsncasecmp+0x1b>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcsncasecmp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdx,%rdx
je     1157 <wcsncasecmp+0x47>
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%edi
call   1030 <towlower@plt>
mov    %eax,%ebp
mov    (%r14,%rbx,4),%edi
call   1030 <towlower@plt>
sub    %eax,%ebp
test   %eax,%eax
je     1159 <wcsncasecmp+0x49>
test   %ebp,%ebp
jne    1159 <wcsncasecmp+0x49>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <wcsncasecmp+0x20>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @wcsncasecmp(i32* %0, i32* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i64 %2, i64* %6
store i32 0, i32* %7
br label %10
10: ; preds = %31, %3
%11 = load i64, i64* %6
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %34
13: ; preds = %10
%14 = load i32*, i32** %4
%15 = getelementptr inbounds i32, i32* %14, i32 1
store i32* %15, i32** %4
%16 = load i32, i32* %14
%17 = call i32 @towlower(i32 %16)
store i32 %17, i32* %8
%18 = load i32*, i32** %5
%19 = getelementptr inbounds i32, i32* %18, i32 1
store i32* %19, i32** %5
%20 = load i32, i32* %18
%21 = call i32 @towlower(i32 %20)
store i32 %21, i32* %9
%22 = load i32, i32* %8
%23 = load i32, i32* %9
%24 = sub nsw i32 %22, %23
store i32 %24, i32* %7
%25 = icmp ne i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %13
%27 = load i32, i32* %9
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26, %13
br label %34
30: ; preds = %26
br label %31
31: ; preds = %30
%32 = load i64, i64* %6
%33 = add i64 %32, -1
store i64 %33, i64* %6
br label %10
34: ; preds = %29, %10
%35 = load i32, i32* %7
ret i32 %35
}

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