#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 const *);
int strncmp(char const *, char const *, int);
int strnicmp(char const *, char const *, int);
int StartsWith(const char *str, const char *startsWith, int ignoreCase) {
  int cmp;
  if (ignoreCase != 0) {
    cmp = strnicmp(str, startsWith, (int)strlen(startsWith));
  } else {
    cmp = strncmp(str, startsWith, (int)strlen(startsWith));
  }
  if (cmp == 0) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<StartsWith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     117d <StartsWith+0x4d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1040 <strnicmp@plt>
mov    %eax,-0x20(%rbp)
jmp    11a8 <StartsWith+0x78>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    11be <StartsWith+0x8e>
movl   $0x1,-0x4(%rbp)
jmp    11c5 <StartsWith+0x95>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StartsWith>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
test   %ebp,%ebp
je     1157 <StartsWith+0x27>
call   1040 <strnicmp@plt>
jmp    115c <StartsWith+0x2c>
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @StartsWith(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
%9 = load i32, i32* %7
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = load i8*, i8** %6
%14 = load i8*, i8** %6
%15 = call i64 @strlen(i8* %14)
%16 = trunc i64 %15 to i32
%17 = call i32 @strnicmp(i8* %12, i8* %13, i32 %16)
store i32 %17, i32* %8
br label %25
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = load i8*, i8** %6
%21 = load i8*, i8** %6
%22 = call i64 @strlen(i8* %21)
%23 = trunc i64 %22 to i32
%24 = call i32 @strncmp(i8* %19, i8* %20, i32 %23)
store i32 %24, i32* %8
br label %25
25: ; preds = %18, %11
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 1, i32* %4
br label %30
29: ; preds = %25
store i32 0, i32* %4
br label %30
30: ; preds = %29, %28
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @StartsWith(i8* %0, i8* %1, i32 %2) {
%4 = icmp eq i32 %2, 0
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = trunc i64 %5 to i32
br i1 %4, label %9, label %7
7: ; preds = %3
%8 = tail call i32 @strnicmp(i8* %0, i8* %1, i32 %6)
br label %11
9: ; preds = %3
%10 = tail call i32 @strncmp(i8* %0, i8* %1, i32 %6)
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ %8, %7 ], [ %10, %9 ]
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
ret i32 %14
}