#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));
  }
  return cmp == 0 ? 1 : 0;
}


x86 assembly (clang, -O0):
<StartsWith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     117d <StartsWith+0x4d>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1040 <strnicmp@plt>
mov    %eax,-0x18(%rbp)
jmp    11a8 <StartsWith+0x78>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmove  %ecx,%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 i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %3
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = load i8*, i8** %5
%14 = call i64 @strlen(i8* %13)
%15 = trunc i64 %14 to i32
%16 = call i32 @strnicmp(i8* %11, i8* %12, i32 %15)
store i32 %16, i32* %7
br label %24
17: ; preds = %3
%18 = load i8*, i8** %4
%19 = load i8*, i8** %5
%20 = load i8*, i8** %5
%21 = call i64 @strlen(i8* %20)
%22 = trunc i64 %21 to i32
%23 = call i32 @strncmp(i8* %18, i8* %19, i32 %22)
store i32 %23, i32* %7
br label %24
24: ; preds = %17, %10
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 1, i32 0
ret i32 %28
}

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
}