#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ perror(char *);
scalar_t__ read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ setsid();
scalar_t__ write(int, char *, scalar_t__);
void do_forward(void) {
  char buf[4096], *b;
  ssize_t r, rr;
  setsid();
  while ((r = read(0, buf, sizeof(buf)))) {
    if (r < 0) {
      if (errno == EINTR)
        continue;
      break;
    }
    b = buf;
    while (r > 0) {
      rr = write(1, b, r);
      if (rr < 0) {
        if (errno == EINTR)
          continue;
        perror("\n\rstartpar: forward write");
        rr = r;
      }
      r -= rr;
      b += rr;
    }
  }
  _exit(0);
}


x86 assembly (clang, -O0):
<do_forward>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    $0x0,%al
call   1050 <setsid@plt>
lea    -0x1000(%rbp),%rsi
xor    %edi,%edi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %rax,-0x1010(%rbp)
cmp    $0x0,%rax
je     1271 <do_forward+0x121>
cmpq   $0x0,-0x1010(%rbp)
jge    11b8 <do_forward+0x68>
mov    0x2e45(%rip),%rax
mov    (%rax),%rax
mov    0x2e33(%rip),%rcx
cmp    (%rcx),%rax
jne    11b3 <do_forward+0x63>
jmp    1162 <do_forward+0x12>
jmp    1271 <do_forward+0x121>
lea    -0x1000(%rbp),%rax
mov    %rax,-0x1008(%rbp)
cmpq   $0x0,-0x1010(%rbp)
jle    126c <do_forward+0x11c>
mov    -0x1008(%rbp),%rsi
mov    -0x1010(%rbp),%rdx
mov    $0x1,%edi
call   1040 <write@plt>
mov    %rax,-0x1018(%rbp)
cmpq   $0x0,-0x1018(%rbp)
jge    123a <do_forward+0xea>
mov    0x2dd8(%rip),%rax
mov    (%rax),%rax
mov    0x2dc6(%rip),%rcx
cmp    (%rcx),%rax
jne    1220 <do_forward+0xd0>
jmp    11c6 <do_forward+0x76>
lea    0xdd9(%rip),%rdi
call   1070 <perror@plt>
mov    -0x1010(%rbp),%rax
mov    %rax,-0x1018(%rbp)
mov    -0x1018(%rbp),%rcx
mov    -0x1010(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x1010(%rbp)
mov    -0x1018(%rbp),%rax
add    -0x1008(%rbp),%rax
mov    %rax,-0x1008(%rbp)
jmp    11c6 <do_forward+0x76>
jmp    1162 <do_forward+0x12>
xor    %edi,%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<do_forward>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
xor    %eax,%eax
call   1050 <setsid@plt>
mov    %rsp,%r15
xor    %edi,%edi
mov    %r15,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
test   %rax,%rax
jne    1186 <do_forward+0x36>
xor    %edi,%edi
call   1030 <_exit@plt>
mov    %rax,%r12
mov    0x2e50(%rip),%r13
mov    0x2e41(%rip),%rbp
lea    0xe62(%rip),%r14
jmp    11c1 <do_forward+0x71>
mov    0x0(%r13),%rax
cmp    0x0(%rbp),%rax
jne    117f <do_forward+0x2f>
xor    %edi,%edi
mov    %r15,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %rax,%r12
test   %rax,%rax
je     117f <do_forward+0x2f>
test   %r12,%r12
js     11a0 <do_forward+0x50>
mov    %r15,%rbx
jmp    11e0 <do_forward+0x90>
mov    %r14,%rdi
call   1070 <perror@plt>
mov    %r12,%rax
add    %rax,%rbx
sub    %rax,%r12
jle    11aa <do_forward+0x5a>
xchg   %ax,%ax
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <write@plt>
test   %rax,%rax
jns    11d6 <do_forward+0x86>
mov    0x0(%r13),%rax
cmp    0x0(%rbp),%rax
je     11e0 <do_forward+0x90>
jmp    11cb <do_forward+0x7b>

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@.str = [26 x i8] c"\0A\0Dstartpar: forward write\00"
define void @do_forward() {
%1 = alloca [4096 x i8]
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = call i32 (...) @setsid()
br label %6
6: ; preds = %45, %17, %0
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%8 = call i64 @read(i32 0, i8* %7, i32 4096)
store i64 %8, i64* %3
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %46
10: ; preds = %6
%11 = load i64, i64* %3
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %13
br label %6
18: ; preds = %13
br label %46
19: ; preds = %10
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
store i8* %20, i8** %2
br label %21
21: ; preds = %38, %34, %19
%22 = load i64, i64* %3
%23 = icmp sgt i64 %22, 0
br i1 %23, label %24, label %45
24: ; preds = %21
%25 = load i8*, i8** %2
%26 = load i64, i64* %3
%27 = call i64 @write(i32 1, i8* %25, i64 %26)
store i64 %27, i64* %4
%28 = load i64, i64* %4
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %24
%31 = load i64, i64* @errno
%32 = load i64, i64* @EINTR
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %30
br label %21
35: ; preds = %30
%36 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%37 = load i64, i64* %3
store i64 %37, i64* %4
br label %38
38: ; preds = %35, %24
%39 = load i64, i64* %4
%40 = load i64, i64* %3
%41 = sub nsw i64 %40, %39
store i64 %41, i64* %3
%42 = load i64, i64* %4
%43 = load i8*, i8** %2
%44 = getelementptr inbounds i8, i8* %43, i64 %42
store i8* %44, i8** %2
br label %21
45: ; preds = %21
br label %6
46: ; preds = %18, %6
%47 = call i32 @_exit(i32 0)
unreachable
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@.str = [26 x i8] c"\0A\0Dstartpar: forward write\00"
define void @do_forward() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @setsid()
%4 = call i64 @read(i32 0, i8* %2, i32 4096)
%5 = icmp eq i64 %4, 0
br i1 %5, label %33, label %6
6: ; preds = %0, %13
%7 = phi i64 [ %14, %13 ], [ %4, %0 ]
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %30
9: ; preds = %6
%10 = load i64, i64* @errno
%11 = load i64, i64* @EINTR
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %33
13: ; preds = %25, %9
%14 = call i64 @read(i32 0, i8* %2, i32 4096)
%15 = icmp eq i64 %14, 0
br i1 %15, label %33, label %6
16: ; preds = %30, %19
%17 = call i64 @write(i32 1, i8* %32, i64 %31)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i64, i64* @errno
%21 = load i64, i64* @EINTR
%22 = icmp eq i64 %20, %21
br i1 %22, label %16, label %23
23: ; preds = %19
%24 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %16, %23
%26 = phi i64 [ %31, %23 ], [ %17, %16 ]
%27 = sub nsw i64 %31, %26
%28 = getelementptr inbounds i8, i8* %32, i64 %26
%29 = icmp sgt i64 %27, 0
br i1 %29, label %30, label %13
30: ; preds = %6, %25
%31 = phi i64 [ %27, %25 ], [ %7, %6 ]
%32 = phi i8* [ %28, %25 ], [ %2, %6 ]
br label %16
33: ; preds = %13, %9, %0
%34 = tail call i32 @_exit(i32 0)
unreachable
}