#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 nn_strcasecmp(const char *a, const char *b) {
  int rv;
  for (;;) {
    if ((*a == 0) && (*b == 0)) {
      return (0);
    }
    if ((rv = (tolower(*a) - tolower(*b))) != 0) {
      return (rv);
    }
    a++;
    b++;
  }
  return (0);
}


x86 assembly (clang, -O0):
<nn_strcasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    114c <nn_strcasecmp+0x3c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    114c <nn_strcasecmp+0x3c>
movl   $0x0,-0x4(%rbp)
jmp    11a2 <nn_strcasecmp+0x92>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     1185 <nn_strcasecmp+0x75>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a2 <nn_strcasecmp+0x92>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1120 <nn_strcasecmp+0x10>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nn_strcasecmp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
nop
movzbl (%r14,%rbx,1),%eax
test   %al,%al
jne    1130 <nn_strcasecmp+0x20>
cmpb   $0x0,(%r15,%rbx,1)
je     114e <nn_strcasecmp+0x3e>
movsbl %al,%edi
call   1030 <tolower@plt>
mov    %eax,%ebp
movsbl (%r15,%rbx,1),%edi
call   1030 <tolower@plt>
sub    %eax,%ebp
jne    1150 <nn_strcasecmp+0x40>
add    $0x1,%rbx
jmp    1120 <nn_strcasecmp+0x10>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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