#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 */
scalar_t__ getByte(unsigned char *);
int findPart(unsigned char *buffer, size_t len) {
  unsigned char charBuffer[2];
  int idx = 0;
  int total = 0;
  while (getByte(charBuffer) > 0) {
    if (idx >= len)
      return 1;
    if (*charBuffer != buffer[idx])
      idx = 0;
    else
      idx++;
    if (total++ > 2000)
      return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<findPart>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x1a(%rbp),%rdi
call   1030 <getByte@plt>
cmp    $0x0,%rax
jle    11af <findPart+0x9f>
movslq -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     115b <findPart+0x4b>
movl   $0x1,-0x4(%rbp)
jmp    11b6 <findPart+0xa6>
movzbl -0x1a(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x20(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     117f <findPart+0x6f>
movl   $0x0,-0x20(%rbp)
jmp    1188 <findPart+0x78>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
cmp    $0x7d0,%eax
jle    11aa <findPart+0x9a>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <findPart+0xa6>
jmp    112e <findPart+0x1e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findPart>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
xor    %ebx,%ebx
mov    $0x7d2,%ebp
lea    0xe(%rsp),%r15
jmp    1137 <findPart+0x27>
xor    %ebx,%ebx
add    $0xffffffff,%ebp
je     116c <findPart+0x5c>
mov    %r15,%rdi
call   1030 <getByte@plt>
test   %rax,%rax
jle    1163 <findPart+0x53>
movslq %ebx,%rcx
cmp    %r12,%rcx
jae    1167 <findPart+0x57>
movzbl 0xe(%rsp),%edx
xor    %eax,%eax
cmp    (%r14,%rcx,1),%dl
jne    1130 <findPart+0x20>
add    $0x1,%ebx
add    $0xffffffff,%ebp
jne    1137 <findPart+0x27>
jmp    116c <findPart+0x5c>
xor    %eax,%eax
jmp    116c <findPart+0x5c>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @findPart(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [2 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 0, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %39, %2
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%11 = call i64 @getByte(i8* %10)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %40
13: ; preds = %9
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = load i64, i64* %5
%17 = icmp uge i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 1, i32* %3
br label %41
19: ; preds = %13
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = load i8*, i8** %4
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = icmp ne i32 %22, %28
br i1 %29, label %30, label %31
30: ; preds = %19
store i32 0, i32* %7
br label %34
31: ; preds = %19
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %34
34: ; preds = %31, %30
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
%37 = icmp sgt i32 %35, 2000
br i1 %37, label %38, label %39
38: ; preds = %34
store i32 0, i32* %3
br label %41
39: ; preds = %34
br label %9
40: ; preds = %9
store i32 0, i32* %3
br label %41
41: ; preds = %40, %38, %18
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
define i32 @findPart(i8* nocapture %0, i64 %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %13, %2
%6 = phi i32 [ 0, %2 ], [ %19, %13 ]
%7 = phi i32 [ 0, %2 ], [ %20, %13 ]
%8 = call i64 @getByte(i8* %4)
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %22
10: ; preds = %5
%11 = sext i32 %6 to i64
%12 = icmp ult i64 %11, %1
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = load i8, i8* %4
%15 = getelementptr inbounds i8, i8* %0, i64 %11
%16 = load i8, i8* %15
%17 = icmp eq i8 %14, %16
%18 = add nsw i32 %6, 1
%19 = select i1 %17, i32 %18, i32 0
%20 = add nuw nsw i32 %7, 1
%21 = icmp eq i32 %20, 2002
br i1 %21, label %22, label %5
22: ; preds = %5, %13, %10
%23 = phi i32 [ 1, %10 ], [ 0, %13 ], [ 0, %5 ]
ret i32 %23
}