#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*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ read(int, char *, int);
scalar_t__ write(int, char *, int);
main() {
  char tab[10];
  if (read(1, tab, 5) < 0) {
    perror("read");
  }
  if (write(10, tab, 5) < 0) {
    perror("write 1");
  }
  write(0, "\n", 1);
  if (write(0, "xxxxx", 2) < 0) {
    perror("write 0");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xe(%rbp),%rsi
mov    $0x1,%edi
mov    $0x5,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jge    1178 <main+0x38>
lea    0xe8d(%rip),%rdi
call   1060 <perror@plt>
lea    -0xe(%rbp),%rsi
mov    $0xa,%edi
mov    $0x5,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11a1 <main+0x61>
lea    0xe69(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
lea    0xe63(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %edi,%edi
lea    0xe52(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11dd <main+0x9d>
lea    0xe3d(%rip),%rdi
call   1060 <perror@plt>
lea    0xe29(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xe(%rsp),%rsi
mov    $0x1,%edi
mov    $0x5,%edx
call   1050 <read@plt>
test   %rax,%rax
js     11b2 <main+0x72>
lea    0xe(%rsp),%rsi
mov    $0xa,%edi
mov    $0x5,%edx
call   1040 <write@plt>
test   %rax,%rax
js     11c0 <main+0x80>
lea    0xe90(%rip),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1040 <write@plt>
lea    0xe7f(%rip),%rsi
xor    %edi,%edi
mov    $0x2,%edx
call   1040 <write@plt>
test   %rax,%rax
js     11ce <main+0x8e>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xe47(%rip),%rdi
call   1060 <perror@plt>
jmp    115d <main+0x1d>
lea    0xe3e(%rip),%rdi
call   1060 <perror@plt>
jmp    1176 <main+0x36>
lea    0xe40(%rip),%rdi
call   1060 <perror@plt>
jmp    11a1 <main+0x61>

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

LLVM IR (-O2):
@.str = [5 x i8] c"read\00"
@.str.1 = [8 x i8] c"write 1\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [6 x i8] c"xxxxx\00"
@.str.4 = [8 x i8] c"write 0\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = call i64 @read(i32 1, i8* %2, i32 5)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = call i64 @write(i32 10, i8* %2, i32 5)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = tail call i64 @write(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%14 = tail call i64 @write(i32 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 2)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = tail call i32 @putchar(i32 10)
ret i32 0
}