#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 */
char toupper(char const);
int fits_strcasecmp(const char *s1, const char *s2) {
  char c1, c2;
  for (;;) {
    c1 = toupper(*s1);
    c2 = toupper(*s2);
    if (c1 < c2)
      return (-1);
    if (c1 > c2)
      return (1);
    if (c1 == 0)
      return (0);
    s1++;
    s2++;
  }
}


x86 assembly (clang, -O0):
<fits_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    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,-0x1a(%rbp)
movsbl -0x19(%rbp),%eax
movsbl -0x1a(%rbp),%ecx
cmp    %ecx,%eax
jge    115a <fits_strcasecmp+0x4a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <fits_strcasecmp+0x9c>
movsbl -0x19(%rbp),%eax
movsbl -0x1a(%rbp),%ecx
cmp    %ecx,%eax
jle    1176 <fits_strcasecmp+0x66>
movl   $0x1,-0x4(%rbp)
jmp    11ac <fits_strcasecmp+0x9c>
movsbl -0x19(%rbp),%eax
cmp    $0x0,%eax
jne    118f <fits_strcasecmp+0x7f>
movl   $0x0,-0x4(%rbp)
jmp    11ac <fits_strcasecmp+0x9c>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1120 <fits_strcasecmp+0x10>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fits_strcasecmp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
movsbl (%rdi),%edi
call   1030 <toupper@plt>
mov    %eax,%ebx
movsbl (%r14),%edi
call   1030 <toupper@plt>
mov    $0xffffffff,%r15d
cmp    %al,%bl
jl     1173 <fits_strcasecmp+0x63>
mov    $0x1,%ebp
cmp    %al,%bl
jg     1168 <fits_strcasecmp+0x58>
test   %bl,%bl
je     1170 <fits_strcasecmp+0x60>
movsbl (%r12,%rbp,1),%edi
call   1030 <toupper@plt>
mov    %eax,%ebx
movsbl (%r14,%rbp,1),%edi
call   1030 <toupper@plt>
add    $0x1,%rbp
cmp    %al,%bl
jge    1140 <fits_strcasecmp+0x30>
jmp    1173 <fits_strcasecmp+0x63>
mov    $0x1,%r15d
jmp    1173 <fits_strcasecmp+0x63>
xor    %r15d,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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