#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 wchar_t;

/* Variables and functions */
scalar_t__ towlower(int const);
size_t wcslen(int const *);
int Rwcsncasecmp(const wchar_t *cs1, const wchar_t *s2) {
  size_t i, n = wcslen(cs1);
  const wchar_t *a = cs1, *b = s2;
  for (i = 0; i < n; i++, a++, b++) {
    if (*b == L'\0' || towlower(*a) != towlower(*b))
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<Rwcsncasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <wcslen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11d4 <Rwcsncasecmp+0xb4>
mov    -0x38(%rbp),%rax
cmpl   $0x0,(%rax)
je     119a <Rwcsncasecmp+0x7a>
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
call   1040 <towlower@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%edi
call   1040 <towlower@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
je     11a6 <Rwcsncasecmp+0x86>
movl   $0x1,-0x4(%rbp)
jmp    11db <Rwcsncasecmp+0xbb>
jmp    11ab <Rwcsncasecmp+0x8b>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
jmp    1155 <Rwcsncasecmp+0x35>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Rwcsncasecmp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
call   1030 <wcslen@plt>
test   %rax,%rax
je     117a <Rwcsncasecmp+0x5a>
mov    %rax,%r15
xor    %ebp,%ebp
mov    $0x1,%r13d
cs nopw 0x0(%rax,%rax,1)
cmpl   $0x0,(%r12,%rbp,4)
je     117d <Rwcsncasecmp+0x5d>
mov    (%r14,%rbp,4),%edi
call   1040 <towlower@plt>
mov    %rax,%rbx
mov    (%r12,%rbp,4),%edi
call   1040 <towlower@plt>
cmp    %rax,%rbx
jne    117d <Rwcsncasecmp+0x5d>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1150 <Rwcsncasecmp+0x30>
xor    %r13d,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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