#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 *, char);
int /*<<< orphan*/ putchar(char);
void wordCopy() {
  char c;
  while ((c = getchar()) != EOF)
    putchar(c);
  c = getchar() != EOF;
  printf("%d\n", c);
  printf("%d\n", EOF);
}


x86 assembly (clang, -O0):
<wordCopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x1(%rbp)
movsbl %al,%eax
mov    0x2e9c(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1165 <wordCopy+0x35>
movsbl -0x1(%rbp),%edi
call   1030 <putchar@plt>
jmp    1138 <wordCopy+0x8>
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl %al,%eax
mov    0x2e72(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0x1(%rbp)
lea    0xe73(%rip),%rdi
movsbl -0x1(%rbp),%esi
call   1040 <printf@plt>
lea    0xe63(%rip),%rdi
mov    0x2e44(%rip),%rax
movsbl (%rax),%esi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wordCopy>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2ea6(%rip),%rbx
cmp    (%rbx),%al
je     1163 <wordCopy+0x33>
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%rbx),%al
jne    1150 <wordCopy+0x20>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %esi,%esi
cmp    (%rbx),%al
setne  %sil
lea    0xe87(%rip),%r14
mov    %r14,%rdi
call   1040 <printf@plt>
movsbl (%rbx),%esi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>

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

LLVM IR (-O2):
@EOF = global i8 0
@.str = [4 x i8] c"%d\0A\00"
define void @wordCopy() {
%1 = tail call signext i8 (...) @getchar()
%2 = load i8, i8* @EOF
%3 = icmp eq i8 %1, %2
br i1 %3, label %10, label %4
4: ; preds = %0, %4
%5 = phi i8 [ %7, %4 ], [ %1, %0 ]
%6 = tail call i32 @putchar(i8 signext %5)
%7 = tail call signext i8 (...) @getchar()
%8 = load i8, i8* @EOF
%9 = icmp eq i8 %7, %8
br i1 %9, label %10, label %4
10: ; preds = %4, %0
%11 = tail call signext i8 (...) @getchar()
%12 = load i8, i8* @EOF
%13 = icmp ne i8 %11, %12
%14 = zext i1 %13 to i8
%15 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %14)
%16 = load i8, i8* @EOF
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %16)
ret void
}