#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 BUFSIZ;
int /*<<< orphan*/ errexit(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int read(int, char *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
scalar_t__ write(int, char *, int);
int TCPechod(int fd) {
  char buf[BUFSIZ];
  int cc;
  while (cc = read(fd, buf, sizeof buf)) {
    if (cc < 0)
      errexit("echo read: %s\n", strerror(errno));
    if (write(fd, buf, cc) < 0)
      errexit("echo write: %s\n", strerror(errno));
  }
  return 0;
}


x86 assembly (clang, -O0):
<TCPechod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x30(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    -0x4(%rbp),%edi
mov    %eax,%edx
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     11f9 <TCPechod+0xb9>
cmpl   $0x0,-0x1c(%rbp)
jge    11bf <TCPechod+0x7f>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%esi
lea    0xe46(%rip),%rdi
call   1050 <errexit@plt>
mov    -0x28(%rbp),%rsi
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11f4 <TCPechod+0xb4>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%esi
lea    0xe20(%rip),%rdi
call   1050 <errexit@plt>
jmp    117b <TCPechod+0x3b>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TCPechod>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
mov    0x2e88(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <read@plt>
test   %eax,%eax
je     11ed <TCPechod+0xad>
mov    %eax,%r12d
mov    0x2e50(%rip),%r13
jmp    11a5 <TCPechod+0x65>
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <read@plt>
mov    %eax,%r12d
test   %eax,%eax
je     11ed <TCPechod+0xad>
test   %r12d,%r12d
jns    11c1 <TCPechod+0x81>
mov    0x0(%r13),%edi
call   1060 <strerror@plt>
lea    0xe46(%rip),%rdi
mov    %eax,%esi
call   1050 <errexit@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <write@plt>
test   %rax,%rax
jns    1190 <TCPechod+0x50>
mov    0x0(%r13),%edi
call   1060 <strerror@plt>
lea    0xe2b(%rip),%rdi
mov    %eax,%esi
call   1050 <errexit@plt>
jmp    1190 <TCPechod+0x50>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [15 x i8] c"echo read: %s\0A\00"
@errno = global i32 0
@.str.1 = [16 x i8] c"echo write: %s\0A\00"
define i32 @TCPechod(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* @BUFSIZ
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %3
%9 = alloca i8, i64 %7
store i64 %7, i64* %4
br label %10
10: ; preds = %31, %1
%11 = load i32, i32* %2
%12 = trunc i64 %7 to i32
%13 = call i32 @read(i32 %11, i8* %9, i32 %12)
store i32 %13, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %32
15: ; preds = %10
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* @errno
%20 = call i32 @strerror(i32 %19)
%21 = call i32 @errexit(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %15
%23 = load i32, i32* %2
%24 = load i32, i32* %5
%25 = call i64 @write(i32 %23, i8* %9, i32 %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i32, i32* @errno
%29 = call i32 @strerror(i32 %28)
%30 = call i32 @errexit(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %27, %22
br label %10
32: ; preds = %10
%33 = load i8*, i8** %3
ret i32 0
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [15 x i8] c"echo read: %s\0A\00"
@errno = global i32 0
@.str.1 = [16 x i8] c"echo write: %s\0A\00"
define i32 @TCPechod(i32 %0) {
%2 = load i32, i32* @BUFSIZ
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i32 @read(i32 %0, i8* %4, i32 %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %24, label %7
7: ; preds = %1, %21
%8 = phi i32 [ %22, %21 ], [ %5, %1 ]
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i32, i32* @errno
%12 = tail call i32 @strerror(i32 %11)
%13 = tail call i32 @errexit(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %10, %7
%15 = call i64 @write(i32 %0, i8* %4, i32 %8)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* @errno
%19 = tail call i32 @strerror(i32 %18)
%20 = tail call i32 @errexit(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %17, %14
%22 = call i32 @read(i32 %0, i8* %4, i32 %2)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %7
24: ; preds = %21, %1
ret i32 0
}