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


x86 assembly (clang, -O0):
<FileUtil_countToLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x424(%rbp)
movl   $0x0,-0x428(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x42c(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
mov    -0x8(%rbp),%rdi
call   1070 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x42d(%rbp)
jne    11cd <FileUtil_countToLine+0x7d>
cmpl   $0x0,-0x428(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x42d(%rbp)
mov    -0x42d(%rbp),%al
test   $0x1,%al
jne    11e0 <FileUtil_countToLine+0x90>
jmp    124b <FileUtil_countToLine+0xfb>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
call   1030 <StrUtil_rmEndSpaces@plt>
cmpl   $0x0,-0x42c(%rbp)
je     1231 <FileUtil_countToLine+0xe1>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x42c(%rbp),%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1231 <FileUtil_countToLine+0xe1>
movl   $0x1,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
jmp    119f <FileUtil_countToLine+0x4f>
mov    -0x424(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x1,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileUtil_countToLine>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdx,%r15
mov    %rsi,0x8(%rsp)
mov    %rdi,%rbx
mov    %rdx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     11b5 <FileUtil_countToLine+0x65>
mov    0x8(%rsp),%rax
mov    %ebp,(%rax)
mov    $0x1,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
lea    0x10(%rsp),%r13
jmp    11e0 <FileUtil_countToLine+0x90>
xchg   %ax,%ax
mov    %r13,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
add    $0x1,%ebp
or     %r14d,%eax
jne    1197 <FileUtil_countToLine+0x47>
mov    %r13,%rdi
call   1030 <StrUtil_rmEndSpaces@plt>
mov    $0x0,%r14d
test   %r12d,%r12d
je     11c0 <FileUtil_countToLine+0x70>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1040 <strncmp@plt>
xor    %r14d,%r14d
test   %eax,%eax
sete   %r14b
jmp    11c0 <FileUtil_countToLine+0x70>

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

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