#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 */
scalar_t__ EOF;
scalar_t__ getchar();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  long nc;
  nc = 0;
  printf("Input character:\n");
  while (getchar() != EOF) {
    ++nc;
    printf("When done press ctrl+D on linux or ctrl+Z on win to end.\n");
  }
  printf("%ld\n", nc);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    0x2e95(%rip),%rcx
cmp    (%rcx),%rax
je     117b <main+0x5b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1145 <main+0x25>
mov    -0x10(%rbp),%rsi
lea    0xec6(%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    0xec9(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e97(%rip),%r15
cmp    (%r15),%rax
je     1178 <main+0x48>
lea    0xeb9(%rip),%r14
xor    %ebx,%ebx
nop
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r15),%rax
jne    1160 <main+0x30>
lea    0xe81(%rip),%rdi
mov    %rbx,%rsi
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 i64 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 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %2
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %8, %0
%5 = call i64 (...) @getchar()
%6 = load i64, i64* @EOF
%7 = icmp ne i64 %5, %6
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = load i64, i64* %2
%10 = add nsw i64 %9, 1
store i64 %10, i64* %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
br label %4
12: ; preds = %4
%13 = load i64, i64* %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %13)
%15 = load i32, i32* %1
ret i32 %15
}

LLVM IR (-O2):
@EOF = global i64 0
@.str.2 = [5 x i8] c"%ld\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 i64 (...) @getchar()
%3 = load i64, i64* @EOF
%4 = icmp eq i64 %2, %3
br i1 %4, label %12, label %5
5: ; preds = %0, %5
%6 = phi i64 [ %7, %5 ], [ 0, %0 ]
%7 = add nuw nsw i64 %6, 1
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.3, i64 0, i64 0))
%9 = tail call i64 (...) @getchar()
%10 = load i64, i64* @EOF
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %5
12: ; preds = %5, %0
%13 = phi i64 [ 0, %0 ], [ %7, %5 ]
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %13)
ret i32 0
}