#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 */

/* Variables and functions */
int EOF;
int fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, long);
int /*<<< orphan*/ stdin;
main(void) {
  int c;
  long line_count;
  line_count = 0;
  while ((c = fgetc(stdin)) != EOF) {
    if (c == '\n') {
      ++line_count;
    }
  }
  printf("%d\n", line_count);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0x2eaa(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e91(%rip),%rcx
cmp    (%rcx),%eax
je     1172 <main+0x52>
cmpl   $0xa,-0x8(%rbp)
jne    116d <main+0x4d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1137 <main+0x17>
mov    -0x10(%rbp),%rsi
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2ebc(%rip),%r14
mov    (%r14),%edi
call   1040 <fgetc@plt>
mov    0x2ea5(%rip),%r15
cmp    (%r15),%eax
jne    1144 <main+0x24>
xor    %ebx,%ebx
jmp    1168 <main+0x48>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %rcx,%rbx
mov    (%r14),%edi
call   1040 <fgetc@plt>
cmp    (%r15),%eax
jne    1150 <main+0x30>
lea    0xe91(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i32 0
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %3
br label %4
4: ; preds = %15, %0
%5 = load i32, i32* @stdin
%6 = call i32 @fgetc(i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %6, %7
br i1 %8, label %9, label %16
9: ; preds = %4
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 10
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i64, i64* %3
%14 = add nsw i64 %13, 1
store i64 %14, i64* %3
br label %15
15: ; preds = %12, %9
br label %4
16: ; preds = %4
%17 = load i64, i64* %3
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %17)
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = load i32, i32* @stdin
%2 = tail call i32 @fgetc(i32 %1)
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %15, label %5
5: ; preds = %0, %5
%6 = phi i32 [ %12, %5 ], [ %2, %0 ]
%7 = phi i64 [ %10, %5 ], [ 0, %0 ]
%8 = icmp eq i32 %6, 10
%9 = zext i1 %8 to i64
%10 = add nuw nsw i64 %7, %9
%11 = load i32, i32* @stdin
%12 = tail call i32 @fgetc(i32 %11)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %5
15: ; preds = %5, %0
%16 = phi i64 [ 0, %0 ], [ %10, %5 ]
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %16)
ret i32 0
}