#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 */
unsigned int strlen(char const *);
unsigned str_starts_with(const char *str1, const char *str2, unsigned f_char,
                         unsigned l_char) {
  unsigned i, len = strlen(str1);
  if (len > l_char - f_char + 1)
    return 0;
  for (i = 0; i < len; i++)
    if (str1[i] != str2[f_char + i])
      return 0;
  return 1;
}


x86 assembly (clang, -O0):
<str_starts_with>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jbe    1152 <str_starts_with+0x42>
movl   $0x0,-0x4(%rbp)
jmp    11ae <str_starts_with+0x9e>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jae    11a7 <str_starts_with+0x97>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%edx
add    -0x24(%rbp),%edx
mov    %edx,%edx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     1194 <str_starts_with+0x84>
movl   $0x0,-0x4(%rbp)
jmp    11ae <str_starts_with+0x9e>
jmp    1199 <str_starts_with+0x89>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1159 <str_starts_with+0x49>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_starts_with>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%ecx
sub    %r15d,%ebp
add    $0x1,%ebp
xor    %eax,%eax
cmp    %ebp,%ecx
ja     116b <str_starts_with+0x5b>
mov    $0x1,%eax
test   %ecx,%ecx
je     116b <str_starts_with+0x5b>
mov    %ecx,%ecx
mov    %r15d,%edx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
movzbl (%r12,%rsi,1),%ebx
lea    (%rdx,%rsi,1),%edi
cmp    (%r14,%rdi,1),%bl
jne    1169 <str_starts_with+0x59>
add    $0x1,%rsi
cmp    %rsi,%rcx
jne    1150 <str_starts_with+0x40>
jmp    116b <str_starts_with+0x5b>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @str_starts_with(i8* %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i32 @strlen(i8* %0)
%6 = sub i32 1, %2
%7 = add i32 %6, %3
%8 = icmp ugt i32 %5, %7
br i1 %8, label %26, label %9
9: ; preds = %4
%10 = icmp eq i32 %5, 0
br i1 %10, label %26, label %11
11: ; preds = %9
%12 = zext i32 %5 to i64
br label %15
13: ; preds = %15
%14 = icmp eq i64 %25, %12
br i1 %14, label %26, label %15
15: ; preds = %11, %13
%16 = phi i64 [ 0, %11 ], [ %25, %13 ]
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = trunc i64 %16 to i32
%20 = add i32 %19, %2
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %1, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %18, %23
%25 = add nuw nsw i64 %16, 1
br i1 %24, label %13, label %26
26: ; preds = %15, %13, %9, %4
%27 = phi i32 [ 0, %4 ], [ 1, %9 ], [ 0, %15 ], [ 1, %13 ]
ret i32 %27
}