#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(int argc, char **argv) {
  long lCharCount = 0;
  char cChar = 0;
  cChar = getchar();
  while (cChar != EOF) {
    lCharCount++;
    cChar = getchar();
  }
  printf("There have %d character.\n", lCharCount);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
mov    0x2e91(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     117d <main+0x5d>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x19(%rbp)
jmp    114c <main+0x2c>
mov    -0x18(%rbp),%rsi
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%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     1150 <main+0x30>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    (%r14),%al
jne    1140 <main+0x20>
lea    0xea9(%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 = [26 x i8] c"There have %d character.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
store i8 0, i8* %7
%8 = call signext i8 (...) @getchar()
store i8 %8, i8* %7
br label %9
9: ; preds = %15, %2
%10 = load i8, i8* %7
%11 = sext i8 %10 to i32
%12 = load i8, i8* @EOF
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %11, %13
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = load i64, i64* %6
%17 = add nsw i64 %16, 1
store i64 %17, i64* %6
%18 = call signext i8 (...) @getchar()
store i8 %18, i8* %7
br label %9
19: ; preds = %9
%20 = load i64, i64* %6
%21 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %20)
ret i32 0
}

LLVM IR (-O2):
@EOF = global i8 0
@.str = [26 x i8] c"There have %d character.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call signext i8 (...) @getchar()
%4 = load i8, i8* @EOF
%5 = icmp eq i8 %3, %4
br i1 %5, label %12, label %6
6: ; preds = %2, %6
%7 = phi i64 [ %8, %6 ], [ 0, %2 ]
%8 = add nuw nsw i64 %7, 1
%9 = tail call signext i8 (...) @getchar()
%10 = load i8, i8* @EOF
%11 = icmp eq i8 %9, %10
br i1 %11, label %12, label %6
12: ; preds = %6, %2
%13 = phi i64 [ 0, %2 ], [ %8, %6 ]
%14 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %13)
ret i32 0
}