#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 /*<<< orphan*/ putchar(int);
main() {
  int c;
  char end = EOF;
  printf("ctrl-d to exit\n");
  while ((c = getchar()) != EOF) {
    putchar(c);
  }
  printf("Printing EOF:\nRight here> %c\n", end);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%eax
mov    %al,-0x9(%rbp)
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%eax
je     117f <main+0x4f>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
jmp    1159 <main+0x29>
movsbl -0x9(%rbp),%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e9e(%rip),%rbx
mov    (%rbx),%ebp
lea    0xecb(%rip),%rdi
call   1040 <puts@plt>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    (%rbx),%eax
je     1174 <main+0x34>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1160 <main+0x20>
movsbl %bpl,%esi
lea    0xe81(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [16 x i8] c"ctrl-d to exit\0A\00"
@.str.1 = [30 x i8] c"Printing EOF:\0ARight here> %c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
store i32 0, i32* %1
%4 = load i32, i32* @EOF
%5 = trunc i32 %4 to i8
store i8 %5, i8* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %11, %0
%8 = call i32 (...) @getchar()
store i32 %8, i32* %2
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32, i32* %2
%13 = call i32 @putchar(i32 %12)
br label %7
14: ; preds = %7
%15 = load i8, i8* %3
%16 = sext i8 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@EOF = global i32 0
@.str.1 = [30 x i8] c"Printing EOF:\0ARight here> %c\0A\00"
@str = [15 x i8] c"ctrl-d to exit\00"
define i32 @main() {
%1 = load i32, i32* @EOF
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (...) @getchar()
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %12, label %6
6: ; preds = %0, %6
%7 = phi i32 [ %9, %6 ], [ %3, %0 ]
%8 = tail call i32 @putchar(i32 %7)
%9 = tail call i32 (...) @getchar()
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %6
12: ; preds = %6, %0
%13 = shl i32 %1, 24
%14 = ashr exact i32 %13, 24
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %14)
ret i32 0
}