#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;

/* Variables and functions */
int /*<<< orphan*/ pexit(char *);
int read(int, char *, int);
unsigned int strlen(char *);
char toupper(char);
int write(int, char *, int);
void childLoop(int readFd, int writeFd) {
  char buf[(1024)];
  unsigned int i;
  ssize_t numRead;
  while ((numRead = read(readFd, buf, (1024))) == (1024)) {
    for (i = 0; i < strlen(buf); ++i) {
      buf[i] = toupper(buf[i]);
    }
    if (write(writeFd, buf, (1024)) != (1024))
      pexit("child loop - write failure");
  }
  if (numRead == -1)
    pexit("child loop - read failure");
}


x86 assembly (clang, -O0):
<childLoop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x418(%rbp)
cmp    $0x400,%eax
jne    121e <childLoop+0xce>
movl   $0x0,-0x414(%rbp)
mov    -0x414(%rbp),%eax
mov    %eax,-0x41c(%rbp)
lea    -0x410(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x41c(%rbp),%eax
cmp    %ecx,%eax
jae    11ee <childLoop+0x9e>
mov    -0x414(%rbp),%eax
movsbl -0x410(%rbp,%rax,1),%edi
ff
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x414(%rbp),%eax
mov    %cl,-0x410(%rbp,%rax,1)
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    1190 <childLoop+0x40>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1040 <write@plt>
cmp    $0x400,%eax
je     1219 <childLoop+0xc9>
lea    0xdec(%rip),%rdi
call   1070 <pexit@plt>
jmp    1161 <childLoop+0x11>
cmpl   $0xffffffff,-0x418(%rbp)
jne    1237 <childLoop+0xe7>
lea    0xde9(%rip),%rdi
call   1070 <pexit@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<childLoop>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %esi,%r14d
mov    %edi,%r12d
mov    %rsp,%rbx
lea    0xe91(%rip),%r15
nop
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
cmp    $0x400,%eax
jne    11e0 <childLoop+0x90>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     11bf <childLoop+0x6f>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%rsp,%rbp,1),%edi
call   1030 <toupper@plt>
mov    %al,(%rsp,%rbp,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbp
jb     11a0 <childLoop+0x50>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1040 <write@plt>
cmp    $0x400,%eax
je     1170 <childLoop+0x20>
mov    %r15,%rdi
call   1070 <pexit@plt>
jmp    1170 <childLoop+0x20>
cmp    $0xffffffff,%eax
jne    11f1 <childLoop+0xa1>
lea    0xe2f(%rip),%rdi
call   1070 <pexit@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"child loop - write failure\00"
@.str.1 = [26 x i8] c"child loop - read failure\00"
define void @childLoop(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
br label %8
8: ; preds = %38, %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, 1024
br i1 %12, label %13, label %39
13: ; preds = %8
store i32 0, i32* %6
br label %14
14: ; preds = %28, %13
%15 = load i32, i32* %6
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
%18 = icmp ult i32 %15, %17
br i1 %18, label %19, label %31
19: ; preds = %14
%20 = load i32, i32* %6
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = call signext i8 @toupper(i8 signext %23)
%25 = load i32, i32* %6
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %26
store i8 %24, i8* %27
br label %28
28: ; preds = %19
%29 = load i32, i32* %6
%30 = add i32 %29, 1
store i32 %30, i32* %6
br label %14
31: ; preds = %14
%32 = load i32, i32* %4
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%34 = call i32 @write(i32 %32, i8* %33, i32 1024)
%35 = icmp ne i32 %34, 1024
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 @pexit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %38
38: ; preds = %36, %31
br label %8
39: ; preds = %8
%40 = load i32, i32* %7
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 @pexit(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %44
44: ; preds = %42, %39
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"child loop - write failure\00"
@.str.1 = [26 x i8] c"child loop - read failure\00"
define void @childLoop(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 = %24, %2
%6 = call i32 @read(i32 %0, i8* %4, i32 1024)
switch i32 %6, label %27 [
i32 1024, label %7
i32 -1, label %25
]
7: ; preds = %5
%8 = call i32 @strlen(i8* %4)
%9 = icmp eq i32 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %7, %10
%11 = phi i64 [ %15, %10 ], [ 0, %7 ]
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = call signext i8 @toupper(i8 signext %13)
store i8 %14, i8* %12
%15 = add nuw nsw i64 %11, 1
%16 = call i32 @strlen(i8* %4)
%17 = zext i32 %16 to i64
%18 = icmp ult i64 %15, %17
br i1 %18, label %10, label %19
19: ; preds = %10, %7
%20 = call i32 @write(i32 %1, i8* %4, i32 1024)
%21 = icmp eq i32 %20, 1024
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = call i32 @pexit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
br label %5
25: ; preds = %5
%26 = call i32 @pexit(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %5, %25
ret void
}