#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 /*<<< 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 *);
size_t read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ write(int /*<<< orphan*/, char *, size_t);
int main() {
  size_t len;
  char buffer[100] = {'\0'};
  while ((len = read(STDIN_FILENO, buffer, sizeof(buffer))) > 0) {
    if (write(STDOUT_FILENO, buffer, len) < 0) {
      fprintf(stderr, "write error:%s\n", strerror(errno));
      exit(1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1050 <read@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jbe    1208 <main+0xa8>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1203 <main+0xa3>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x84(%rbp),%edi
mov    %rax,%rdx
lea    0xe0c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1182 <main+0x22>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
mov    0x2e40(%rip),%r14
mov    %rsp,%rbx
mov    0x2e5e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14),%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1040 <read@plt>
test   %rax,%rax
je     11fa <main+0xaa>
mov    (%r15),%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
test   %rax,%rax
jns    11a0 <main+0x50>
mov    0x2e09(%rip),%rax
mov    (%rax),%ebx
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe1a(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@stderr = global i32 0
@.str = [16 x i8] c"write error:%s\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %7, %0
%4 = load i32, i32* @STDIN_FILENO
%5 = call i64 @read(i32 %4, i8* %2, i32 100)
%6 = icmp eq i64 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %3
%8 = load i32, i32* @STDOUT_FILENO
%9 = call i64 @write(i32 %8, i8* %2, i64 %5)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %3
11: ; preds = %7
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %3
ret i32 0
}