#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*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int getpid();
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
void child(int fd1[2], int fd2[2]) {
  char line[132];
  close(fd1[1]);
  close(fd2[0]);
  while (1) {
    read(fd1[0], line, 132);
    if (strcmp(line, "end") == 0) {
      close(fd1[0]);
      close(fd2[1]);
      exit(0);
    } else {
      fprintf(stdout, "I'm the child (PID=%d)\n", getpid());
      sprintf(line, "X");
      write(fd2[1], line, strlen(line) + 1);
    }
  }
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x84,%edx
call   1070 <read@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    120c <child+0x7c>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb0(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0xb0(%rbp),%edi
mov    %eax,%edx
lea    0xdd3(%rip),%rsi
call   1090 <fprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xdd8(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0xac(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0xa0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xac(%rbp),%edi
mov    -0xa8(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
jmp    11ba <child+0x2a>

x86 assembly (clang, -O2):
<child>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
mov    0x4(%rdi),%edi
call   1060 <close@plt>
mov    (%r14),%edi
call   1060 <close@plt>
mov    (%r12),%edi
mov    %rsp,%rbx
mov    %rbx,%rsi
mov    $0x84,%edx
call   1070 <read@plt>
lea    0xe3e(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     123d <child+0xbd>
lea    0xe2e(%rip),%r15
mov    %rsp,%rbx
lea    0xe20(%rip),%r13
mov    0x2df9(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1090 <fprintf@plt>
movw   $0x58,(%rsp)
mov    0x4(%r14),%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
mov    (%r12),%edi
mov    %rbx,%rsi
mov    $0x84,%edx
call   1070 <read@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    11e0 <child+0x60>
mov    (%r12),%edi
call   1060 <close@plt>
mov    0x4(%r14),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"end\00"
@stdout = global i32 0
@.str.1 = [24 x i8] c"I'm the child (PID=%d)\0A\00"
@.str.2 = [2 x i8] c"X\00"
define void @child(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [132 x i8]
store i32* %0, i32** %3
store i32* %1, i32** %4
%6 = load i32*, i32** %3
%7 = getelementptr inbounds i32, i32* %6, i64 1
%8 = load i32, i32* %7
%9 = call i32 @close(i32 %8)
%10 = load i32*, i32** %4
%11 = getelementptr inbounds i32, i32* %10, i64 0
%12 = load i32, i32* %11
%13 = call i32 @close(i32 %12)
br label %14
14: ; preds = %2, %47
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds [132 x i8], [132 x i8]* %5, i64 0, i64 0
%19 = call i32 @read(i32 %17, i8* %18, i32 132)
%20 = getelementptr inbounds [132 x i8], [132 x i8]* %5, i64 0, i64 0
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %14
%24 = load i32*, i32** %3
%25 = getelementptr inbounds i32, i32* %24, i64 0
%26 = load i32, i32* %25
%27 = call i32 @close(i32 %26)
%28 = load i32*, i32** %4
%29 = getelementptr inbounds i32, i32* %28, i64 1
%30 = load i32, i32* %29
%31 = call i32 @close(i32 %30)
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %14
%34 = load i32, i32* @stdout
%35 = call i32 (...) @getpid()
%36 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds [132 x i8], [132 x i8]* %5, i64 0, i64 0
%38 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32*, i32** %4
%40 = getelementptr inbounds i32, i32* %39, i64 1
%41 = load i32, i32* %40
%42 = getelementptr inbounds [132 x i8], [132 x i8]* %5, i64 0, i64 0
%43 = getelementptr inbounds [132 x i8], [132 x i8]* %5, i64 0, i64 0
%44 = call i64 @strlen(i8* %43)
%45 = add nsw i64 %44, 1
%46 = call i32 @write(i32 %41, i8* %42, i64 %45)
br label %47
47: ; preds = %33
br label %14
}

LLVM IR (-O2):
@.str = [4 x i8] c"end\00"
@stdout = global i32 0
@.str.1 = [24 x i8] c"I'm the child (PID=%d)\0A\00"
define void @child(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca [132 x i8]
%4 = getelementptr inbounds [132 x i8], [132 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i32, i32* %0, i64 1
%6 = load i32, i32* %5
%7 = tail call i32 @close(i32 %6)
%8 = load i32, i32* %1
%9 = tail call i32 @close(i32 %8)
%10 = load i32, i32* %0
%11 = call i32 @read(i32 %10, i8* %4, i32 132)
%12 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = bitcast [132 x i8]* %3 to i16*
%16 = getelementptr inbounds i32, i32* %1, i64 1
br label %24
17: ; preds = %24, %2
%18 = load i32, i32* %0
%19 = call i32 @close(i32 %18)
%20 = getelementptr inbounds i32, i32* %1, i64 1
%21 = load i32, i32* %20
%22 = call i32 @close(i32 %21)
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %14, %24
%25 = load i32, i32* @stdout
%26 = call i32 (...) @getpid()
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %26)
store i16 88, i16* %15
%28 = load i32, i32* %16
%29 = call i64 @strlen(i8* %4)
%30 = add nsw i64 %29, 1
%31 = call i32 @write(i32 %28, i8* %4, i64 %30)
%32 = load i32, i32* %0
%33 = call i32 @read(i32 %32, i8* %4, i32 132)
%34 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %17, label %24
}