#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(char const);
int tolower(char const);
int strcasecmp(const char *s1, const char *s2) {
  for (size_t i = 0;; i++) {
    int d = tolower(s1[i]) - tolower(s2[i]);
    if (d || !s1[i])
      return d;
    assert(s2[i]);
  }
}


x86 assembly (clang, -O0):
<strcasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1183 <strcasecmp+0x63>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    118c <strcasecmp+0x6c>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <assert@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <strcasecmp+0x18>

x86 assembly (clang, -O2):
<strcasecmp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
movsbl (%rdi),%edi
call   1040 <tolower@plt>
mov    %eax,%ebp
movsbl (%r14),%edi
call   1040 <tolower@plt>
sub    %eax,%ebp
jne    1185 <strcasecmp+0x65>
mov    $0x1,%ebx
nopl   0x0(%rax)
cmpb   $0x0,-0x1(%r15,%rbx,1)
je     1183 <strcasecmp+0x63>
movsbl -0x1(%r14,%rbx,1),%edi
call   1030 <assert@plt>
movsbl (%r15,%rbx,1),%edi
call   1040 <tolower@plt>
mov    %eax,%ebp
movsbl (%r14,%rbx,1),%edi
call   1040 <tolower@plt>
add    $0x1,%rbx
sub    %eax,%ebp
je     1150 <strcasecmp+0x30>
jmp    1185 <strcasecmp+0x65>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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