#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 */
size_t read(int /*<<< orphan*/, char **, int);
size_t write(int, char *, int);
int main() {
  char buf[128];
  size_t nread = read(0, &buf, sizeof(buf));
  if (nread == -1)
    write(2, "read error", 20);
  if (write(1, buf, nread) != nread)
    write(2, "write error", 20);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x90(%rbp),%rsi
xor    %edi,%edi
mov    $0x80,%edx
call   1040 <read@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0xffffffffffffffff,-0x98(%rbp)
ff
jne    1170 <main+0x50>
mov    $0x2,%edi
lea    0xe9a(%rip),%rsi
mov    $0x14,%edx
call   1030 <write@plt>
lea    -0x90(%rbp),%rsi
mov    -0x98(%rbp),%rax
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
cmp    -0x98(%rbp),%rax
je     11ad <main+0x8d>
mov    $0x2,%edi
lea    0xe68(%rip),%rsi
mov    $0x14,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x80,%edx
call   1040 <read@plt>
mov    %rax,%rbx
cmp    $0xffffffffffffffff,%rax
jne    1156 <main+0x36>
lea    0xeb9(%rip),%rsi
mov    $0x2,%edi
mov    $0x14,%edx
call   1030 <write@plt>
mov    %rsp,%rsi
mov    $0x1,%edi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    %rbx,%rax
je     1180 <main+0x60>
lea    0xe9a(%rip),%rsi
mov    $0x2,%edi
mov    $0x14,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"read error\00"
@.str.1 = [12 x i8] c"write error\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = bitcast [128 x i8]* %1 to i8**
%4 = call i64 @read(i32 0, i8** %3, i32 128)
%5 = icmp eq i64 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i64 @write(i32 2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 20)
br label %8
8: ; preds = %6, %0
%9 = trunc i64 %4 to i32
%10 = call i64 @write(i32 1, i8* %2, i32 %9)
%11 = icmp eq i64 %10, %4
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i64 @write(i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 20)
br label %14
14: ; preds = %12, %8
ret i32 0
}