#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 const);
int kl_strceq(char const *s1, char const *s2) {
  int i = 0;
  while (tolower(s1[i]) == tolower(s2[i])) {
    if (s1[i] == '\0') {
      return 1;
    }
    i++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<kl_strceq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <tolower@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <tolower@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jne    118c <kl_strceq+0x7c>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    117e <kl_strceq+0x6e>
movl   $0x1,-0x4(%rbp)
jmp    1193 <kl_strceq+0x83>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1127 <kl_strceq+0x17>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kl_strceq>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
movsbl (%rdi),%edi
call   1030 <tolower@plt>
mov    %rax,%rbp
movsbl (%r14),%edi
call   1030 <tolower@plt>
xor    %r15d,%r15d
cmp    %rax,%rbp
jne    1170 <kl_strceq+0x60>
mov    $0x1,%ebx
nop
cmpb   $0x0,-0x1(%r12,%rbx,1)
je     116a <kl_strceq+0x5a>
movsbl (%r12,%rbx,1),%edi
call   1030 <tolower@plt>
mov    %rax,%rbp
movsbl (%r14,%rbx,1),%edi
call   1030 <tolower@plt>
add    $0x1,%rbx
cmp    %rax,%rbp
je     1140 <kl_strceq+0x30>
jmp    1170 <kl_strceq+0x60>
mov    $0x1,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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