#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 *s1, const char *s2) {
  int result;
  while (1) {
    result = tolower(*s1) - tolower(*s2++);
    if ((result != 0) || (*s1++ == 0)) {
      break;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<strcasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1175 <strcasecmp+0x65>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    117a <strcasecmp+0x6a>
jmp    117f <strcasecmp+0x6f>
jmp    1120 <strcasecmp+0x10>
mov    -0x14(%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,%r15
xor    %ebx,%ebx
nop
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    1145 <strcasecmp+0x35>
cmpb   $0x0,(%r15,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1120 <strcasecmp+0x10>
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 i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
br label %6
6: ; preds = %2, %24
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = call i32 @tolower(i8 signext %8)
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %4
%12 = load i8, i8* %10
%13 = call i32 @tolower(i8 signext %12)
%14 = sub nsw i32 %9, %13
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %6
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %3
%20 = load i8, i8* %18
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17, %6
br label %25
24: ; preds = %17
br label %6
25: ; preds = %23
%26 = load i32, i32* %5
ret i32 %26
}

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