#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() {
  double characters_count;
  int last_character;
  printf("Input character:\n");
  for (characters_count; (last_character = getchar()) != EOF;
       ++characters_count) {
    if (last_character != '\n') {
      printf("When done press ctrl+D on linux or ctrl+Z on win to end.\n");
    }
  }
  printf("%.0f\n", characters_count);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e9a(%rip),%rcx
cmp    (%rcx),%eax
je     118a <main+0x6a>
cmpl   $0xa,-0x14(%rbp)
je     116e <main+0x4e>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1173 <main+0x53>
movsd  0xe85(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    113d <main+0x1d>
movsd  -0x10(%rbp),%xmm0
lea    0xebe(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e9a(%rip),%rbx
lea    0xeca(%rip),%r14
jmp    117d <main+0x4d>
nopw   0x0(%rax,%rax,1)
movsd  (%rsp),%xmm0
addsd  0xe93(%rip),%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%rbx),%eax
je     118c <main+0x5c>
cmp    $0xa,%eax
je     1160 <main+0x30>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    1160 <main+0x30>
lea    0xe75(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Input character:\0A\00"
@EOF = global i32 0
@.str.1 = [58 x i8] c"When done press ctrl+D on linux or ctrl+Z on win to end.\0A\00"
@.str.2 = [6 x i8] c"%.0f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%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))
%5 = load double, double* %2
br label %6
6: ; preds = %16, %0
%7 = call i32 (...) @getchar()
store i32 %7, i32* %3
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %19
10: ; preds = %6
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 10
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
br label %16
16: ; preds = %15
%17 = load double, double* %2
%18 = fadd double %17, 1.000000e+00
store double %18, double* %2
br label %6
19: ; preds = %6
%20 = load double, double* %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %20)
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@EOF = global i32 0
@.str.2 = [6 x i8] c"%.0f\0A\00"
@str = [17 x i8] c"Input character:\00"
@str.3 = [57 x i8] c"When done press ctrl+D on linux or ctrl+Z on win to end.\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, %11
%6 = phi i32 [ %13, %11 ], [ %2, %0 ]
%7 = phi double [ %12, %11 ], [ undef, %0 ]
%8 = icmp eq i32 %6, 10
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.3, i64 0, i64 0))
br label %11
11: ; preds = %5, %9
%12 = fadd double %7, 1.000000e+00
%13 = tail call i32 (...) @getchar()
%14 = load i32, i32* @EOF
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %5
16: ; preds = %11
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %12)
ret i32 0
}