#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(int);
int xstrcasecmp(const char *s1, const char *s2) {
  const char *p, *q;
  p = s1;
  q = s2;
  while (*p && toupper((int)*p) == toupper((int)*q))
    p++, q++;
  return (toupper((int)*p) - toupper((int)*q));
}


x86 assembly (clang, -O0):
<xstrcasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     116d <xstrcasecmp+0x5d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    117d <xstrcasecmp+0x6d>
jmp    119a <xstrcasecmp+0x8a>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1130 <xstrcasecmp+0x20>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
sub    %ecx,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstrcasecmp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    (%rdi),%bpl
test   %bpl,%bpl
je     115a <xstrcasecmp+0x4a>
mov    %rdi,%rbx
add    $0x1,%rbx
nopl   0x0(%rax)
movsbl %bpl,%edi
call   1030 <toupper@plt>
mov    %eax,%r15d
movsbl (%r14),%edi
call   1030 <toupper@plt>
cmp    %eax,%r15d
jne    115c <xstrcasecmp+0x4c>
add    $0x1,%r14
movzbl (%rbx),%ebp
add    $0x1,%rbx
test   %bpl,%bpl
jne    1130 <xstrcasecmp+0x20>
xor    %ebp,%ebp
movsbl %bpl,%edi
call   1030 <toupper@plt>
mov    %eax,%ebx
movsbl (%r14),%edi
call   1030 <toupper@plt>
sub    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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