#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ strchr(char *, char);
int bib_entries(char *filename) {
  int res = 0;
  char cur_line[255];
  FILE *bib_file = NULL;
  bib_file = fopen(filename, "r");
  if (bib_file != NULL) {
    while (fgets(cur_line, 255, bib_file) != NULL) {
      if (strchr("@", *cur_line)) {
        res += 1;
      }
    }
  }
  fclose(bib_file);
  return res;
}


x86 assembly (clang, -O0):
<bib_entries>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x118(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     11dd <bib_entries+0x9d>
jmp    118b <bib_entries+0x4b>
lea    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rdx
mov    $0xff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11d8 <bib_entries+0x98>
lea    0xe4e(%rip),%rdi
movsbl -0x110(%rbp),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11d3 <bib_entries+0x93>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118b <bib_entries+0x4b>
jmp    11dd <bib_entries+0x9d>
mov    -0x118(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bib_entries>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
test   %rax,%rax
je     11b8 <bib_entries+0x78>
mov    %rsp,%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11b8 <bib_entries+0x78>
xor    %ebp,%ebp
lea    0xe81(%rip),%r14
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%rsp),%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    %r15,%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1190 <bib_entries+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"@\00"
define i32 @bib_entries(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [255 x i8]
%5 = alloca i32*
store i8* %0, i8** %2
store i32 0, i32* %3
store i32* null, i32** %5
%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 ne i32* %8, null
br i1 %9, label %10, label %26
10: ; preds = %1
br label %11
11: ; preds = %24, %10
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%13 = load i32*, i32** %5
%14 = call i32* @fgets(i8* %12, i32 255, i32* %13)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %25
16: ; preds = %11
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%18 = load i8, i8* %17
%19 = call i64 @strchr(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %24
24: ; preds = %21, %16
br label %11
25: ; preds = %11
br label %26
26: ; preds = %25, %1
%27 = load i32*, i32** %5
%28 = call i32 @fclose(i32* %27)
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"@\00"
define i32 @bib_entries(i8* nocapture %0) {
%2 = alloca [255 x i8]
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %18, label %6
6: ; preds = %1
%7 = call i32* @fgets(i8* %3, i32 255, i32* %4)
%8 = icmp eq i32* %7, null
br i1 %8, label %18, label %9
9: ; preds = %6, %9
%10 = phi i32 [ %15, %9 ], [ 0, %6 ]
%11 = load i8, i8* %3
%12 = call i64 @strchr(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8 signext %11)
%13 = icmp ne i64 %12, 0
%14 = zext i1 %13 to i32
%15 = add nuw nsw i32 %10, %14
%16 = call i32* @fgets(i8* %3, i32 255, i32* %4)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %9
18: ; preds = %9, %6, %1
%19 = phi i32 [ 0, %1 ], [ 0, %6 ], [ %15, %9 ]
%20 = call i32 @fclose(i32* %4)
ret i32 %19
}