#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*/ buf;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  char buf[16384];
  int n;
  for (;;) {
    n = read(0, buf, sizeof(buf));
    if (n <= 0 && errno == EINTR)
      continue;
    if (n <= 0)
      break;
    write(1, buf, n);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x4010(%rbp),%rsi
xor    %edi,%edi
mov    $0x4000,%edx
call   1040 <read@plt>
mov    %eax,-0x4014(%rbp)
cmpl   $0x0,-0x4014(%rbp)
jg     117e <main+0x5e>
mov    0x2e7a(%rip),%rax
mov    (%rax),%rax
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%rax
jne    117e <main+0x5e>
jmp    1139 <main+0x19>
cmpl   $0x0,-0x4014(%rbp)
jg     1190 <main+0x70>
jmp    11ac <main+0x8c>
lea    -0x4010(%rbp),%rsi
mov    -0x4014(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    1139 <main+0x19>
xor    %eax,%eax
add    $0x4020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x4000,%rsp
mov    %rsp,%rbx
mov    0x2eaa(%rip),%r14
mov    0x2e9b(%rip),%r15
jmp    114f <main+0x2f>
nop
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x4000,%edx
call   1040 <read@plt>
test   %eax,%eax
jg     1140 <main+0x20>
mov    (%r14),%rax
cmp    (%r15),%rax
je     114f <main+0x2f>
xor    %eax,%eax
add    $0x4000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [16384 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %22, %17, %2
%9 = getelementptr inbounds [16384 x i8], [16384 x i8]* %6, i64 0, i64 0
%10 = call i32 @read(i32 0, i8* %9, i32 16384)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp sle i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %13
br label %8
18: ; preds = %13, %8
%19 = load i32, i32* %7
%20 = icmp sle i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18
br label %26
22: ; preds = %18
%23 = getelementptr inbounds [16384 x i8], [16384 x i8]* %6, i64 0, i64 0
%24 = load i32, i32* %7
%25 = call i32 @write(i32 1, i8* %23, i32 %24)
br label %8
26: ; preds = %21
ret i32 0
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [16384 x i8]
%4 = getelementptr inbounds [16384 x i8], [16384 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %14, %2
%6 = call i32 @read(i32 0, i8* %4, i32 16384)
%7 = icmp slt i32 %6, 1
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINTR
%11 = icmp eq i64 %9, %10
br i1 %11, label %14, label %15
12: ; preds = %5
%13 = call i32 @write(i32 1, i8* %4, i32 %6)
br label %14
14: ; preds = %12, %8
br label %5
15: ; preds = %8
ret i32 0
}