#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*/ outbuf;

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
char rot13_char(char);
int /*<<< orphan*/ write(int, char *, size_t);
void children(int fd) {
  char outbuf[16384 + 1];
  size_t outbuf_used = 0;
  ssize_t result;
  while (1) {
    char ch;
    result = read(fd, &ch, 1);
    if (result == 0) {
      break;
    } else if (result == -1) {
      perror("read() failed");
      break;
    }
    if (outbuf_used < sizeof(outbuf))
      outbuf[outbuf_used++] = rot13_char(ch);
    if (ch == '\n') {
      write(fd, outbuf, outbuf_used);
      outbuf_used = 0;
      continue;
    }
  }
}


x86 assembly (clang, -O0):
<children>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4020,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x4018(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x401d(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x401c(%rbp)
cmpl   $0x0,-0x401c(%rbp)
jne    1185 <children+0x45>
jmp    121e <children+0xde>
cmpl   $0xffffffff,-0x401c(%rbp)
jne    11a3 <children+0x63>
lea    0xe67(%rip),%rdi
call   1060 <perror@plt>
jmp    121e <children+0xde>
jmp    11a8 <children+0x68>
cmpq   $0x4001,-0x4018(%rbp)
jae    11e3 <children+0xa3>
movsbl -0x401d(%rbp),%edi
call   1050 <rot13_char@plt>
mov    %al,%cl
mov    -0x4018(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x4018(%rbp)
mov    %cl,-0x4010(%rbp,%rax,1)
movsbl -0x401d(%rbp),%eax
cmp    $0xa,%eax
jne    1219 <children+0xd9>
mov    -0x4(%rbp),%edi
lea    -0x4010(%rbp),%rsi
mov    -0x4018(%rbp),%rdx
call   1030 <write@plt>
movq   $0x0,-0x4018(%rbp)
jmp    1159 <children+0x19>
jmp    1159 <children+0x19>
add    $0x4020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<children>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x4020,%rsp
mov    %edi,%r12d
xor    %ebp,%ebp
lea    0xf(%rsp),%r14
lea    0x10(%rsp),%r15
xchg   %ax,%ax
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %eax,%eax
je     11ae <children+0x6e>
cmp    $0xffffffff,%eax
je     11be <children+0x7e>
movzbl 0xf(%rsp),%ebx
cmp    $0x4000,%rbp
ja     1197 <children+0x57>
movsbl %bl,%edi
call   1050 <rot13_char@plt>
mov    %al,0x10(%rsp,%rbp,1)
add    $0x1,%rbp
cmp    $0xa,%bl
jne    1160 <children+0x20>
mov    %r12d,%edi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1030 <write@plt>
xor    %ebp,%ebp
jmp    1160 <children+0x20>
add    $0x4020,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe3b(%rip),%rdi
add    $0x4020,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <perror@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"read() failed\00"
define void @children(i32 %0) {
%2 = alloca i32
%3 = alloca [16385 x i8]
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8
store i32 %0, i32* %2
store i64 0, i64* %4
br label %7
7: ; preds = %1, %32, %37
%8 = load i32, i32* %2
%9 = call i32 @read(i32 %8, i8* %6, i32 1)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %7
br label %38
13: ; preds = %7
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %38
18: ; preds = %13
br label %19
19: ; preds = %18
%20 = load i64, i64* %4
%21 = icmp ult i64 %20, 16385
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i8, i8* %6
%24 = call signext i8 @rot13_char(i8 signext %23)
%25 = load i64, i64* %4
%26 = add i64 %25, 1
store i64 %26, i64* %4
%27 = getelementptr inbounds [16385 x i8], [16385 x i8]* %3, i64 0, i64 %25
store i8 %24, i8* %27
br label %28
28: ; preds = %22, %19
%29 = load i8, i8* %6
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 10
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i32, i32* %2
%34 = getelementptr inbounds [16385 x i8], [16385 x i8]* %3, i64 0, i64 0
%35 = load i64, i64* %4
%36 = call i32 @write(i32 %33, i8* %34, i64 %35)
store i64 0, i64* %4
br label %7
37: ; preds = %28
br label %7
38: ; preds = %16, %12
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"read() failed\00"
define void @children(i32 %0) {
%2 = alloca [16385 x i8]
%3 = alloca i8
%4 = getelementptr inbounds [16385 x i8], [16385 x i8]* %2, i64 0, i64 0
br label %5
5: ; preds = %22, %1
%6 = phi i64 [ 0, %1 ], [ %23, %22 ]
%7 = call i32 @read(i32 %0, i8* %3, i32 1)
switch i32 %7, label %10 [
i32 0, label %24
i32 -1, label %8
]
8: ; preds = %5
%9 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %24
10: ; preds = %5
%11 = icmp ult i64 %6, 16385
%12 = load i8, i8* %3
br i1 %11, label %13, label %17
13: ; preds = %10
%14 = tail call signext i8 @rot13_char(i8 signext %12)
%15 = add nuw nsw i64 %6, 1
%16 = getelementptr inbounds [16385 x i8], [16385 x i8]* %2, i64 0, i64 %6
store i8 %14, i8* %16
br label %17
17: ; preds = %10, %13
%18 = phi i64 [ %15, %13 ], [ %6, %10 ]
%19 = icmp eq i8 %12, 10
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @write(i32 %0, i8* %4, i64 %18)
br label %22
22: ; preds = %17, %20
%23 = phi i64 [ 0, %20 ], [ %18, %17 ]
br label %5
24: ; preds = %5, %8
ret void
}