#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 strlen(char const *);
scalar_t__ tolower(char const);
int startsWith(const char *a, const char *b) {
  int i, n = 0;
  n = strlen(b);
  if (strlen(a) < n)
    return -1;
  for (i = 0; i < n; i++)
    if (tolower(a[i]) != tolower(b[i]))
      return -1;
  return 0;
}


x86 assembly (clang, -O0):
<startsWith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0x20(%rbp),%eax
jge    1161 <startsWith+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <startsWith+0xb0>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11c9 <startsWith+0xa9>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     11b6 <startsWith+0x96>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <startsWith+0xb0>
jmp    11bb <startsWith+0x9b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1168 <startsWith+0x48>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<startsWith>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r13
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    $0xffffffff,%r14d
cmp    %r15d,%eax
jl     1189 <startsWith+0x69>
test   %r15d,%r15d
jle    1186 <startsWith+0x66>
mov    %r15d,%r15d
xor    %ebp,%ebp
nopl   0x0(%rax)
movsbl 0x0(%r13,%rbp,1),%edi
call   1040 <tolower@plt>
mov    %rax,%rbx
movsbl (%r12,%rbp,1),%edi
call   1040 <tolower@plt>
cmp    %rax,%rbx
jne    1189 <startsWith+0x69>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1160 <startsWith+0x40>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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