#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int count_sources(char *filename) {
  int number = 0;
  int ch = 0;
  FILE *fp;
  fp = fopen(filename, "r");
  if (fp == NULL) {
    fprintf(stderr, "Can not open file %s\n", filename);
    exit(EXIT_FAILURE);
  }
  while (!feof(fp)) {
    ch = fgetc(fp);
    if (ch == '\n')
      number++;
  }
  fclose(fp);
  return number;
}


x86 assembly (clang, -O0):
<count_sources>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c0 <count_sources+0x60>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe55(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11c5 <count_sources+0x65>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e3 <count_sources+0x83>
jmp    1207 <count_sources+0xa7>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jne    1202 <count_sources+0xa2>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c5 <count_sources+0x65>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_sources>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbp
lea    0xe93(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11bf <count_sources+0x5f>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    11ae <count_sources+0x4e>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     1190 <count_sources+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
mov    %rbp,%rdx
call   1050 <fprintf@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"Can not open file %s\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @count_sources(i8* %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 %7, label %4
4: ; preds = %1
%5 = tail call i32 @feof(i32* %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %12, label %20
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %4, %12
%13 = phi i32 [ %17, %12 ], [ 0, %4 ]
%14 = tail call i32 @fgetc(i32* %2)
%15 = icmp eq i32 %14, 10
%16 = zext i1 %15 to i32
%17 = add nuw nsw i32 %13, %16
%18 = tail call i32 @feof(i32* %2)
%19 = icmp eq i32 %18, 0
br i1 %19, label %12, label %20
20: ; preds = %12, %4
%21 = phi i32 [ 0, %4 ], [ %17, %12 ]
%22 = tail call i32 @fclose(i32* %2)
ret i32 %21
}