#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int fgetc(int /*<<< orphan*/ *);
size_t strlen(char const *);
bool match(FILE *f, const char *str) {
  size_t matched = 0;
  size_t len = strlen(str);
  while (matched != len) {
    int c = fgetc(f);
    if (c == EOF)
      return false;
    if (c == str[matched])
      matched++;
    else
      matched = 0;
  }
  return true;
}


x86 assembly (clang, -O0):
<match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     11b2 <match+0x92>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2e7f(%rip),%rcx
cmp    (%rcx),%eax
jne    117d <match+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    11b9 <match+0x99>
mov    -0x2c(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    11a5 <match+0x85>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11ad <match+0x8d>
movq   $0x0,-0x20(%rbp)
jmp    1145 <match+0x25>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     118d <match+0x6d>
mov    %rax,%rbp
xor    %ebx,%ebx
mov    0x2e98(%rip),%r12
jmp    1167 <match+0x47>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %ebx,%ebx
cmp    %rbp,%rbx
je     118d <match+0x6d>
mov    %r15,%rdi
call   1040 <fgetc@plt>
cmp    (%r12),%eax
je     118a <match+0x6a>
movsbl 0x0(%r13,%rbx,1),%ecx
cmp    %ecx,%eax
jne    1160 <match+0x40>
add    $0x1,%rbx
cmp    %rbp,%rbx
jne    1167 <match+0x47>
jmp    118d <match+0x6d>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @match(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 0, i64* %6
%9 = load i8*, i8** %5
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %7
br label %11
11: ; preds = %34, %2
%12 = load i64, i64* %6
%13 = load i64, i64* %7
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %35
15: ; preds = %11
%16 = load i32*, i32** %4
%17 = call i32 @fgetc(i32* %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 0, i32* %3
br label %36
22: ; preds = %15
%23 = load i32, i32* %8
%24 = load i8*, i8** %5
%25 = load i64, i64* %6
%26 = getelementptr inbounds i8, i8* %24, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %23, %28
br i1 %29, label %30, label %33
30: ; preds = %22
%31 = load i64, i64* %6
%32 = add i64 %31, 1
store i64 %32, i64* %6
br label %34
33: ; preds = %22
store i64 0, i64* %6
br label %34
34: ; preds = %33, %30
br label %11
35: ; preds = %11
store i32 1, i32* %3
br label %36
36: ; preds = %35, %21
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @match(i32* nocapture %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %18, label %5
5: ; preds = %2, %10
%6 = phi i64 [ %16, %10 ], [ 0, %2 ]
%7 = tail call i32 @fgetc(i32* %0)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %18, label %10
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %1, i64 %6
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %7, %13
%15 = add i64 %6, 1
%16 = select i1 %14, i64 %15, i64 0
%17 = icmp eq i64 %16, %3
br i1 %17, label %18, label %5
18: ; preds = %10, %5, %2
%19 = phi i32 [ 1, %2 ], [ 0, %5 ], [ 1, %10 ]
ret i32 %19
}