#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 */
unsigned char tolower(unsigned char const);
int strcasecmp(const char *str1, const char *str2) {
  const unsigned char *s1 = (const unsigned char *)str1;
  const unsigned char *s2 = (const unsigned char *)str2;
  while (*s1 || *s2) {
    unsigned char c1 = tolower(*s1);
    unsigned char c2 = tolower(*s2);
    if (c1 < c2) {
      return -1;
    } else if (c1 > c2) {
      return 1;
    }
    s1++;
    s2++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<strcasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movzbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x2b(%rbp)
jne    1155 <strcasecmp+0x45>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x2b(%rbp)
mov    -0x2b(%rbp),%al
test   $0x1,%al
jne    1165 <strcasecmp+0x55>
jmp    11dd <strcasecmp+0xcd>
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   1030 <tolower@plt>
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rax
movzbl (%rax),%edi
call   1030 <tolower@plt>
mov    %al,-0x2a(%rbp)
movzbl -0x29(%rbp),%eax
movzbl -0x2a(%rbp),%ecx
cmp    %ecx,%eax
jge    119f <strcasecmp+0x8f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <strcasecmp+0xd4>
movzbl -0x29(%rbp),%eax
movzbl -0x2a(%rbp),%ecx
cmp    %ecx,%eax
jle    11bb <strcasecmp+0xab>
movl   $0x1,-0x4(%rbp)
jmp    11e4 <strcasecmp+0xd4>
jmp    11c0 <strcasecmp+0xb0>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1130 <strcasecmp+0x20>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcasecmp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
nop
movzbl (%r14,%rbx,1),%eax
test   %al,%al
jne    1130 <strcasecmp+0x20>
cmpb   $0x0,(%r15,%rbx,1)
je     115f <strcasecmp+0x4f>
movzbl %al,%edi
call   1030 <tolower@plt>
mov    %eax,%ebp
movzbl (%r15,%rbx,1),%edi
call   1030 <tolower@plt>
cmp    %al,%bpl
jb     1151 <strcasecmp+0x41>
ja     1158 <strcasecmp+0x48>
add    $0x1,%rbx
jmp    1120 <strcasecmp+0x10>
mov    $0xffffffff,%eax
jmp    1161 <strcasecmp+0x51>
mov    $0x1,%eax
jmp    1161 <strcasecmp+0x51>
xor    %eax,%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 i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
store i8* %10, i8** %6
%11 = load i8*, i8** %5
store i8* %11, i8** %7
br label %12
12: ; preds = %45, %2
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = load i8*, i8** %7
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br label %22
22: ; preds = %17, %12
%23 = phi i1 [ true, %12 ], [ %21, %17 ]
br i1 %23, label %24, label %50
24: ; preds = %22
%25 = load i8*, i8** %6
%26 = load i8, i8* %25
%27 = call zeroext i8 @tolower(i8 zeroext %26)
store i8 %27, i8* %8
%28 = load i8*, i8** %7
%29 = load i8, i8* %28
%30 = call zeroext i8 @tolower(i8 zeroext %29)
store i8 %30, i8* %9
%31 = load i8, i8* %8
%32 = zext i8 %31 to i32
%33 = load i8, i8* %9
%34 = zext i8 %33 to i32
%35 = icmp slt i32 %32, %34
br i1 %35, label %36, label %37
36: ; preds = %24
store i32 -1, i32* %3
br label %51
37: ; preds = %24
%38 = load i8, i8* %8
%39 = zext i8 %38 to i32
%40 = load i8, i8* %9
%41 = zext i8 %40 to i32
%42 = icmp sgt i32 %39, %41
br i1 %42, label %43, label %44
43: ; preds = %37
store i32 1, i32* %3
br label %51
44: ; preds = %37
br label %45
45: ; preds = %44
%46 = load i8*, i8** %6
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %6
%48 = load i8*, i8** %7
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %7
br label %12
50: ; preds = %22
store i32 0, i32* %3
br label %51
51: ; preds = %50, %43, %36
%52 = load i32, i32* %3
ret i32 %52
}

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