#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;
int EXIT_SUCCESS;
char getchar();
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  char c;
  int count = 0;
  while (c != EOF) {
    c = getchar();
    count++;
  }
  printf("you entered EOF! EOF is %d\n", EOF);
  printf("you entered %d characters\n", count);
  return EXIT_SUCCESS;
}


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)
movl   $0x0,-0x18(%rbp)
movsbl -0x11(%rbp),%eax
mov    0x2ea0(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     116b <main+0x4b>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x11(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113d <main+0x1d>
mov    0x2e76(%rip),%rax
movsbl (%rax),%esi
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2ebd(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
add    $0x1,%ebx
cmp    (%r14),%al
jne    1130 <main+0x10>
movsbl %al,%esi
lea    0xeb7(%rip),%rdi
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EOF = global i8 0
@.str = [28 x i8] c"you entered EOF! EOF is %d\0A\00"
@.str.1 = [27 x i8] c"you entered %d characters\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %8
8: ; preds = %14, %2
%9 = load i8, i8* %6
%10 = sext i8 %9 to i32
%11 = load i8, i8* @EOF
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %10, %12
br i1 %13, label %14, label %18
14: ; preds = %8
%15 = call signext i8 (...) @getchar()
store i8 %15, i8* %6
%16 = load i32, i32* %7
%17 = add nsw i32 %16, 1
store i32 %17, i32* %7
br label %8
18: ; preds = %8
%19 = load i8, i8* @EOF
%20 = sext i8 %19 to i32
%21 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %7
%23 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i32, i32* @EXIT_SUCCESS
ret i32 %24
}

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