#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 errno;
int /*<<< orphan*/ printf(char *, int, char *);
int readn(int /*<<< orphan*/, char *, int);
char *strerror(int);
int write(int /*<<< orphan*/, char *, int);
int main() {
  int nread;
  int ntoread;
  int nwrite;
  int ntowrite;
  char buf[1024];
  ntoread = 10;
  if ((nread = readn(STDIN_FILENO, buf, ntoread)) < 0) {
    printf("readn error[%d][%s]\n", errno, strerror(errno));
    return -1;
  }
  ntowrite = ntoread;
  if ((nwrite = write(STDOUT_FILENO, buf, ntowrite)) < 0) {
    printf("readn error[%d][%s]\n", errno, strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0xc(%rbp)
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <readn@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11bb <main+0x7b>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x424(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x424(%rbp),%esi
mov    %rax,%rdx
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122a <main+0xea>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    1223 <main+0xe3>
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x428(%rbp),%esi
mov    %rax,%rdx
lea    0xdee(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122a <main+0xea>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1050 <readn@plt>
test   %eax,%eax
js     1180 <main+0x40>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <write@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jns    11a6 <main+0x66>
mov    0x2e51(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1060 <strerror@plt>
lea    0xe69(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x400,%rsp
pop    %rbx
ret

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

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