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

/* Variables and functions */
int read_nonblock(int, char *, int);
int write_nonblock(int, char *, int);
int forward(int src, int dest) {
  char line[1024];
  ssize_t nr, nw;
  do {
  } while (0);
  while (nr = read_nonblock(src, line, sizeof(line)), nr > 0)
    if (nw = write_nonblock(dest, line, nr), nw != nr)
      return nw;
  return nr;
}


x86 assembly (clang, -O0):
<forward>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
jmp    1136 <forward+0x16>
jmp    113b <forward+0x1b>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read_nonblock@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jle    11a2 <forward+0x82>
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
call   1030 <write_nonblock@plt>
mov    %eax,-0x418(%rbp)
mov    -0x418(%rbp),%eax
cmp    -0x414(%rbp),%eax
je     119d <forward+0x7d>
mov    -0x418(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <forward+0x8b>
jmp    113b <forward+0x1b>
mov    -0x414(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<forward>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x400,%edx
call   1040 <read_nonblock@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1168 <forward+0x48>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <write_nonblock@plt>
cmp    %ebx,%eax
je     1140 <forward+0x20>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @forward(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
br label %9
9: ; preds = %2
br label %10
10: ; preds = %9
br label %11
11: ; preds = %27, %10
%12 = load i32, i32* %4
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%14 = call i32 @read_nonblock(i32 %12, i8* %13, i32 1024)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %11
%18 = load i32, i32* %5
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%20 = load i32, i32* %7
%21 = call i32 @write_nonblock(i32 %18, i8* %19, i32 %20)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = load i32, i32* %7
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = load i32, i32* %8
store i32 %26, i32* %3
br label %30
27: ; preds = %17
br label %11
28: ; preds = %11
%29 = load i32, i32* %7
store i32 %29, i32* %3
br label %30
30: ; preds = %28, %25
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
define i32 @forward(i32 %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %8, %2
%6 = call i32 @read_nonblock(i32 %0, i8* %4, i32 1024)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = call i32 @write_nonblock(i32 %1, i8* %4, i32 %6)
%10 = icmp eq i32 %9, %6
br i1 %10, label %5, label %11
11: ; preds = %5, %8
%12 = phi i32 [ %9, %8 ], [ %6, %5 ]
ret i32 %12
}