#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 getchar();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int last_character, newlines_count;
  printf("Input character:\n");
  while ((last_character = getchar()) != EOF) {
    if (last_character == '\n') {
      ++newlines_count;
    }
    printf("i've seen %d lines so far\n", newlines_count);
  }
  printf("There was total of %d lines in your input\n", newlines_count);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e9a(%rip),%rcx
cmp    (%rcx),%eax
je     117f <main+0x5f>
cmpl   $0xa,-0x8(%rbp)
jne    1169 <main+0x49>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    113d <main+0x1d>
mov    -0xc(%rbp),%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
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
lea    0xf0a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
lea    0xeb1(%rip),%r14
mov    0x2e92(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r15),%eax
jne    1160 <main+0x30>
lea    0xe92(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Input character:\0A\00"
@EOF = global i32 0
@.str.1 = [27 x i8] c"i've seen %d lines so far\0A\00"
@.str.2 = [43 x i8] c"There was total of %d lines in your input\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %15, %0
%6 = call i32 (...) @getchar()
store i32 %6, i32* %2
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %6, %7
br i1 %8, label %9, label %18
9: ; preds = %5
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 10
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
br label %15
15: ; preds = %12, %9
%16 = load i32, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %5
18: ; preds = %5
%19 = load i32, i32* %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@EOF = global i32 0
@.str.1 = [27 x i8] c"i've seen %d lines so far\0A\00"
@.str.2 = [43 x i8] c"There was total of %d lines in your input\0A\00"
@str = [17 x i8] c"Input character:\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (...) @getchar()
%3 = load i32, i32* @EOF
%4 = icmp ne i32 %2, %3
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ %12, %5 ], [ %2, %0 ]
%7 = phi i32 [ %10, %5 ], [ undef, %0 ]
%8 = icmp eq i32 %6, 10
%9 = zext i1 %8 to i32
%10 = add nsw i32 %7, %9
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = tail call i32 (...) @getchar()
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %5
15: ; preds = %5
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %10)
ret i32 0
}