#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__ tolower(char);
int hash_compare_checksum(const char *chk1, const char *chk2, int length) {
  char c1, c2;
  length *= 2;
  while (length--) {
    c1 = *chk1++;
    c2 = *chk2++;
    if (tolower(c1) != tolower(c2))
      return 0;
    if (!c1)
      return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<hash_compare_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
je     11b5 <hash_compare_checksum+0xa5>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x1d(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x1e(%rbp)
movsbl -0x1d(%rbp),%edi
call   1030 <tolower@plt>
mov    %rax,-0x28(%rbp)
movsbl -0x1e(%rbp),%edi
call   1030 <tolower@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     119a <hash_compare_checksum+0x8a>
movl   $0x0,-0x4(%rbp)
jmp    11bc <hash_compare_checksum+0xac>
cmpb   $0x0,-0x1d(%rbp)
jne    11b0 <hash_compare_checksum+0xa0>
movl   $0x0,-0x4(%rbp)
jmp    11bc <hash_compare_checksum+0xac>
jmp    112c <hash_compare_checksum+0x1c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_compare_checksum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %rsi,(%rsp)
mov    %rdi,%r15
add    %r12d,%r12d
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
cmp    %r14d,%r12d
je     1169 <hash_compare_checksum+0x59>
movsbl (%r15,%r14,1),%ebp
mov    (%rsp),%rax
movsbl (%rax,%r14,1),%r13d
mov    %ebp,%edi
call   1030 <tolower@plt>
mov    %rax,%rbx
mov    %r13d,%edi
call   1030 <tolower@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %ebp,%ebp
je     116e <hash_compare_checksum+0x5e>
add    $0x1,%r14
cmp    %rcx,%rbx
je     1130 <hash_compare_checksum+0x20>
jmp    116e <hash_compare_checksum+0x5e>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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