#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 strcmp_insensitive(const char *s, const char *t) {
  size_t i;
  for (i = 0; toupper(s[i]) == toupper(t[i]); i++) {
    if (s[i] == '\0')
      return 0;
  }
  return toupper(s[i]) - toupper(t[i]);
}


x86 assembly (clang, -O0):
<strcmp_insensitive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jne    1191 <strcmp_insensitive+0x81>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    117b <strcmp_insensitive+0x6b>
movl   $0x0,-0x4(%rbp)
jmp    11c0 <strcmp_insensitive+0xb0>
jmp    1180 <strcmp_insensitive+0x70>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1128 <strcmp_insensitive+0x18>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcmp_insensitive>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
movsbl (%rdi),%edi
call   1030 <toupper@plt>
mov    %eax,%ebp
movsbl (%r14),%edi
call   1030 <toupper@plt>
cmp    %eax,%ebp
jne    1171 <strcmp_insensitive+0x61>
xor    %r15d,%r15d
xor    %ebx,%ebx
nopl   (%rax)
cmpb   $0x0,(%r12,%rbx,1)
je     118d <strcmp_insensitive+0x7d>
lea    0x1(%rbx),%rbp
movsbl 0x1(%r12,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %eax,%r13d
movsbl 0x1(%r14,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %rbp,%rbx
cmp    %eax,%r13d
je     1140 <strcmp_insensitive+0x30>
add    %rbp,%r12
jmp    1173 <strcmp_insensitive+0x63>
xor    %ebp,%ebp
movsbl (%r12),%edi
call   1030 <toupper@plt>
mov    %eax,%r15d
movsbl (%r14,%rbp,1),%edi
call   1030 <toupper@plt>
sub    %eax,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @strcmp_insensitive(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 %22
8: ; preds = %2, %13
%9 = phi i8* [ %15, %13 ], [ %0, %2 ]
%10 = phi i64 [ %14, %13 ], [ 0, %2 ]
%11 = load i8, i8* %9
%12 = icmp eq i8 %11, 0
br i1 %12, label %31, label %13
13: ; preds = %8
%14 = add i64 %10, 1
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = tail call i32 @toupper(i8 signext %16)
%18 = getelementptr inbounds i8, i8* %1, i64 %14
%19 = load i8, i8* %18
%20 = tail call i32 @toupper(i8 signext %19)
%21 = icmp eq i32 %17, %20
br i1 %21, label %8, label %22
22: ; preds = %13, %2
%23 = phi i64 [ 0, %2 ], [ %14, %13 ]
%24 = phi i8* [ %0, %2 ], [ %15, %13 ]
%25 = getelementptr inbounds i8, i8* %1, i64 %23
%26 = load i8, i8* %24
%27 = tail call i32 @toupper(i8 signext %26)
%28 = load i8, i8* %25
%29 = tail call i32 @toupper(i8 signext %28)
%30 = sub nsw i32 %27, %29
br label %31
31: ; preds = %8, %22
%32 = phi i32 [ %30, %22 ], [ 0, %8 ]
ret i32 %32
}