#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 tolower(char const);
int strcasecmp(const char *a, const char *b) {
  int r;
  if (a == b)
    return 0;
  while ((r = tolower(*a) - tolower(*b++)) == 0) {
    if (*a++ == '\0')
      break;
  }
  return r;
}


x86 assembly (clang, -O0):
<strcasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    113a <strcasecmp+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    11a3 <strcasecmp+0x93>
jmp    113f <strcasecmp+0x2f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    119d <strcasecmp+0x8d>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1198 <strcasecmp+0x88>
jmp    119d <strcasecmp+0x8d>
jmp    113f <strcasecmp+0x2f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcasecmp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    %rsi,%rdi
je     1155 <strcasecmp+0x45>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%r15,%rbx,1),%edi
call   1030 <tolower@plt>
mov    %eax,%ebp
movsbl (%r14,%rbx,1),%edi
call   1030 <tolower@plt>
sub    %eax,%ebp
jne    1157 <strcasecmp+0x47>
cmpb   $0x0,(%r15,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1130 <strcasecmp+0x20>
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 i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = load i8*, i8** %5
%9 = icmp eq i8* %7, %8
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %3
br label %32
11: ; preds = %2
br label %12
12: ; preds = %29, %11
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = call i32 @tolower(i8 signext %14)
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %5
%18 = load i8, i8* %16
%19 = call i32 @tolower(i8 signext %18)
%20 = sub nsw i32 %15, %19
store i32 %20, i32* %6
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %12
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
%25 = load i8, i8* %23
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22
br label %30
29: ; preds = %22
br label %12
30: ; preds = %28, %12
%31 = load i32, i32* %6
store i32 %31, i32* %3
br label %32
32: ; preds = %30, %10
%33 = load i32, i32* %3
ret i32 %33
}

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