#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 /*<<< orphan*/ assert(char const *);
size_t strlen(char const *);
int strncasecmp(char *, char const *, size_t);
int strncmp(char *, char const *, size_t);
int _mx_strbeginswith(char *str, const char *start, char **endptr,
                      short ignore_case) {
  size_t len;
  int res;
  assert(str);
  assert(start);
  len = strlen(start);
  if (ignore_case)
    res = strncasecmp(str, start, len);
  else
    res = strncmp(str, start, len);
  if (res != 0 || !endptr)
    return !res;
  *endptr = str + len;
  return 1;
}


x86 assembly (clang, -O0):
<_mx_strbeginswith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %cx,%ax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ax,-0x22(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
cmpw   $0x0,-0x22(%rbp)
je     119e <_mx_strbeginswith+0x5e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1060 <strncasecmp@plt>
mov    %eax,-0x34(%rbp)
jmp    11b2 <_mx_strbeginswith+0x72>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <strncmp@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    11c7 <_mx_strbeginswith+0x87>
cmpq   $0x0,-0x20(%rbp)
jne    11dd <_mx_strbeginswith+0x9d>
cmpl   $0x0,-0x34(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11f3 <_mx_strbeginswith+0xb3>
mov    -0x10(%rbp),%rcx
add    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_mx_strbeginswith>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
test   %bp,%bp
je     1185 <_mx_strbeginswith+0x45>
call   1060 <strncasecmp@plt>
test   %r14,%r14
jne    118f <_mx_strbeginswith+0x4f>
jmp    11a0 <_mx_strbeginswith+0x60>
call   1030 <strncmp@plt>
test   %r14,%r14
je     11a0 <_mx_strbeginswith+0x60>
test   %eax,%eax
jne    11a0 <_mx_strbeginswith+0x60>
add    %r15,%r12
mov    %r12,(%r14)
mov    $0x1,%ecx
jmp    11a7 <_mx_strbeginswith+0x67>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_mx_strbeginswith(i8* %0, i8* %1, i8** %2, i16 signext %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i16
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8** %2, i8*** %8
store i16 %3, i16* %9
%12 = load i8*, i8** %6
%13 = call i32 @assert(i8* %12)
%14 = load i8*, i8** %7
%15 = call i32 @assert(i8* %14)
%16 = load i8*, i8** %7
%17 = call i64 @strlen(i8* %16)
store i64 %17, i64* %10
%18 = load i16, i16* %9
%19 = icmp ne i16 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %4
%21 = load i8*, i8** %6
%22 = load i8*, i8** %7
%23 = load i64, i64* %10
%24 = call i32 @strncasecmp(i8* %21, i8* %22, i64 %23)
store i32 %24, i32* %11
br label %30
25: ; preds = %4
%26 = load i8*, i8** %6
%27 = load i8*, i8** %7
%28 = load i64, i64* %10
%29 = call i32 @strncmp(i8* %26, i8* %27, i64 %28)
store i32 %29, i32* %11
br label %30
30: ; preds = %25, %20
%31 = load i32, i32* %11
%32 = icmp ne i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = load i8**, i8*** %8
%35 = icmp ne i8** %34, null
br i1 %35, label %41, label %36
36: ; preds = %33, %30
%37 = load i32, i32* %11
%38 = icmp ne i32 %37, 0
%39 = xor i1 %38, true
%40 = zext i1 %39 to i32
store i32 %40, i32* %5
br label %46
41: ; preds = %33
%42 = load i8*, i8** %6
%43 = load i64, i64* %10
%44 = getelementptr inbounds i8, i8* %42, i64 %43
%45 = load i8**, i8*** %8
store i8* %44, i8** %45
store i32 1, i32* %5
br label %46
46: ; preds = %41, %36
%47 = load i32, i32* %5
ret i32 %47
}

LLVM IR (-O2):
define i32 @_mx_strbeginswith(i8* %0, i8* %1, i8** writeonly %2, i16 signext %3) {
%5 = tail call i32 @assert(i8* %0)
%6 = tail call i32 @assert(i8* %1)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = icmp eq i16 %3, 0
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = tail call i32 @strncasecmp(i8* %0, i8* %1, i64 %7)
br label %13
11: ; preds = %4
%12 = tail call i32 @strncmp(i8* %0, i8* %1, i64 %7)
br label %13
13: ; preds = %11, %9
%14 = phi i32 [ %10, %9 ], [ %12, %11 ]
%15 = icmp eq i32 %14, 0
%16 = icmp ne i8** %2, null
%17 = and i1 %16, %15
br i1 %17, label %20, label %18
18: ; preds = %13
%19 = zext i1 %15 to i32
br label %22
20: ; preds = %13
%21 = getelementptr inbounds i8, i8* %0, i64 %7
store i8* %21, i8** %2
br label %22
22: ; preds = %20, %18
%23 = phi i32 [ 1, %20 ], [ %19, %18 ]
ret i32 %23
}