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


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
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jne    117e <strcasecmp+0x6e>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1161 <strcasecmp+0x51>
movl   $0x0,-0x4(%rbp)
jmp    11a3 <strcasecmp+0x93>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1120 <strcasecmp+0x10>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%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
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <toupper@plt>
mov    %eax,%ebp
movsbl (%r14),%edi
call   1030 <toupper@plt>
cmp    %eax,%ebp
jne    116d <strcasecmp+0x5d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x0,(%rbx)
je     1187 <strcasecmp+0x77>
lea    0x1(%r14),%rbp
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <toupper@plt>
mov    %eax,%r15d
movsbl 0x1(%r14),%edi
call   1030 <toupper@plt>
mov    %rbp,%r14
cmp    %eax,%r15d
je     1140 <strcasecmp+0x30>
jmp    1170 <strcasecmp+0x60>
mov    %r14,%rbp
movsbl (%rbx),%edi
call   1030 <toupper@plt>
mov    %eax,%ebx
movsbl 0x0(%rbp),%edi
call   1030 <toupper@plt>
sub    %eax,%ebx
jmp    1189 <strcasecmp+0x79>
xor    %ebx,%ebx
mov    %ebx,%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*
store i8* %0, i8** %4
store i8* %1, i8** %5
br label %6
6: ; preds = %19, %2
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = call i32 @toupper(i8 signext %8)
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = call i32 @toupper(i8 signext %11)
%13 = icmp eq i32 %9, %12
br i1 %13, label %14, label %24
14: ; preds = %6
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %14
store i32 0, i32* %3
br label %32
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %5
br label %6
24: ; preds = %6
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = call i32 @toupper(i8 signext %26)
%28 = load i8*, i8** %5
%29 = load i8, i8* %28
%30 = call i32 @toupper(i8 signext %29)
%31 = sub nsw i32 %27, %30
store i32 %31, i32* %3
br label %32
32: ; preds = %24, %18
%33 = load i32, i32* %3
ret i32 %33
}

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