#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 */
unsigned char tolower(unsigned char);
int mystricmp(char *s1, char *s2) {
  unsigned char u1, u2;
  for (;;) {
    u1 = (unsigned char)*s1++;
    u1 = tolower(u1);
    u2 = (unsigned char)*s2++;
    u2 = tolower(u2);
    if (u1 != u2)
      return u1 - u2;
    if (u1 == '\0')
      return 0;
  }
}


x86 assembly (clang, -O0):
<mystricmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%edi
call   1030 <tolower@plt>
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x1a(%rbp)
movzbl -0x1a(%rbp),%edi
call   1030 <tolower@plt>
mov    %al,-0x1a(%rbp)
movzbl -0x19(%rbp),%eax
movzbl -0x1a(%rbp),%ecx
cmp    %ecx,%eax
je     1182 <mystricmp+0x72>
movzbl -0x19(%rbp),%eax
movzbl -0x1a(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11a0 <mystricmp+0x90>
movzbl -0x19(%rbp),%eax
cmp    $0x0,%eax
jne    119b <mystricmp+0x8b>
movl   $0x0,-0x4(%rbp)
jmp    11a0 <mystricmp+0x90>
jmp    1120 <mystricmp+0x10>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mystricmp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
nop
movzbl (%r15,%rbx,1),%edi
call   1030 <tolower@plt>
mov    %eax,%ebp
movzbl (%r14,%rbx,1),%edi
call   1030 <tolower@plt>
cmp    %al,%bpl
jne    1148 <mystricmp+0x38>
add    $0x1,%rbx
test   %bpl,%bpl
jne    1120 <mystricmp+0x10>
xor    %eax,%eax
jmp    1153 <mystricmp+0x43>
mov    %eax,%ecx
movzbl %bpl,%eax
movzbl %cl,%ecx
sub    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mystricmp(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 = %35, %2
%9 = load i8*, i8** %4
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %4
%11 = load i8, i8* %9
store i8 %11, i8* %6
%12 = load i8, i8* %6
%13 = call zeroext i8 @tolower(i8 zeroext %12)
store i8 %13, i8* %6
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %5
%16 = load i8, i8* %14
store i8 %16, i8* %7
%17 = load i8, i8* %7
%18 = call zeroext i8 @tolower(i8 zeroext %17)
store i8 %18, i8* %7
%19 = load i8, i8* %6
%20 = zext i8 %19 to i32
%21 = load i8, i8* %7
%22 = zext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br i1 %23, label %24, label %30
24: ; preds = %8
%25 = load i8, i8* %6
%26 = zext i8 %25 to i32
%27 = load i8, i8* %7
%28 = zext i8 %27 to i32
%29 = sub nsw i32 %26, %28
store i32 %29, i32* %3
br label %36
30: ; preds = %8
%31 = load i8, i8* %6
%32 = zext i8 %31 to i32
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 0, i32* %3
br label %36
35: ; preds = %30
br label %8
36: ; preds = %34, %24
%37 = load i32, i32* %3
ret i32 %37
}

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