#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(int);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int findNcameras(FILE *fp) {
  int lineno, ncams, ch;
  lineno = ncams = 0;
  while (!feof(fp)) {
    if ((ch = fgetc(fp)) == '#') {
      {
        char buf[2048];
        while (!feof(fp))
          if (!fgets(buf, 2048 - 1, fp) || buf[strlen(buf) - 1] == '\n')
            break;
      };
      ++lineno;
      continue;
    }
    if (feof(fp))
      break;
    ungetc(ch, fp);
    {
      char buf[2048];
      while (!feof(fp))
        if (!fgets(buf, 2048 - 1, fp) || buf[strlen(buf) - 1] == '\n')
          break;
    };
    ++lineno;
    if (ferror(fp)) {
      fprintf(stderr, "findNcameras(): error reading input file, line %d\n",
              lineno);
      exit(1);
    }
    ++ncams;
  }
  return ncams;
}


x86 assembly (clang, -O0):
<findNcameras>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11bc <findNcameras+0x3c>
jmp    1326 <findNcameras+0x1a6>
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x23,%eax
jne    124d <findNcameras+0xcd>
jmp    11d6 <findNcameras+0x56>
mov    -0x8(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f5 <findNcameras+0x75>
jmp    123f <findNcameras+0xbf>
lea    -0x820(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x7ff,%esi
call   1060 <fgets@plt>
cmp    $0x0,%eax
je     1235 <findNcameras+0xb5>
lea    -0x820(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x820(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    123a <findNcameras+0xba>
jmp    123f <findNcameras+0xbf>
jmp    11d6 <findNcameras+0x56>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119d <findNcameras+0x1d>
mov    -0x8(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     1265 <findNcameras+0xe5>
jmp    1326 <findNcameras+0x1a6>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1090 <ungetc@plt>
mov    -0x8(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1290 <findNcameras+0x110>
jmp    12da <findNcameras+0x15a>
lea    -0x1020(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x7ff,%esi
call   1060 <fgets@plt>
cmp    $0x0,%eax
je     12d0 <findNcameras+0x150>
lea    -0x1020(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x1020(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    12d5 <findNcameras+0x155>
jmp    12da <findNcameras+0x15a>
jmp    1271 <findNcameras+0xf1>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1318 <findNcameras+0x198>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xcf7(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119d <findNcameras+0x1d>
mov    -0x10(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findNcameras>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %rdi,%rbx
call   1080 <feof@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11b2 <findNcameras+0x32>
mov    %r14d,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r15d,%r15d
mov    %rsp,%rbp
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    $0x23,%eax
jne    1215 <findNcameras+0x95>
nopl   (%rax)
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %rax,%rax
jne    1202 <findNcameras+0x82>
mov    %rbp,%rdi
mov    $0x7ff,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %eax,%eax
je     1202 <findNcameras+0x82>
mov    %rbp,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbp,1)
jne    11d0 <findNcameras+0x50>
add    $0x1,%r15d
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %rax,%rax
je     11c0 <findNcameras+0x40>
jmp    119f <findNcameras+0x1f>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %rax,%rax
jne    119f <findNcameras+0x1f>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1090 <ungetc@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %rax,%rax
jne    1272 <findNcameras+0xf2>
mov    %rbp,%rdi
mov    $0x7ff,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %eax,%eax
je     1272 <findNcameras+0xf2>
mov    %rbp,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbp,1)
jne    1240 <findNcameras+0xc0>
add    $0x1,%r15d
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    128c <findNcameras+0x10c>
add    $0x1,%r14d
jmp    1206 <findNcameras+0x86>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    0xd64(%rip),%rsi
mov    %r15d,%edx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [51 x i8] c"findNcameras(): error reading input file, line %d\0A\00"
define i32 @findNcameras(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2048 x i8]
%7 = alloca [2048 x i8]
store i32* %0, i32** %2
store i32 0, i32* %4
store i32 0, i32* %3
br label %8
8: ; preds = %83, %39, %1
%9 = load i32*, i32** %2
%10 = call i64 @feof(i32* %9)
%11 = icmp ne i64 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %86
13: ; preds = %8
%14 = load i32*, i32** %2
%15 = call i32 @fgetc(i32* %14)
store i32 %15, i32* %5
%16 = icmp eq i32 %15, 35
br i1 %16, label %17, label %42
17: ; preds = %13
br label %18
18: ; preds = %38, %17
%19 = load i32*, i32** %2
%20 = call i64 @feof(i32* %19)
%21 = icmp ne i64 %20, 0
%22 = xor i1 %21, true
br i1 %22, label %23, label %39
23: ; preds = %18
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%25 = load i32*, i32** %2
%26 = call i32 @fgets(i8* %24, i32 2047, i32* %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %23
%29 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 10
br i1 %36, label %37, label %38
37: ; preds = %28, %23
br label %39
38: ; preds = %28
br label %18
39: ; preds = %37, %18
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %8
42: ; preds = %13
%43 = load i32*, i32** %2
%44 = call i64 @feof(i32* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
br label %86
47: ; preds = %42
%48 = load i32, i32* %5
%49 = load i32*, i32** %2
%50 = call i32 @ungetc(i32 %48, i32* %49)
br label %51
51: ; preds = %71, %47
%52 = load i32*, i32** %2
%53 = call i64 @feof(i32* %52)
%54 = icmp ne i64 %53, 0
%55 = xor i1 %54, true
br i1 %55, label %56, label %72
56: ; preds = %51
%57 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%58 = load i32*, i32** %2
%59 = call i32 @fgets(i8* %57, i32 2047, i32* %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %70
61: ; preds = %56
%62 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%63 = call i32 @strlen(i8* %62)
%64 = sub nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 %65
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 10
br i1 %69, label %70, label %71
70: ; preds = %61, %56
br label %72
71: ; preds = %61
br label %51
72: ; preds = %70, %51
%73 = load i32, i32* %3
%74 = add nsw i32 %73, 1
store i32 %74, i32* %3
%75 = load i32*, i32** %2
%76 = call i64 @ferror(i32* %75)
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %83
78: ; preds = %72
%79 = load i32, i32* @stderr
%80 = load i32, i32* %3
%81 = call i32 @fprintf(i32 %79, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %80)
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %72
%84 = load i32, i32* %4
%85 = add nsw i32 %84, 1
store i32 %85, i32* %4
br label %8
86: ; preds = %46, %8
%87 = load i32, i32* %4
ret i32 %87
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [51 x i8] c"findNcameras(): error reading input file, line %d\0A\00"
define i32 @findNcameras(i32* nocapture %0) {
%2 = alloca [2048 x i8]
%3 = alloca [2048 x i8]
%4 = call i64 @feof(i32* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %64
6: ; preds = %1
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
br label %9
9: ; preds = %6, %60
%10 = phi i32 [ 0, %6 ], [ %53, %60 ]
%11 = phi i32 [ 0, %6 ], [ %61, %60 ]
br label %12
12: ; preds = %9, %30
%13 = phi i32 [ %10, %9 ], [ %31, %30 ]
%14 = call i32 @fgetc(i32* %0)
%15 = icmp eq i32 %14, 35
br i1 %15, label %16, label %34
16: ; preds = %12
br label %17
17: ; preds = %23, %16
%18 = call i64 @feof(i32* %0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %17
%21 = call i32 @fgets(i8* %7, i32 2047, i32* %0)
%22 = icmp eq i32 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %20
%24 = call i32 @strlen(i8* %7)
%25 = add nsw i32 %24, -1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 10
br i1 %29, label %30, label %17
30: ; preds = %20, %23, %17
%31 = add nsw i32 %13, 1
%32 = call i64 @feof(i32* %0)
%33 = icmp eq i64 %32, 0
br i1 %33, label %12, label %64
34: ; preds = %12
%35 = call i64 @feof(i32* %0)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %64
37: ; preds = %34
%38 = call i32 @ungetc(i32 %14, i32* %0)
br label %39
39: ; preds = %45, %37
%40 = call i64 @feof(i32* %0)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %52
42: ; preds = %39
%43 = call i32 @fgets(i8* %8, i32 2047, i32* %0)
%44 = icmp eq i32 %43, 0
br i1 %44, label %52, label %45
45: ; preds = %42
%46 = call i32 @strlen(i8* %8)
%47 = add nsw i32 %46, -1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = icmp eq i8 %50, 10
br i1 %51, label %52, label %39
52: ; preds = %42, %45, %39
%53 = add nsw i32 %13, 1
%54 = call i64 @ferror(i32* %0)
%55 = icmp eq i64 %54, 0
br i1 %55, label %60, label %56
56: ; preds = %52
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %53)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %52
%61 = add nuw nsw i32 %11, 1
%62 = call i64 @feof(i32* %0)
%63 = icmp eq i64 %62, 0
br i1 %63, label %9, label %64
64: ; preds = %34, %60, %30, %1
%65 = phi i32 [ 0, %1 ], [ %11, %30 ], [ %61, %60 ], [ %11, %34 ]
ret i32 %65
}