#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 */
typedef int ssize_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int /*<<< orphan*/, char *, int);
int main(int argc, char *argv[]) {
  char buffer[32768];
  ssize_t size_read = read(STDIN_FILENO, buffer, sizeof(buffer));
  if (size_read == -1) {
    fprintf(stderr, "Unable to read from STDIN: %s\n", strerror(errno));
    exit(1);
  }
  if (-1 == write(STDOUT_FILENO, buffer, size_read)) {
    fprintf(stderr, "Unable to write to STDOUT: %s\n", strerror(errno));
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    -0x8010(%rbp),%rsi
mov    $0x8000,%edx
call   1040 <read@plt>
mov    %eax,-0x8014(%rbp)
cmpl   $0xffffffff,-0x8014(%rbp)
jne    11d2 <main+0x82>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8018(%rbp)
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x8018(%rbp),%edi
mov    %rax,%rdx
lea    0xe3d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    -0x8010(%rbp),%rsi
mov    -0x8014(%rbp),%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1238 <main+0xe8>
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x801c(%rbp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x801c(%rbp),%edi
mov    %rax,%rdx
lea    0xdf6(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %eax,%eax
add    $0x8020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x8000,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0x8000,%edx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
je     1196 <main+0x46>
mov    0x2e76(%rip),%rcx
mov    (%rcx),%edi
mov    %rsp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     11b6 <main+0x66>
xor    %eax,%eax
add    $0x8000,%rsp
pop    %rbx
ret
mov    0x2e3b(%rip),%rax
mov    (%rax),%ebx
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe4c(%rip),%rsi
jmp    11d4 <main+0x84>
mov    0x2e1b(%rip),%rax
mov    (%rax),%ebx
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe4b(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Unable to read from STDIN: %s\0A\00"
@errno = global i32 0
@STDOUT_FILENO = global i32 0
@.str.1 = [31 x i8] c"Unable to write to STDOUT: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [32768 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @STDIN_FILENO
%9 = getelementptr inbounds [32768 x i8], [32768 x i8]* %6, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 32768)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i32, i32* @STDOUT_FILENO
%21 = getelementptr inbounds [32768 x i8], [32768 x i8]* %6, i64 0, i64 0
%22 = load i32, i32* %7
%23 = call i32 @write(i32 %20, i8* %21, i32 %22)
%24 = icmp eq i32 -1, %23
br i1 %24, label %25, label %31
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Unable to read from STDIN: %s\0A\00"
@errno = global i32 0
@STDOUT_FILENO = global i32 0
@.str.1 = [31 x i8] c"Unable to write to STDOUT: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [32768 x i8]
%4 = getelementptr inbounds [32768 x i8], [32768 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @STDIN_FILENO
%6 = call i32 @read(i32 %5, i8* %4, i32 32768)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i32, i32* @STDOUT_FILENO
%16 = call i32 @write(i32 %15, i8* %4, i32 %6)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = tail call i8* @strerror(i32 %20)
%22 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %14
ret i32 0
}