#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 const);
int _pd_strcasecmp(const unsigned char *lhs, const unsigned char *rhs) {
  for (;;) {
    unsigned char lhsc = tolower(*lhs);
    unsigned char rhsc = tolower(*rhs);
    if ((!lhsc || lhsc == '\t') && (!rhsc || rhsc == '\t'))
      return 0;
    if (!lhsc || lhsc == '\t')
      return -1;
    if (!rhsc || rhsc == '\t')
      return 1;
    if (lhsc < rhsc)
      return -1;
    if (lhsc > rhsc)
      return 1;
    lhs++;
    rhs++;
  }
}


x86 assembly (clang, -O0):
<_pd_strcasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1030 <tolower@plt>
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1030 <tolower@plt>
mov    %al,-0x1a(%rbp)
cmpb   $0x0,-0x19(%rbp)
je     1155 <_pd_strcasecmp+0x45>
movzbl -0x19(%rbp),%eax
cmp    $0x9,%eax
jne    1178 <_pd_strcasecmp+0x68>
cmpb   $0x0,-0x1a(%rbp)
je     116c <_pd_strcasecmp+0x5c>
movzbl -0x1a(%rbp),%eax
cmp    $0x9,%eax
jne    1178 <_pd_strcasecmp+0x68>
movl   $0x0,-0x4(%rbp)
jmp    1213 <_pd_strcasecmp+0x103>
cmpb   $0x0,-0x19(%rbp)
je     118f <_pd_strcasecmp+0x7f>
movzbl -0x19(%rbp),%eax
cmp    $0x9,%eax
jne    119b <_pd_strcasecmp+0x8b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1213 <_pd_strcasecmp+0x103>
cmpb   $0x0,-0x1a(%rbp)
je     11b2 <_pd_strcasecmp+0xa2>
movzbl -0x1a(%rbp),%eax
cmp    $0x9,%eax
jne    11be <_pd_strcasecmp+0xae>
movl   $0x1,-0x4(%rbp)
jmp    1213 <_pd_strcasecmp+0x103>
movzbl -0x19(%rbp),%eax
movzbl -0x1a(%rbp),%ecx
cmp    %ecx,%eax
jge    11da <_pd_strcasecmp+0xca>
movl   $0xffffffff,-0x4(%rbp)
jmp    1213 <_pd_strcasecmp+0x103>
movzbl -0x19(%rbp),%eax
movzbl -0x1a(%rbp),%ecx
cmp    %ecx,%eax
jle    11f6 <_pd_strcasecmp+0xe6>
movl   $0x1,-0x4(%rbp)
jmp    1213 <_pd_strcasecmp+0x103>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1120 <_pd_strcasecmp+0x10>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_pd_strcasecmp>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%r12,1),%edi
call   1030 <tolower@plt>
mov    %eax,%ebx
movzbl (%r14,%r12,1),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
cmp    $0x9,%bl
je     1151 <_pd_strcasecmp+0x41>
test   %bl,%bl
jne    116a <_pd_strcasecmp+0x5a>
xor    %eax,%eax
test   %cl,%cl
je     1189 <_pd_strcasecmp+0x79>
cmp    $0x9,%cl
je     1189 <_pd_strcasecmp+0x79>
mov    $0xffffffff,%eax
test   %bl,%bl
je     1189 <_pd_strcasecmp+0x79>
cmp    $0x9,%bl
je     1189 <_pd_strcasecmp+0x79>
mov    $0x1,%eax
test   %cl,%cl
je     1189 <_pd_strcasecmp+0x79>
cmp    $0x9,%cl
je     1189 <_pd_strcasecmp+0x79>
cmp    %cl,%bl
jb     1184 <_pd_strcasecmp+0x74>
ja     1189 <_pd_strcasecmp+0x79>
add    $0x1,%r12
jmp    1130 <_pd_strcasecmp+0x20>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @_pd_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 = %59, %2
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = call zeroext i8 @tolower(i8 zeroext %10)
store i8 %11, i8* %6
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = call zeroext i8 @tolower(i8 zeroext %13)
store i8 %14, i8* %7
%15 = load i8, i8* %6
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %8
%18 = load i8, i8* %6
%19 = zext i8 %18 to i32
%20 = icmp eq i32 %19, 9
br i1 %20, label %21, label %29
21: ; preds = %17, %8
%22 = load i8, i8* %7
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i8, i8* %7
%26 = zext i8 %25 to i32
%27 = icmp eq i32 %26, 9
br i1 %27, label %28, label %29
28: ; preds = %24, %21
store i32 0, i32* %3
br label %64
29: ; preds = %24, %17
%30 = load i8, i8* %6
%31 = icmp ne i8 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i8, i8* %6
%34 = zext i8 %33 to i32
%35 = icmp eq i32 %34, 9
br i1 %35, label %36, label %37
36: ; preds = %32, %29
store i32 -1, i32* %3
br label %64
37: ; preds = %32
%38 = load i8, i8* %7
%39 = icmp ne i8 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = load i8, i8* %7
%42 = zext i8 %41 to i32
%43 = icmp eq i32 %42, 9
br i1 %43, label %44, label %45
44: ; preds = %40, %37
store i32 1, i32* %3
br label %64
45: ; preds = %40
%46 = load i8, i8* %6
%47 = zext i8 %46 to i32
%48 = load i8, i8* %7
%49 = zext i8 %48 to i32
%50 = icmp slt i32 %47, %49
br i1 %50, label %51, label %52
51: ; preds = %45
store i32 -1, i32* %3
br label %64
52: ; preds = %45
%53 = load i8, i8* %6
%54 = zext i8 %53 to i32
%55 = load i8, i8* %7
%56 = zext i8 %55 to i32
%57 = icmp sgt i32 %54, %56
br i1 %57, label %58, label %59
58: ; preds = %52
store i32 1, i32* %3
br label %64
59: ; preds = %52
%60 = load i8*, i8** %4
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %4
%62 = load i8*, i8** %5
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %5
br label %8
64: ; preds = %58, %51, %44, %36, %28
%65 = load i32, i32* %3
ret i32 %65
}

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