#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*/ error(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ keyword(char *, char *);
int count_seqerrs(char *filename) {
  FILE *fin;
  char line[1024 + 1];
  int nseqerrs;
  if ((fin = fopen(filename, "r")) == NULL) {
    error("Could not open file %s", filename);
    return 0;
  }
  nseqerrs = 0;
  while (fgets(line, 1024 + 1, fin)) {
    if (keyword(line, "SEQ_ERROR")) {
      nseqerrs++;
    }
  }
  fclose(fin);
  return nseqerrs;
}


x86 assembly (clang, -O0):
<count_seqerrs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1199 <count_seqerrs+0x49>
mov    -0x10(%rbp),%rsi
lea    0xe7a(%rip),%rdi
call   1060 <error@plt>
movl   $0x0,-0x4(%rbp)
jmp    1205 <count_seqerrs+0xb5>
movl   $0x0,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x401,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11f3 <count_seqerrs+0xa3>
lea    -0x420(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1050 <keyword@plt>
cmp    $0x0,%rax
je     11ee <count_seqerrs+0x9e>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    11a3 <count_seqerrs+0x53>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x424(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_seqerrs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rbx
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d1 <count_seqerrs+0x81>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x401,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11c7 <count_seqerrs+0x77>
lea    0xe87(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <keyword@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    $0x401,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    11a0 <count_seqerrs+0x50>
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    11e2 <count_seqerrs+0x92>
lea    0xe2a(%rip),%rdi
mov    %rbx,%rsi
call   1060 <error@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"Could not open file %s\00"
@.str.2 = [10 x i8] c"SEQ_ERROR\00"
define i32 @count_seqerrs(i8* %0) {
%2 = alloca [1025 x i8]
%3 = getelementptr inbounds [1025 x i8], [1025 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 %9, label %6
6: ; preds = %1
%7 = call i64 @fgets(i8* %3, i32 1025, i32* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %19, label %11
9: ; preds = %1
%10 = tail call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %22
11: ; preds = %6, %11
%12 = phi i32 [ %16, %11 ], [ 0, %6 ]
%13 = call i64 @keyword(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp ne i64 %13, 0
%15 = zext i1 %14 to i32
%16 = add nuw nsw i32 %12, %15
%17 = call i64 @fgets(i8* %3, i32 1025, i32* %4)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %11
19: ; preds = %11, %6
%20 = phi i32 [ 0, %6 ], [ %16, %11 ]
%21 = call i32 @fclose(i32* %4)
br label %22
22: ; preds = %19, %9
%23 = phi i32 [ 0, %9 ], [ %20, %19 ]
ret i32 %23
}