#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 EOF;
scalar_t__ EXIT_SUCCESS;
scalar_t__ evaluateMatch(int, int, int, int, int);
int getchar();
scalar_t__ legalChar(int);
int /*<<< orphan*/ printForDebug(int, int *, int);
int findPattern(int pattern, int index, int debugMode) {
  int counterFound = 0;
  int counterPosition = 1;
  int letter;
  int wasItCounted = 0;
  int stateEnter = 1;
  while ((letter = getchar()) != EOF) {
    if (debugMode == 1) {
      printForDebug(letter, &stateEnter, counterPosition);
    }
    if (legalChar(letter) == EXIT_SUCCESS) {
      if (evaluateMatch(pattern, letter, index, counterPosition,
                        wasItCounted) != EXIT_SUCCESS) {
        counterFound++;
        wasItCounted = 1;
      } else {
        counterPosition++;
      }
    } else {
      wasItCounted = 0;
      counterPosition = 1;
    }
  }
  return counterFound;
}


x86 assembly (clang, -O0):
<findPattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%eax
je     1212 <findPattern+0xd2>
cmpl   $0x1,-0xc(%rbp)
jne    119f <findPattern+0x5f>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%edx
lea    -0x20(%rbp),%rsi
call   1050 <printForDebug@plt>
mov    -0x18(%rbp),%edi
call   1060 <legalChar@plt>
mov    0x2e2a(%rip),%rcx
cmp    (%rcx),%rax
jne    11ff <findPattern+0xbf>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1040 <evaluateMatch@plt>
mov    0x2e05(%rip),%rcx
cmp    (%rcx),%rax
je     11f1 <findPattern+0xb1>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
jmp    11fa <findPattern+0xba>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    120d <findPattern+0xcd>
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    116d <findPattern+0x2d>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findPattern>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %esi,0x10(%rsp)
mov    %edi,0xc(%rsp)
movl   $0x1,0x14(%rsp)
xor    %r13d,%r13d
xor    %eax,%eax
call   1030 <getchar@plt>
mov    %eax,%r14d
mov    0x2e74(%rip),%rax
cmp    (%rax),%r14d
jne    118b <findPattern+0x4b>
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebp
mov    0x2e41(%rip),%r15
xor    %r12d,%r12d
xor    %r13d,%r13d
jmp    11be <findPattern+0x7e>
nop
xor    %r12d,%r12d
mov    $0x1,%ebp
xor    %eax,%eax
call   1030 <getchar@plt>
mov    %eax,%r14d
mov    0x2e2f(%rip),%rax
cmp    (%rax),%r14d
je     1179 <findPattern+0x39>
cmp    $0x1,%ebx
jne    11d2 <findPattern+0x92>
mov    %r14d,%edi
lea    0x14(%rsp),%rsi
mov    %ebp,%edx
call   1050 <printForDebug@plt>
mov    %r14d,%edi
call   1060 <legalChar@plt>
cmp    (%r15),%rax
jne    11a0 <findPattern+0x60>
mov    0xc(%rsp),%edi
mov    %r14d,%esi
mov    0x10(%rsp),%edx
mov    %ebp,%ecx
mov    %r12d,%r8d
call   1040 <evaluateMatch@plt>
cmp    (%r15),%rax
jne    1200 <findPattern+0xc0>
add    $0x1,%ebp
jmp    11a8 <findPattern+0x68>
xchg   %ax,%ax
add    $0x1,%r13d
mov    $0x1,%r12d
jmp    11a8 <findPattern+0x68>

LLVM IR (-O0):
@EOF = global i32 0
@EXIT_SUCCESS = global i64 0
define i32 @findPattern(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 1, i32* %8
store i32 0, i32* %10
store i32 1, i32* %11
br label %12
12: ; preds = %45, %3
%13 = call i32 (...) @getchar()
store i32 %13, i32* %9
%14 = load i32, i32* @EOF
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %46
16: ; preds = %12
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* %9
%21 = load i32, i32* %8
%22 = call i32 @printForDebug(i32 %20, i32* %11, i32 %21)
br label %23
23: ; preds = %19, %16
%24 = load i32, i32* %9
%25 = call i64 @legalChar(i32 %24)
%26 = load i64, i64* @EXIT_SUCCESS
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %44
28: ; preds = %23
%29 = load i32, i32* %4
%30 = load i32, i32* %9
%31 = load i32, i32* %5
%32 = load i32, i32* %8
%33 = load i32, i32* %10
%34 = call i64 @evaluateMatch(i32 %29, i32 %30, i32 %31, i32 %32, i32 %33)
%35 = load i64, i64* @EXIT_SUCCESS
%36 = icmp ne i64 %34, %35
br i1 %36, label %37, label %40
37: ; preds = %28
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
store i32 1, i32* %10
br label %43
40: ; preds = %28
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %43
43: ; preds = %40, %37
br label %45
44: ; preds = %23
store i32 0, i32* %10
store i32 1, i32* %8
br label %45
45: ; preds = %44, %43
br label %12
46: ; preds = %12
%47 = load i32, i32* %7
ret i32 %47
}

LLVM IR (-O2):
@EOF = global i32 0
@EXIT_SUCCESS = global i64 0
define i32 @findPattern(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 1, i32* %4
%6 = call i32 (...) @getchar()
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %37, label %9
9: ; preds = %3
%10 = icmp eq i32 %2, 1
br label %11
11: ; preds = %9, %30
%12 = phi i32 [ %6, %9 ], [ %34, %30 ]
%13 = phi i32 [ 0, %9 ], [ %33, %30 ]
%14 = phi i32 [ 0, %9 ], [ %32, %30 ]
%15 = phi i32 [ 1, %9 ], [ %31, %30 ]
br i1 %10, label %16, label %18
16: ; preds = %11
%17 = call i32 @printForDebug(i32 %12, i32* %4, i32 %15)
br label %18
18: ; preds = %16, %11
%19 = call i64 @legalChar(i32 %12)
%20 = load i64, i64* @EXIT_SUCCESS
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = call i64 @evaluateMatch(i32 %0, i32 %12, i32 %1, i32 %15, i32 %13)
%24 = load i64, i64* @EXIT_SUCCESS
%25 = icmp eq i64 %23, %24
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = add nsw i32 %14, 1
br label %30
28: ; preds = %22
%29 = add nsw i32 %15, 1
br label %30
30: ; preds = %18, %26, %28
%31 = phi i32 [ %15, %26 ], [ %29, %28 ], [ 1, %18 ]
%32 = phi i32 [ %27, %26 ], [ %14, %28 ], [ %14, %18 ]
%33 = phi i32 [ 1, %26 ], [ %13, %28 ], [ 0, %18 ]
%34 = call i32 (...) @getchar()
%35 = load i32, i32* @EOF
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %11
37: ; preds = %30, %3
%38 = phi i32 [ 0, %3 ], [ %32, %30 ]
ret i32 %38
}