#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 /*<<< orphan*/ assert(int /*<<< orphan*/ const *);
int towlower(int /*<<< orphan*/ const);
int wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n) {
  int lc1 = 0;
  int lc2 = 0;
  int diff = 0;
  assert(s1);
  assert(s2);
  while (n--) {
    lc1 = towlower(*s1);
    lc2 = towlower(*s2);
    diff = lc1 - lc2;
    if (diff)
      return diff;
    if (!lc1)
      return 0;
    ++s1;
    ++s2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<wcsncasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
je     11e1 <wcsncasecmp+0xc1>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <towlower@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1040 <towlower@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
sub    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11ae <wcsncasecmp+0x8e>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e8 <wcsncasecmp+0xc8>
cmpl   $0x0,-0x24(%rbp)
jne    11c4 <wcsncasecmp+0xa4>
movl   $0x0,-0x4(%rbp)
jmp    11e8 <wcsncasecmp+0xc8>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    115b <wcsncasecmp+0x3b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcsncasecmp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <assert@plt>
mov    %r14,%rdi
call   1030 <assert@plt>
test   %r12,%r12
je     1180 <wcsncasecmp+0x60>
add    $0xffffffffffffffff,%r12
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r15,%rbx,4),%edi
call   1040 <towlower@plt>
mov    %eax,%ebp
mov    (%r14,%rbx,4),%edi
call   1040 <towlower@plt>
mov    %eax,%ecx
mov    %ebp,%eax
sub    %ecx,%eax
jne    1182 <wcsncasecmp+0x62>
xor    %eax,%eax
test   %ebp,%ebp
je     1182 <wcsncasecmp+0x62>
lea    0x1(%rbx),%rcx
cmp    %rbx,%r12
mov    %rcx,%rbx
jne    1150 <wcsncasecmp+0x30>
jmp    1182 <wcsncasecmp+0x62>
xor    %eax,%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 i32*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i64 %2, i64* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%11 = load i32*, i32** %5
%12 = call i32 @assert(i32* %11)
%13 = load i32*, i32** %6
%14 = call i32 @assert(i32* %13)
br label %15
15: ; preds = %37, %3
%16 = load i64, i64* %7
%17 = add i64 %16, -1
store i64 %17, i64* %7
%18 = icmp ne i64 %16, 0
br i1 %18, label %19, label %42
19: ; preds = %15
%20 = load i32*, i32** %5
%21 = load i32, i32* %20
%22 = call i32 @towlower(i32 %21)
store i32 %22, i32* %8
%23 = load i32*, i32** %6
%24 = load i32, i32* %23
%25 = call i32 @towlower(i32 %24)
store i32 %25, i32* %9
%26 = load i32, i32* %8
%27 = load i32, i32* %9
%28 = sub nsw i32 %26, %27
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %19
%32 = load i32, i32* %10
store i32 %32, i32* %4
br label %43
33: ; preds = %19
%34 = load i32, i32* %8
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %33
store i32 0, i32* %4
br label %43
37: ; preds = %33
%38 = load i32*, i32** %5
%39 = getelementptr inbounds i32, i32* %38, i32 1
store i32* %39, i32** %5
%40 = load i32*, i32** %6
%41 = getelementptr inbounds i32, i32* %40, i32 1
store i32* %41, i32** %6
br label %15
42: ; preds = %15
store i32 0, i32* %4
br label %43
43: ; preds = %42, %36, %31
%44 = load i32, i32* %4
ret i32 %44
}

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