#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 */
int towlower(int const);
int wcscasecmp(const wchar_t *s1, const wchar_t *s2) {
  size_t n = 0;
  for (;;) {
    wchar_t wc1 = towlower(s1[n]);
    wchar_t wc2 = towlower(s2[n]);
    if (wc1 != wc2)
      return (wc1 > wc2) ? +1 : -1;
    if (wc1 == L'\0')
      return 0;
    n++;
  }
}


x86 assembly (clang, -O0):
<wcscasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <towlower@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <towlower@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
je     1177 <wcscasecmp+0x67>
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%esi
mov    $0xffffffff,%eax
mov    $0x1,%ecx
cmp    %esi,%edx
cmovg  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    119e <wcscasecmp+0x8e>
cmpl   $0x0,-0x24(%rbp)
jne    118d <wcscasecmp+0x7d>
movl   $0x0,-0x4(%rbp)
jmp    119e <wcscasecmp+0x8e>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1128 <wcscasecmp+0x18>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcscasecmp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%edi
call   1030 <towlower@plt>
mov    %eax,%ebp
mov    (%r14),%edi
call   1030 <towlower@plt>
cmp    %eax,%ebp
jne    1160 <wcscasecmp+0x50>
mov    $0x4,%ebx
nopw   0x0(%rax,%rax,1)
test   %ebp,%ebp
je     116f <wcscasecmp+0x5f>
mov    (%r15,%rbx,1),%edi
call   1030 <towlower@plt>
mov    %eax,%ebp
mov    (%r14,%rbx,1),%edi
call   1030 <towlower@plt>
add    $0x4,%rbx
cmp    %eax,%ebp
je     1140 <wcscasecmp+0x30>
xor    %ecx,%ecx
cmp    %eax,%ebp
setg   %cl
lea    (%rcx,%rcx,1),%eax
add    $0xffffffff,%eax
jmp    1171 <wcscasecmp+0x61>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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