#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 getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, int *, int);
void manage_child(int pipe[]) {
  int integer;
  printf("Child process (PID %d)\n", getpid());
  close(pipe[1]);
  integer = 0;
  while (integer != -1) {
    read(pipe[0], &integer, sizeof(int));
    printf("\nValue received: %d\n", integer);
  }
  close(pipe[0]);
  printf("Child has finished.\n");
}


x86 assembly (clang, -O0):
<manage_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <close@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
je     11aa <manage_child+0x6a>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    -0xc(%rbp),%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1176 <manage_child+0x36>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1050 <close@plt>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<manage_child>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe98(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbx),%edi
call   1060 <close@plt>
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%r14
lea    0xe8b(%rip),%r15
nopl   (%rax)
mov    (%rbx),%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    0x4(%rsp),%ebp
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0xffffffff,%ebp
jne    1190 <manage_child+0x40>
mov    (%rbx),%edi
call   1060 <close@plt>
lea    0xe6b(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Child process (PID %d)\0A\00"
@.str.1 = [21 x i8] c"\0AValue received: %d\0A\00"
@.str.2 = [21 x i8] c"Child has finished.\0A\00"
define void @manage_child(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
%4 = call i32 (...) @getpid()
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32*, i32** %2
%7 = getelementptr inbounds i32, i32* %6, i64 1
%8 = load i32, i32* %7
%9 = call i32 @close(i32 %8)
store i32 0, i32* %3
br label %10
10: ; preds = %13, %1
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32*, i32** %2
%15 = getelementptr inbounds i32, i32* %14, i64 0
%16 = load i32, i32* %15
%17 = call i32 @read(i32 %16, i32* %3, i32 4)
%18 = load i32, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %10
20: ; preds = %10
%21 = load i32*, i32** %2
%22 = getelementptr inbounds i32, i32* %21, i64 0
%23 = load i32, i32* %22
%24 = call i32 @close(i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"Child process (PID %d)\0A\00"
@.str.1 = [21 x i8] c"\0AValue received: %d\0A\00"
@str = [20 x i8] c"Child has finished.\00"
define void @manage_child(i32* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = getelementptr inbounds i32, i32* %0, i64 1
%7 = load i32, i32* %6
%8 = tail call i32 @close(i32 %7)
store i32 0, i32* %2
br label %9
9: ; preds = %1, %9
%10 = load i32, i32* %0
%11 = call i32 @read(i32 %10, i32* %2, i32 4)
%12 = load i32, i32* %2
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = icmp eq i32 %12, -1
br i1 %14, label %15, label %9
15: ; preds = %9
%16 = load i32, i32* %0
%17 = tail call i32 @close(i32 %16)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
ret void
}