#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*/ EXIT_FAILURE;
int /*<<< orphan*/ echo(char *, char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int write(int, char *, int);
void connectionHandler(int fdInput, int fdOutput) {
  char input[1024];
  char output[1024];
  int readSize;
  do {
    if ((readSize = read(fdInput, input, 1024)) == -1) {
      do {
        perror("read");
        exit(EXIT_FAILURE);
      } while (0);
    }
    if (readSize > 0) {
      echo(input, output, readSize);
      if (write(fdOutput, output, readSize) == -1) {
        do {
          perror("write");
          exit(EXIT_FAILURE);
        } while (0);
      }
    }
  } while (readSize);
  return;
}


x86 assembly (clang, -O0):
<connectionHandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0x814(%rbp)
cmp    $0xffffffff,%eax
jne    11a3 <connectionHandler+0x53>
jmp    1189 <connectionHandler+0x39>
lea    0xe70(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x814(%rbp)
jle    120b <connectionHandler+0xbb>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rsi
mov    -0x814(%rbp),%edx
call   1030 <echo@plt>
mov    -0x8(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    -0x814(%rbp),%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1206 <connectionHandler+0xb6>
jmp    11ec <connectionHandler+0x9c>
lea    0xe12(%rip),%rdi
call   1060 <perror@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    120b <connectionHandler+0xbb>
jmp    1210 <connectionHandler+0xc0>
cmpl   $0x0,-0x814(%rbp)
jne    1161 <connectionHandler+0x11>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connectionHandler>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
lea    0x400(%rsp),%r12
mov    %rsp,%r15
jmp    1184 <connectionHandler+0x34>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %ebx,%ebx
je     11c6 <connectionHandler+0x76>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     11d6 <connectionHandler+0x86>
mov    %eax,%ebx
test   %eax,%eax
jle    1180 <connectionHandler+0x30>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <echo@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1180 <connectionHandler+0x30>
lea    0xe41(%rip),%rdi
jmp    11dd <connectionHandler+0x8d>
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe23(%rip),%rdi
call   1060 <perror@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"read\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [6 x i8] c"write\00"
define void @connectionHandler(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
br label %8
8: ; preds = %40, %2
%9 = load i32, i32* %3
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = call i32 @read(i32 %9, i8* %10, i32 1024)
store i32 %11, i32* %7
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %8
br label %14
14: ; preds = %13
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; No predecessors!
br label %19
19: ; preds = %18, %8
%20 = load i32, i32* %7
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %39
22: ; preds = %19
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%25 = load i32, i32* %7
%26 = call i32 @echo(i8* %23, i8* %24, i32 %25)
%27 = load i32, i32* %4
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%29 = load i32, i32* %7
%30 = call i32 @write(i32 %27, i8* %28, i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %38
32: ; preds = %22
br label %33
33: ; preds = %32
%34 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; No predecessors!
br label %38
38: ; preds = %37, %22
br label %39
39: ; preds = %38, %19
br label %40
40: ; preds = %39
%41 = load i32, i32* %7
%42 = icmp ne i32 %41, 0
br i1 %42, label %8, label %43
43: ; preds = %40
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"read\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [6 x i8] c"write\00"
define void @connectionHandler(i32 %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
br label %7
7: ; preds = %24, %2
%8 = call i32 @read(i32 %0, i8* %5, i32 1024)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %7
%15 = icmp sgt i32 %8, 0
br i1 %15, label %16, label %24
16: ; preds = %14
%17 = call i32 @echo(i8* %5, i8* %6, i32 %8)
%18 = call i32 @write(i32 %1, i8* %6, i32 %8)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %14, %16
%25 = icmp eq i32 %8, 0
br i1 %25, label %26, label %7
26: ; preds = %24
ret void
}