#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 /*<<< orphan*/ errx(int, char *);
scalar_t__ ferror(int /*<<< orphan*/);
int fread(char *, int, int, int /*<<< orphan*/);
int fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(void) {
  char buf;
  while (fread(&buf, 1, 1, stdin) == 1)
    if (fwrite(&buf, 1, 1, stdout) != 1)
      errx(1, "Write error");
  if (ferror(stdin))
    errx(1, "Read error");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%ecx
lea    -0x5(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    11a9 <main+0x69>
mov    0x2e60(%rip),%rax
mov    (%rax),%ecx
lea    -0x5(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1060 <fwrite@plt>
cmp    $0x1,%eax
je     11a4 <main+0x64>
mov    $0x1,%edi
lea    0xe61(%rip),%rsi
call   1050 <errx@plt>
jmp    114f <main+0xf>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11d2 <main+0x92>
mov    $0x1,%edi
lea    0xe3f(%rip),%rsi
call   1050 <errx@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e99(%rip),%r15
mov    (%r15),%ecx
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    11c4 <main+0x84>
mov    0x2e66(%rip),%r12
lea    0x7(%rsp),%rbx
lea    0xe82(%rip),%r14
jmp    119a <main+0x5a>
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    11c4 <main+0x84>
mov    (%r12),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
cmp    $0x1,%eax
je     1180 <main+0x40>
mov    $0x1,%edi
mov    %r14,%rsi
call   1050 <errx@plt>
jmp    1180 <main+0x40>
mov    (%r15),%edi
call   1030 <ferror@plt>
test   %rax,%rax
je     11e2 <main+0xa2>
lea    0xe34(%rip),%rsi
mov    $0x1,%edi
call   1050 <errx@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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