#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*/ error(int);
int /*<<< orphan*/ printf(char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main(void) {
  char buf[100];
  int num = 0;
  if ((num = read(STDIN_FILENO, buf, 10)) == -1) {
    printf("read error");
    error(-1);
  } else {
    write(STDOUT_FILENO, buf, num);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x74(%rbp)
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rsi
mov    $0xa,%edx
call   1050 <read@plt>
mov    %eax,-0x74(%rbp)
cmp    $0xffffffff,%eax
jne    1197 <main+0x57>
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <error@plt>
jmp    11ac <main+0x6c>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rsi
mov    -0x74(%rbp),%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x68,%rsp
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     1174 <main+0x34>
mov    0x2e8a(%rip),%rcx
mov    (%rcx),%edi
mov    %rsp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    118a <main+0x4a>
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <error@plt>
xor    %eax,%eax
add    $0x68,%rsp
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() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%4 = load i32, i32* @STDIN_FILENO
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = call i32 @read(i32 %4, i8* %5, i32 10)
store i32 %6, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @error(i32 -1)
br label %16
11: ; preds = %0
%12 = load i32, i32* @STDOUT_FILENO
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%14 = load i32, i32* %3
%15 = call i32 @write(i32 %12, i8* %13, i32 %14)
br label %16
16: ; preds = %11, %8
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() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @STDIN_FILENO
%4 = call i32 @read(i32 %3, i8* %2, i32 10)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @error(i32 -1)
br label %12
9: ; preds = %0
%10 = load i32, i32* @STDOUT_FILENO
%11 = call i32 @write(i32 %10, i8* %2, i32 %4)
br label %12
12: ; preds = %9, %6
ret i32 0
}