#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__ memcmp(char const *, char const *, int);
scalar_t__ strncasecmp(char const *, char const *, int);
int ILibString_StartsWithEx(const char *inString, int inStringLength,
                            const char *startsWithString,
                            int startsWithStringLength, int caseSensitive) {
  int RetVal = 0;
  if (inStringLength >= startsWithStringLength) {
    if (caseSensitive != 0 &&
        memcmp(inString, startsWithString, startsWithStringLength) == 0)
      RetVal = 1;
    else if (caseSensitive == 0 && strncasecmp(inString, startsWithString,
                                               startsWithStringLength) == 0)
      RetVal = 1;
  }
  return (RetVal);
}


x86 assembly (clang, -O0):
<ILibString_StartsWithEx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     11b2 <ILibString_StartsWithEx+0x92>
cmpl   $0x0,-0x20(%rbp)
je     117d <ILibString_StartsWithEx+0x5d>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    117d <ILibString_StartsWithEx+0x5d>
movl   $0x1,-0x24(%rbp)
jmp    11ad <ILibString_StartsWithEx+0x8d>
cmpl   $0x0,-0x20(%rbp)
jne    11a8 <ILibString_StartsWithEx+0x88>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%rax
jne    11a8 <ILibString_StartsWithEx+0x88>
movl   $0x1,-0x24(%rbp)
jmp    11ad <ILibString_StartsWithEx+0x8d>
jmp    11b2 <ILibString_StartsWithEx+0x92>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ILibString_StartsWithEx>:
push   %rax
cmp    %ecx,%esi
jge    1129 <ILibString_StartsWithEx+0x9>
xor    %eax,%eax
jmp    1145 <ILibString_StartsWithEx+0x25>
mov    %rdx,%rsi
mov    %ecx,%edx
test   %r8d,%r8d
je     113a <ILibString_StartsWithEx+0x1a>
call   1030 <memcmp@plt>
jmp    113f <ILibString_StartsWithEx+0x1f>
call   1040 <strncasecmp@plt>
test   %rax,%rax
sete   %al
movzbl %al,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @ILibString_StartsWithEx(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i32 0, i32* %11
%12 = load i32, i32* %7
%13 = load i32, i32* %9
%14 = icmp sge i32 %12, %13
br i1 %14, label %15, label %37
15: ; preds = %5
%16 = load i32, i32* %10
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = load i8*, i8** %6
%20 = load i8*, i8** %8
%21 = load i32, i32* %9
%22 = call i64 @memcmp(i8* %19, i8* %20, i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 1, i32* %11
br label %36
25: ; preds = %18, %15
%26 = load i32, i32* %10
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = load i8*, i8** %6
%30 = load i8*, i8** %8
%31 = load i32, i32* %9
%32 = call i64 @strncasecmp(i8* %29, i8* %30, i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %28
store i32 1, i32* %11
br label %35
35: ; preds = %34, %28, %25
br label %36
36: ; preds = %35, %24
br label %37
37: ; preds = %36, %5
%38 = load i32, i32* %11
ret i32 %38
}

LLVM IR (-O2):
define i32 @ILibString_StartsWithEx(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4) {
%6 = icmp slt i32 %1, %3
br i1 %6, label %15, label %7
7: ; preds = %5
%8 = icmp eq i32 %4, 0
br i1 %8, label %12, label %9
9: ; preds = %7
%10 = tail call i64 @memcmp(i8* %0, i8* %2, i32 %3)
%11 = icmp eq i64 %10, 0
br label %15
12: ; preds = %7
%13 = tail call i64 @strncasecmp(i8* %0, i8* %2, i32 %3)
%14 = icmp eq i64 %13, 0
br label %15
15: ; preds = %9, %12, %5
%16 = phi i1 [ false, %5 ], [ %14, %12 ], [ %11, %9 ]
%17 = zext i1 %16 to i32
ret i32 %17
}