#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 */
struct __locale_t {
  int dummy;
};

/* Variables and functions */
int tolower_l(int /*<<< orphan*/, struct __locale_t *);
int strcasecmp_l(const char *s1, const char *s2, struct __locale_t *locale) {
  int d = 0;
  for (;;) {
    const int c1 = tolower_l(*s1++, locale);
    const int c2 = tolower_l(*s2++, locale);
    if (((d = c1 - c2) != 0) || (c2 == '\0'))
      break;
  }
  return d;
}


x86 assembly (clang, -O0):
<strcasecmp_l>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
mov    -0x18(%rbp),%rsi
call   1030 <tolower_l@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
mov    -0x18(%rbp),%rsi
call   1030 <tolower_l@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    1183 <strcasecmp_l+0x73>
cmpl   $0x0,-0x24(%rbp)
jne    1188 <strcasecmp_l+0x78>
jmp    118d <strcasecmp_l+0x7d>
jmp    112b <strcasecmp_l+0x1b>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcasecmp_l>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%r15,%rbx,1),%edi
mov    %r12,%rsi
call   1030 <tolower_l@plt>
mov    %eax,%ebp
movsbl (%r14,%rbx,1),%edi
mov    %r12,%rsi
call   1030 <tolower_l@plt>
sub    %eax,%ebp
test   %eax,%eax
je     115a <strcasecmp_l+0x4a>
add    $0x1,%rbx
test   %ebp,%ebp
je     1130 <strcasecmp_l+0x20>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.__locale_t = type { i32 }
define i32 @strcasecmp_l(i8* nocapture %0, i8* nocapture %1, %struct.__locale_t* %2) {
br label %4
4: ; preds = %4, %3
%5 = phi i8* [ %1, %3 ], [ %11, %4 ]
%6 = phi i8* [ %0, %3 ], [ %7, %4 ]
%7 = getelementptr inbounds i8, i8* %6, i64 1
%8 = load i8, i8* %6
%9 = sext i8 %8 to i32
%10 = tail call i32 @tolower_l(i32 %9, %struct.__locale_t* %2)
%11 = getelementptr inbounds i8, i8* %5, i64 1
%12 = load i8, i8* %5
%13 = sext i8 %12 to i32
%14 = tail call i32 @tolower_l(i32 %13, %struct.__locale_t* %2)
%15 = sub nsw i32 %10, %14
%16 = icmp ne i32 %15, 0
%17 = icmp eq i32 %14, 0
%18 = or i1 %17, %16
br i1 %18, label %19, label %4
19: ; preds = %4
ret i32 %15
}