#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 *, ...);
int main(int argc, char **argv) {
  long lCharCount = 0;
  printf("please input some character:");
  char cChar = getchar();
  for (; cChar != EOF; lCharCount++) {
    cChar = getchar();
  }
  printf("charCount is %ld", 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)
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
mov    0x2e87(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1187 <main+0x67>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1156 <main+0x36>
mov    -0x18(%rbp),%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2ea6(%rip),%r14
cmp    (%r14),%al
je     1160 <main+0x40>
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
add    $0x1,%rbx
cmp    (%r14),%al
jne    1150 <main+0x30>
lea    0xeb6(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [29 x i8] c"please input some character:\00"
@EOF = global i8 0
@.str.1 = [17 x i8] c"charCount is %ld\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
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%9 = call signext i8 (...) @getchar()
store i8 %9, i8* %7
br label %10
10: ; preds = %18, %2
%11 = load i8, i8* %7
%12 = sext i8 %11 to i32
%13 = load i8, i8* @EOF
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %12, %14
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = call signext i8 (...) @getchar()
store i8 %17, i8* %7
br label %18
18: ; preds = %16
%19 = load i64, i64* %6
%20 = add nsw i64 %19, 1
store i64 %20, i64* %6
br label %10
21: ; preds = %10
%22 = load i64, i64* %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 %22)
ret i32 0
}

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