#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
unsigned char *forward_scan(unsigned char *start, unsigned char *stop,
                            unsigned char *goal, int length) {
  unsigned char *i;
  int j, flag;
  for (i = start; i < stop; i++) {
    if (*i != *goal)
      continue;
    else {
      if (length == 1)
        return (i);
      else {
        flag = 1;
        for (j = 1; j < length; j++)
          if (*(i + j) != *(goal + j)) {
            flag = 0;
            break;
          }
        if (flag)
          return (i);
      }
    }
  }
  fprintf(stderr, "forward_scan() failed.\n\n");
  return (NULL);
}


x86 assembly (clang, -O0):
<forward_scan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11ff <forward_scan+0xef>
mov    -0x30(%rbp),%rax
movzbl (%rax),%eax
mov    -0x20(%rbp),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
je     1158 <forward_scan+0x48>
jmp    11ee <forward_scan+0xde>
cmpl   $0x1,-0x24(%rbp)
jne    116f <forward_scan+0x5f>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    121c <forward_scan+0x10c>
movl   $0x1,-0x38(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11c8 <forward_scan+0xb8>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x20(%rbp),%rcx
movslq -0x34(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11b5 <forward_scan+0xa5>
movl   $0x0,-0x38(%rbp)
jmp    11c8 <forward_scan+0xb8>
jmp    11ba <forward_scan+0xaa>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    117d <forward_scan+0x6d>
cmpl   $0x0,-0x38(%rbp)
je     11df <forward_scan+0xcf>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    121c <forward_scan+0x10c>
jmp    11e4 <forward_scan+0xd4>
jmp    11e9 <forward_scan+0xd9>
jmp    11ee <forward_scan+0xde>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    112f <forward_scan+0x1f>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<forward_scan>:
push   %rax
cmp    %rsi,%rdi
jae    1166 <forward_scan+0x56>
mov    %rdi,%rax
mov    (%rdx),%r8b
mov    %ecx,%r9d
jmp    1139 <forward_scan+0x29>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rax
cmp    %rsi,%rax
je     1166 <forward_scan+0x56>
cmp    %r8b,(%rax)
jne    1130 <forward_scan+0x20>
cmp    $0x2,%ecx
jl     1164 <forward_scan+0x54>
mov    $0x1,%edi
nopl   0x0(%rax,%rax,1)
movzbl (%rax,%rdi,1),%r10d
cmp    (%rdx,%rdi,1),%r10b
jne    1130 <forward_scan+0x20>
add    $0x1,%rdi
cmp    %rdi,%r9
jne    1150 <forward_scan+0x40>
pop    %rcx
ret
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"forward_scan() failed.\0A\0A\00"
define i8* @forward_scan(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%13 = load i8*, i8** %6
store i8* %13, i8** %10
br label %14
14: ; preds = %64, %4
%15 = load i8*, i8** %10
%16 = load i8*, i8** %7
%17 = icmp ult i8* %15, %16
br i1 %17, label %18, label %67
18: ; preds = %14
%19 = load i8*, i8** %10
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = load i8*, i8** %8
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = icmp ne i32 %21, %24
br i1 %25, label %26, label %27
26: ; preds = %18
br label %64
27: ; preds = %18
%28 = load i32, i32* %9
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = load i8*, i8** %10
store i8* %31, i8** %5
br label %70
32: ; preds = %27
store i32 1, i32* %12
store i32 1, i32* %11
br label %33
33: ; preds = %53, %32
%34 = load i32, i32* %11
%35 = load i32, i32* %9
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %56
37: ; preds = %33
%38 = load i8*, i8** %10
%39 = load i32, i32* %11
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = load i8*, i8** %8
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = icmp ne i32 %43, %49
br i1 %50, label %51, label %52
51: ; preds = %37
store i32 0, i32* %12
br label %56
52: ; preds = %37
br label %53
53: ; preds = %52
%54 = load i32, i32* %11
%55 = add nsw i32 %54, 1
store i32 %55, i32* %11
br label %33
56: ; preds = %51, %33
%57 = load i32, i32* %12
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = load i8*, i8** %10
store i8* %60, i8** %5
br label %70
61: ; preds = %56
br label %62
62: ; preds = %61
br label %63
63: ; preds = %62
br label %64
64: ; preds = %63, %26
%65 = load i8*, i8** %10
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %10
br label %14
67: ; preds = %14
%68 = load i32, i32* @stderr
%69 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %5
br label %70
70: ; preds = %67, %59, %30
%71 = load i8*, i8** %5
ret i8* %71
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"forward_scan() failed.\0A\0A\00"
define i8* @forward_scan(i8* %0, i8* readnone %1, i8* nocapture %2, i32 %3) {
%5 = icmp ult i8* %0, %1
br i1 %5, label %6, label %32
6: ; preds = %4
%7 = ptrtoint i8* %1 to i64
%8 = ptrtoint i8* %0 to i64
%9 = load i8, i8* %2
%10 = icmp slt i32 %3, 2
%11 = sub i64 %7, %8
%12 = getelementptr i8, i8* %0, i64 %11
%13 = zext i32 %3 to i64
br label %14
14: ; preds = %6, %29
%15 = phi i8* [ %0, %6 ], [ %30, %29 ]
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, %9
br i1 %17, label %18, label %29
18: ; preds = %14
br i1 %10, label %35, label %21
19: ; preds = %21
%20 = icmp eq i64 %28, %13
br i1 %20, label %35, label %21
21: ; preds = %18, %19
%22 = phi i64 [ %28, %19 ], [ 1, %18 ]
%23 = getelementptr inbounds i8, i8* %15, i64 %22
%24 = load i8, i8* %23
%25 = getelementptr inbounds i8, i8* %2, i64 %22
%26 = load i8, i8* %25
%27 = icmp eq i8 %24, %26
%28 = add nuw nsw i64 %22, 1
br i1 %27, label %19, label %29
29: ; preds = %21, %14
%30 = getelementptr inbounds i8, i8* %15, i64 1
%31 = icmp eq i8* %30, %12
br i1 %31, label %32, label %14
32: ; preds = %29, %4
%33 = load i32, i32* @stderr
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %18, %19, %32
%36 = phi i8* [ null, %32 ], [ %15, %19 ], [ %15, %18 ]
ret i8* %36
}