#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 */
char EOF;
char getchar();
int /*<<< orphan*/ printf(char *, long);
int main(void) {
  char c;
  long number_of_lines = 0;
  while ((c = getchar()) != EOF) {
    if (c == '\n') {
      ++number_of_lines;
    }
  }
  printf("The number of line in the text stream is: %ld", number_of_lines);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
mov    0x2e9d(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1174 <main+0x54>
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
jne    116f <main+0x4f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1137 <main+0x17>
mov    -0x10(%rbp),%rsi
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2eb4(%rip),%r14
cmp    (%r14),%al
je     1156 <main+0x36>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %rcx,%rbx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    (%r14),%al
jne    1140 <main+0x20>
lea    0xea3(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EOF = global i8 0
@.str = [46 x i8] c"The number of line in the text stream is: %ld\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %3
br label %4
4: ; preds = %17, %0
%5 = call signext i8 (...) @getchar()
store i8 %5, i8* %2
%6 = sext i8 %5 to i32
%7 = load i8, i8* @EOF
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %6, %8
br i1 %9, label %10, label %18
10: ; preds = %4
%11 = load i8, i8* %2
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 10
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i64, i64* %3
%16 = add nsw i64 %15, 1
store i64 %16, i64* %3
br label %17
17: ; preds = %14, %10
br label %4
18: ; preds = %4
%19 = load i64, i64* %3
%20 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i64 %19)
ret i32 0
}

LLVM IR (-O2):
@EOF = global i8 0
@.str = [46 x i8] c"The number of line in the text stream is: %ld\00"
define i32 @main() {
%1 = tail call signext i8 (...) @getchar()
%2 = load i8, i8* @EOF
%3 = icmp eq i8 %1, %2
br i1 %3, label %13, label %4
4: ; preds = %0, %4
%5 = phi i8 [ %10, %4 ], [ %1, %0 ]
%6 = phi i64 [ %9, %4 ], [ 0, %0 ]
%7 = icmp eq i8 %5, 10
%8 = zext i1 %7 to i64
%9 = add nuw nsw i64 %6, %8
%10 = tail call signext i8 (...) @getchar()
%11 = load i8, i8* @EOF
%12 = icmp eq i8 %10, %11
br i1 %12, label %13, label %4
13: ; preds = %4, %0
%14 = phi i64 [ 0, %0 ], [ %9, %4 ]
%15 = tail call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i64 %14)
ret i32 0
}