#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 EXIT_SUCCESS;
int getchar();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ putchar(int);
int main() {
  int ch;
  int line;
  int at_beginning;
  line = 0;
  at_beginning = 1;
  while ((ch = getchar()) != EOF) {
    if (at_beginning == 1) {
      at_beginning = 0;
      line += 1;
      printf("%d ", line);
    }
    putchar(ch);
    if (ch == '\n')
      at_beginning = 1;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e8a(%rip),%rcx
cmp    (%rcx),%eax
je     11ad <main+0x7d>
cmpl   $0x1,-0x10(%rbp)
jne    118f <main+0x5f>
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
cmpl   $0xa,-0x8(%rbp)
jne    11a8 <main+0x78>
movl   $0x1,-0x10(%rbp)
jmp    114d <main+0x1d>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2ea2(%rip),%r15
cmp    (%r15),%eax
jne    115d <main+0x2d>
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
mov    $0x1,%ebx
lea    0xe95(%rip),%r14
xor    %r12d,%r12d
jmp    118d <main+0x5d>
mov    %ebp,%edi
call   1030 <putchar@plt>
xor    %ebx,%ebx
cmp    $0xa,%ebp
sete   %bl
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
je     114b <main+0x1b>
cmp    $0x1,%ebx
jne    1170 <main+0x40>
add    $0x1,%r12d
mov    %r14,%rdi
mov    %r12d,%esi
call   1040 <printf@plt>
jmp    1170 <main+0x40>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [4 x i8] c"%d \00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 1, i32* %4
br label %5
5: ; preds = %23, %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 %24
9: ; preds = %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %9
store i32 0, i32* %4
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %12, %9
%18 = load i32, i32* %2
%19 = call i32 @putchar(i32 %18)
%20 = load i32, i32* %2
%21 = icmp eq i32 %20, 10
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 1, i32* %4
br label %23
23: ; preds = %22, %17
br label %5
24: ; preds = %5
%25 = load i32, i32* @EXIT_SUCCESS
ret i32 %25
}

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