#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 /*<<< orphan*/ exit(int);
scalar_t__ ferror(int /*<<< orphan*/);
int getc(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int putc(int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main() {
  int ch;
  while ((ch = getc(stdin)) != EOF)
    if (putc(ch, stdout) == EOF) {
      perror("putc");
      exit(1);
    }
  if (ferror(stdin)) {
    perror("ferror");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
call   1070 <getc@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%eax
je     11ba <main+0x6a>
mov    -0x8(%rbp),%edi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
call   1040 <putc@plt>
mov    0x2e49(%rip),%rcx
cmp    (%rcx),%eax
jne    11b5 <main+0x65>
lea    0xe5a(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    115f <main+0xf>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11e8 <main+0x98>
lea    0xe2c(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e8c(%rip),%r14
mov    0x2e7d(%rip),%rbx
mov    0x2e66(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    (%r14),%edi
call   1070 <getc@plt>
cmp    (%rbx),%eax
je     11a0 <main+0x50>
mov    (%r15),%esi
mov    %eax,%edi
call   1040 <putc@plt>
cmp    (%rbx),%eax
jne    1170 <main+0x20>
lea    0xe6f(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    (%r14),%edi
call   1030 <ferror@plt>
test   %rax,%rax
jne    11b5 <main+0x65>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe49(%rip),%rdi
jmp    1191 <main+0x41>

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i32 0
@stdout = global i32 0
@.str = [5 x i8] c"putc\00"
@.str.1 = [7 x i8] c"ferror\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %17, %0
%4 = load i32, i32* @stdin
%5 = call i32 @getc(i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* @EOF
%7 = icmp ne i32 %5, %6
br i1 %7, label %8, label %18
8: ; preds = %3
%9 = load i32, i32* %2
%10 = load i32, i32* @stdout
%11 = call i32 @putc(i32 %9, i32 %10)
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %8
br label %3
18: ; preds = %3
%19 = load i32, i32* @stdin
%20 = call i64 @ferror(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
@stdout = global i32 0
@.str = [5 x i8] c"putc\00"
@.str.1 = [7 x i8] c"ferror\00"
define i32 @main() {
br label %1
1: ; preds = %6, %0
%2 = load i32, i32* @stdin
%3 = tail call i32 @getc(i32 %2)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %14, label %6
6: ; preds = %1
%7 = load i32, i32* @stdout
%8 = tail call i32 @putc(i32 %3, i32 %7)
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %1
11: ; preds = %6
%12 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = load i32, i32* @stdin
%16 = tail call i64 @ferror(i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %14
ret i32 0
}