#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 (*a || *b) {
    int ca = toupper(*a);
    int cb = toupper(*b);
    if (ca < cb)
      return (-1);
    if (ca > cb)
      return (1);
    ++a;
    ++b;
  }
  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
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
jne    1145 <strcasecmp+0x35>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1155 <strcasecmp+0x45>
jmp    11c0 <strcasecmp+0xb0>
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,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    118b <strcasecmp+0x7b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <strcasecmp+0xb7>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    11a3 <strcasecmp+0x93>
movl   $0x1,-0x4(%rbp)
jmp    11c7 <strcasecmp+0xb7>
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>
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     115e <strcasecmp+0x4e>
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %eax,%ebp
movsbl (%r15,%rbx,1),%edi
call   1030 <toupper@plt>
cmp    %eax,%ebp
jl     1150 <strcasecmp+0x40>
jg     1157 <strcasecmp+0x47>
add    $0x1,%rbx
jmp    1120 <strcasecmp+0x10>
mov    $0xffffffff,%eax
jmp    1160 <strcasecmp+0x50>
mov    $0x1,%eax
jmp    1160 <strcasecmp+0x50>
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 i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
br label %8
8: ; preds = %36, %2
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %8
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br label %18
18: ; preds = %13, %8
%19 = phi i1 [ true, %8 ], [ %17, %13 ]
br i1 %19, label %20, label %41
20: ; preds = %18
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = call i32 @toupper(i8 signext %22)
store i32 %23, i32* %6
%24 = load i8*, i8** %5
%25 = load i8, i8* %24
%26 = call i32 @toupper(i8 signext %25)
store i32 %26, i32* %7
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %20
store i32 -1, i32* %3
br label %42
31: ; preds = %20
%32 = load i32, i32* %6
%33 = load i32, i32* %7
%34 = icmp sgt i32 %32, %33
br i1 %34, label %35, label %36
35: ; preds = %31
store i32 1, i32* %3
br label %42
36: ; preds = %31
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %4
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %5
br label %8
41: ; preds = %18
store i32 0, i32* %3
br label %42
42: ; preds = %41, %35, %30
%43 = load i32, i32* %3
ret i32 %43
}

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 i32 @toupper(i8 signext %6)
%13 = load i8, i8* %4
%14 = tail call i32 @toupper(i8 signext %13)
%15 = icmp slt i32 %12, %14
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = icmp sgt i32 %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
}