#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*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ alarm(int);
int /*<<< orphan*/ err_sys(char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main(int argc, char **argv) {
  int n;
  char line[4096];
  alarm(10);
  if ((n = read(STDIN_FILENO, line, 4096)) < 0) {
    err_sys("read error");
  }
  alarm(0);
  write(STDOUT_FILENO, line, n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xa,%edi
call   1050 <alarm@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1195 <main+0x55>
lea    0xe70(%rip),%rdi
call   1030 <err_sys@plt>
xor    %edi,%edi
call   1050 <alarm@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <write@plt>
xor    %eax,%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x1000,%rsp
mov    $0xa,%edi
call   1050 <alarm@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    117a <main+0x3a>
lea    0xe8b(%rip),%rdi
call   1030 <err_sys@plt>
xor    %edi,%edi
call   1050 <alarm@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    %ebx,%edx
call   1040 <write@plt>
xor    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@.str = [11 x i8] c"read error\00"
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @alarm(i32 10)
%9 = load i32, i32* @STDIN_FILENO
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%11 = call i32 @read(i32 %9, i8* %10, i32 4096)
store i32 %11, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = call i32 @alarm(i32 0)
%17 = load i32, i32* @STDOUT_FILENO
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%19 = load i32, i32* %6
%20 = call i32 @write(i32 %17, i8* %18, i32 %19)
ret i32 0
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@.str = [11 x i8] c"read error\00"
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @alarm(i32 10)
%6 = load i32, i32* @STDIN_FILENO
%7 = call i32 @read(i32 %6, i8* %4, i32 4096)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = tail call i32 @alarm(i32 0)
%13 = load i32, i32* @STDOUT_FILENO
%14 = call i32 @write(i32 %13, i8* %4, i32 %7)
ret i32 0
}