#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(unsigned char);
int tolower(unsigned char);
int strcasecmp(const char *s1, const char *s2) {
  for (size_t i = 0;; i++) {
    unsigned char c1 = s1[i], c2 = s2[i];
    int d = tolower(c1) - tolower(c2);
    if (d || !c1)
      return d;
    assert(c2);
  }
}


x86 assembly (clang, -O0):
<strcasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1a(%rbp)
movzbl -0x19(%rbp),%edi
call   1040 <tolower@plt>
mov    %eax,-0x24(%rbp)
movzbl -0x1a(%rbp),%edi
call   1040 <tolower@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1187 <strcasecmp+0x67>
cmpb   $0x0,-0x19(%rbp)
jne    1190 <strcasecmp+0x70>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret
movzbl -0x1a(%rbp),%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   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
movzbl (%rdi),%r15d
mov    (%rsi),%r13b
mov    %r15d,%edi
call   1040 <tolower@plt>
mov    %eax,%ebp
movzbl %r13b,%edi
call   1040 <tolower@plt>
sub    %eax,%ebp
test   %r15d,%r15d
je     1195 <strcasecmp+0x75>
test   %ebp,%ebp
jne    1195 <strcasecmp+0x75>
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
movzbl %r13b,%edi
call   1030 <assert@plt>
movzbl (%r12,%rbx,1),%r15d
movzbl (%r14,%rbx,1),%r13d
mov    %r15d,%edi
call   1040 <tolower@plt>
mov    %eax,%ebp
movzbl %r13b,%edi
call   1040 <tolower@plt>
sub    %eax,%ebp
test   %r15d,%r15d
je     1195 <strcasecmp+0x75>
add    $0x1,%rbx
test   %ebp,%ebp
je     1160 <strcasecmp+0x40>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 i8
%7 = alloca i8
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i64 0, i64* %5
br label %9
9: ; preds = %33, %2
%10 = load i8*, i8** %3
%11 = load i64, i64* %5
%12 = getelementptr inbounds i8, i8* %10, i64 %11
%13 = load i8, i8* %12
store i8 %13, i8* %6
%14 = load i8*, i8** %4
%15 = load i64, i64* %5
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %7
%18 = load i8, i8* %6
%19 = call i32 @tolower(i8 zeroext %18)
%20 = load i8, i8* %7
%21 = call i32 @tolower(i8 zeroext %20)
%22 = sub nsw i32 %19, %21
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = icmp ne i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %9
%26 = load i8, i8* %6
%27 = icmp ne i8 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %25, %9
%29 = load i32, i32* %8
ret i32 %29
30: ; preds = %25
%31 = load i8, i8* %7
%32 = call i32 @assert(i8 zeroext %31)
br label %33
33: ; preds = %30
%34 = load i64, i64* %5
%35 = add i64 %34, 1
store i64 %35, i64* %5
br label %9
}

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