#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int count_lines(char *file_path) {
  FILE *file = fopen(file_path, "r");
  int c;
  int line_count = 0;
  if (file == NULL) {
    fprintf(stderr, "File not found.\n");
    fclose(file);
    return 0;
  }
  while ((c = fgetc(file)) != EOF) {
    if (c == '\n') {
      line_count++;
    }
  }
  fclose(file);
  return line_count;
}


x86 assembly (clang, -O0):
<count_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119c <count_lines+0x5c>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e3 <count_lines+0xa3>
jmp    11a1 <count_lines+0x61>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%eax
je     11d4 <count_lines+0x94>
cmpl   $0xa,-0x1c(%rbp)
jne    11cf <count_lines+0x8f>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a1 <count_lines+0x61>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_lines>:
push   %r15
push   %r14
push   %rbx
lea    0xeb4(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119c <count_lines+0x5c>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <fgetc@plt>
mov    0x2e80(%rip),%r15
xor    %ebx,%ebx
cmp    (%r15),%eax
je     1197 <count_lines+0x57>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebx
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%eax
jne    1180 <count_lines+0x40>
mov    %r14,%rdi
jmp    11b5 <count_lines+0x75>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
call   1050 <fprintf@plt>
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <fclose@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"File not found.\0A\00"
@EOF = global i32 0
define i32 @count_lines(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %4
store i32 0, i32* %6
%9 = load i32*, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32*, i32** %4
%15 = call i32 @fclose(i32* %14)
store i32 0, i32* %2
br label %33
16: ; preds = %1
br label %17
17: ; preds = %28, %16
%18 = load i32*, i32** %4
%19 = call i32 @fgetc(i32* %18)
store i32 %19, i32* %5
%20 = load i32, i32* @EOF
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %29
22: ; preds = %17
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %28
28: ; preds = %25, %22
br label %17
29: ; preds = %17
%30 = load i32*, i32** %4
%31 = call i32 @fclose(i32* %30)
%32 = load i32, i32* %6
store i32 %32, i32* %2
br label %33
33: ; preds = %29, %11
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"File not found.\0A\00"
@EOF = global i32 0
define i32 @count_lines(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = tail call i32 @fgetc(i32* %2)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %21, label %12
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @fclose(i32* null)
br label %24
12: ; preds = %4, %12
%13 = phi i32 [ %18, %12 ], [ %5, %4 ]
%14 = phi i32 [ %17, %12 ], [ 0, %4 ]
%15 = icmp eq i32 %13, 10
%16 = zext i1 %15 to i32
%17 = add nuw nsw i32 %14, %16
%18 = tail call i32 @fgetc(i32* %2)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %12
21: ; preds = %12, %4
%22 = phi i32 [ 0, %4 ], [ %17, %12 ]
%23 = tail call i32 @fclose(i32* %2)
br label %24
24: ; preds = %21, %8
%25 = phi i32 [ 0, %8 ], [ %22, %21 ]
ret i32 %25
}