#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 */
scalar_t__ tolower(unsigned long);
int stricmp(const char *str1, const char *str2) {
  const unsigned char *p1 = (unsigned char *)str1 - 1;
  const unsigned char *p2 = (unsigned char *)str2 - 1;
  unsigned long c1, c2;
  while (tolower(c1 = *++p1) == tolower(c2 = *++p2)) {
    if (!c1) {
      return 0;
    }
  }
  return c1 - c2;
}


x86 assembly (clang, -O0):
<stricmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movzbl 0x1(%rax),%eax
mov    %eax,%edi
mov    %rdi,-0x30(%rbp)
call   1030 <tolower@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movzbl 0x1(%rax),%eax
mov    %eax,%edi
mov    %rdi,-0x38(%rbp)
call   1030 <tolower@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jne    11a4 <stricmp+0x94>
cmpq   $0x0,-0x30(%rbp)
jne    119f <stricmp+0x8f>
movl   $0x0,-0x4(%rbp)
jmp    11af <stricmp+0x9f>
jmp    1138 <stricmp+0x28>
mov    -0x30(%rbp),%rax
sub    -0x38(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stricmp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r15,%rbp,1),%r12d
mov    %r12,%rdi
call   1030 <tolower@plt>
mov    %rax,%r13
movzbl (%r14,%rbp,1),%ebx
mov    %rbx,%rdi
call   1030 <tolower@plt>
cmp    %rax,%r13
jne    1160 <stricmp+0x50>
add    $0x1,%rbp
test   %r12d,%r12d
jne    1130 <stricmp+0x20>
xor    %r12d,%r12d
jmp    1163 <stricmp+0x53>
sub    %ebx,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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