#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 */
scalar_t__ strlen(char *);
scalar_t__ tolower(unsigned char);
unsigned char strcmpnc(unsigned char *p1, unsigned char *p2) {
  unsigned char nResult = 1;
  if (strlen((char *)p1) != strlen((char *)p2)) {
    nResult = 0;
  } else {
    while (*p1) {
      if (tolower(*p1) != tolower(*p2)) {
        nResult = 0;
        break;
      }
      p1++;
      p2++;
    }
  }
  return nResult;
}


x86 assembly (clang, -O0):
<strcmpnc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x1,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
je     1163 <strcmpnc+0x43>
movb   $0x0,-0x11(%rbp)
jmp    11cc <strcmpnc+0xac>
jmp    1168 <strcmpnc+0x48>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c7 <strcmpnc+0xa7>
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1040 <tolower@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1040 <tolower@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     11aa <strcmpnc+0x8a>
movb   $0x0,-0x11(%rbp)
jmp    11c7 <strcmpnc+0xa7>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1168 <strcmpnc+0x48>
jmp    11cc <strcmpnc+0xac>
movzbl -0x11(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcmpnc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %rax,%rbp
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %rax,%rbp
jne    117a <strcmpnc+0x5a>
mov    (%r12),%al
mov    $0x1,%r15b
test   %al,%al
je     117d <strcmpnc+0x5d>
xor    %ebx,%ebx
movzbl %al,%edi
call   1040 <tolower@plt>
mov    %rax,%rbp
movzbl (%r14,%rbx,1),%edi
call   1040 <tolower@plt>
cmp    %rax,%rbp
jne    117a <strcmpnc+0x5a>
movzbl 0x1(%r12,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1150 <strcmpnc+0x30>
jmp    117d <strcmpnc+0x5d>
xor    %r15d,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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