#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 strncasecmp(const char *s1, const char *s2, int amount) {
  int i = 0;
  for (; i < amount; i++) {
    if (toLower(*s1) != toLower(*s2)) {
      return 1;
    }
    s1++;
    s2++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<strncasecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1194 <strncasecmp+0x84>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toLower@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toLower@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     116e <strncasecmp+0x5e>
movl   $0x1,-0x4(%rbp)
jmp    119b <strncasecmp+0x8b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112a <strncasecmp+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strncasecmp>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %edx,%edx
jle    1155 <strncasecmp+0x45>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edi
call   1030 <toLower@plt>
mov    %rax,%r13
movsbl (%r14,%rbx,1),%edi
call   1030 <toLower@plt>
cmp    %rax,%r13
jne    1159 <strncasecmp+0x49>
add    $0x1,%rbx
cmp    %ebx,%r12d
jne    1130 <strncasecmp+0x20>
xor    %eax,%eax
jmp    115e <strncasecmp+0x4e>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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