#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 read(int, char *, int);
int /*<<< orphan*/ rot13(unsigned char *, unsigned char *, int);
int write(int, char *, int);
int connectionHandler(int fdInput, int fdOutput) {
  char input[1024];
  char output[1024];
  int readSize;
  if ((readSize = read(fdInput, input, 1024)) < 1) {
    return -1;
  }
  rot13((unsigned char *)input, (unsigned char *)output, readSize);
  if (write(fdOutput, output, readSize) < 1) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<connectionHandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0x814(%rbp)
cmp    $0x1,%eax
jge    1170 <connectionHandler+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ba <connectionHandler+0x8a>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rsi
mov    -0x814(%rbp),%edx
call   1040 <rot13@plt>
mov    -0xc(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    -0x814(%rbp),%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jge    11b3 <connectionHandler+0x83>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ba <connectionHandler+0x8a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connectionHandler>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %esi,%ebx
mov    %rsp,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    117e <connectionHandler+0x4e>
mov    %eax,%ebp
mov    %rsp,%rdi
lea    0x400(%rsp),%r14
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <rot13@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
setle  %al
neg    %eax
jmp    1183 <connectionHandler+0x53>
mov    $0xffffffff,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @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
%7 = call i32 @read(i32 %0, i8* %5, i32 1024)
%8 = icmp slt i32 %7, 1
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = call i32 @rot13(i8* %5, i8* %6, i32 %7)
%11 = call i32 @write(i32 %1, i8* %6, i32 %7)
%12 = icmp slt i32 %11, 1
%13 = sext i1 %12 to i32
br label %14
14: ; preds = %9, %2
%15 = phi i32 [ -1, %2 ], [ %13, %9 ]
ret i32 %15
}