#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 /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int /*<<< orphan*/);
bool check_for_pattern(FILE *fp, char *pattern, char *buf) {
  while (fgets(buf, 500, fp) != NULL) {
    if (!strncmp(buf, pattern, strlen(pattern)))
      return true;
  }
  return false;
}


x86 assembly (clang, -O0):
<check_for_pattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x1f4,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11a2 <check_for_pattern+0x72>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    119d <check_for_pattern+0x6d>
movl   $0x1,-0x4(%rbp)
jmp    11a9 <check_for_pattern+0x79>
jmp    1144 <check_for_pattern+0x14>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_for_pattern>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
xchg   %ax,%ax
mov    %r14,%rdi
mov    $0x1f4,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1175 <check_for_pattern+0x45>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1140 <check_for_pattern+0x10>
mov    $0x1,%eax
jmp    1177 <check_for_pattern+0x47>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @check_for_pattern(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
br label %8
8: ; preds = %21, %3
%9 = load i8*, i8** %7
%10 = load i32*, i32** %5
%11 = call i32* @fgets(i8* %9, i32 500, i32* %10)
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %22
13: ; preds = %8
%14 = load i8*, i8** %7
%15 = load i8*, i8** %6
%16 = load i8*, i8** %6
%17 = call i32 @strlen(i8* %16)
%18 = call i32 @strncmp(i8* %14, i8* %15, i32 %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %13
store i32 1, i32* %4
br label %23
21: ; preds = %13
br label %8
22: ; preds = %8
store i32 0, i32* %4
br label %23
23: ; preds = %22, %20
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
define i32 @check_for_pattern(i32* nocapture %0, i8* %1, i8* %2) {
br label %4
4: ; preds = %7, %3
%5 = tail call i32* @fgets(i8* %2, i32 500, i32* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = tail call i32 @strlen(i8* %1)
%9 = tail call i32 @strncmp(i8* %2, i8* %1, i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %4
11: ; preds = %4, %7
%12 = phi i32 [ 1, %7 ], [ 0, %4 ]
ret i32 %12
}