#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*/ string_empty(char const *);
size_t string_length(char const *);
int /*<<< orphan*/ strncasecmp(char const *, char const *, size_t);
int string_starts_with_ignore_case(const char *string, const char *prefix) {
  if (!string_empty(prefix)) {
    size_t length = string_length(string);
    size_t prefix_length = string_length(prefix);
    if (length < prefix_length)
      return 0;
    return !strncasecmp(string, prefix, prefix_length);
  }
  return 1;
}


x86 assembly (clang, -O0):
<string_starts_with_ignore_case>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <string_empty@plt>
cmp    $0x0,%eax
jne    11ac <string_starts_with_ignore_case+0x7c>
mov    -0x10(%rbp),%rdi
call   1040 <string_length@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <string_length@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1186 <string_starts_with_ignore_case+0x56>
movl   $0x0,-0x4(%rbp)
jmp    11b3 <string_starts_with_ignore_case+0x83>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <strncasecmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11b3 <string_starts_with_ignore_case+0x83>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_starts_with_ignore_case>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <string_empty@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
jne    117f <string_starts_with_ignore_case+0x4f>
mov    %r14,%rdi
call   1040 <string_length@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <string_length@plt>
mov    %rax,%rdx
xor    %eax,%eax
cmp    %rdx,%r15
jb     117f <string_starts_with_ignore_case+0x4f>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strncasecmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @string_starts_with_ignore_case(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @string_empty(i8* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %28, label %11
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i64 @string_length(i8* %12)
store i64 %13, i64* %6
%14 = load i8*, i8** %5
%15 = call i64 @string_length(i8* %14)
store i64 %15, i64* %7
%16 = load i64, i64* %6
%17 = load i64, i64* %7
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %11
store i32 0, i32* %3
br label %29
20: ; preds = %11
%21 = load i8*, i8** %4
%22 = load i8*, i8** %5
%23 = load i64, i64* %7
%24 = call i32 @strncasecmp(i8* %21, i8* %22, i64 %23)
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
%27 = zext i1 %26 to i32
store i32 %27, i32* %3
br label %29
28: ; preds = %2
store i32 1, i32* %3
br label %29
29: ; preds = %28, %20, %19
%30 = load i32, i32* %3
ret i32 %30
}

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