#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int FileUtil_countLines(FILE *fp, char *string) {
  int count = 0;
  char line[1024];
  int lenString = strlen(string);
  fgets(line, 1024, fp);
  while (!feof(fp)) {
    if (!strncmp(line, string, lenString)) {
      count++;
    }
    fgets(line, 1024, fp);
  }
  return count;
}


x86 assembly (clang, -O0):
<FileUtil_countLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
mov    -0x8(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    119c <FileUtil_countLines+0x5c>
jmp    11de <FileUtil_countLines+0x9e>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x424(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11c4 <FileUtil_countLines+0x84>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
jmp    117e <FileUtil_countLines+0x3e>
mov    -0x14(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileUtil_countLines>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    11c0 <FileUtil_countLines+0x80>
xor    %ebp,%ebp
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <strncmp@plt>
cmp    $0x1,%eax
adc    $0x0,%ebp
mov    %r12,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     1190 <FileUtil_countLines+0x50>
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @FileUtil_countLines(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %7
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = load i32*, i32** %3
%12 = call i32 @fgets(i8* %10, i32 1024, i32* %11)
br label %13
13: ; preds = %27, %2
%14 = load i32*, i32** %3
%15 = call i32 @feof(i32* %14)
%16 = icmp ne i32 %15, 0
%17 = xor i1 %16, true
br i1 %17, label %18, label %31
18: ; preds = %13
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%20 = load i8*, i8** %4
%21 = load i32, i32* %7
%22 = call i32 @strncmp(i8* %19, i8* %20, i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %18
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %27
27: ; preds = %24, %18
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%29 = load i32*, i32** %3
%30 = call i32 @fgets(i8* %28, i32 1024, i32* %29)
br label %13
31: ; preds = %13
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
define i32 @FileUtil_countLines(i32* nocapture %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strlen(i8* %1)
%6 = call i32 @fgets(i8* %4, i32 1024, i32* %0)
%7 = call i32 @feof(i32* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %2, %9
%10 = phi i32 [ %14, %9 ], [ 0, %2 ]
%11 = call i32 @strncmp(i8* %4, i8* %1, i32 %5)
%12 = icmp eq i32 %11, 0
%13 = zext i1 %12 to i32
%14 = add nuw nsw i32 %10, %13
%15 = call i32 @fgets(i8* %4, i32 1024, i32* %0)
%16 = call i32 @feof(i32* %0)
%17 = icmp eq i32 %16, 0
br i1 %17, label %9, label %18
18: ; preds = %9, %2
%19 = phi i32 [ 0, %2 ], [ %14, %9 ]
ret i32 %19
}