#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*/ scanf(char *, int *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, int *, int);
void manage_parent(int pipe[]) {
  int integer;
  printf("Parent process (PID %d)\n", getpid());
  close(pipe[0]);
  integer = 0;
  while (integer != -1) {
    scanf("%d", &integer);
    write(pipe[1], &integer, sizeof(int));
  }
  close(pipe[1]);
  wait(NULL);
  printf("Parent: has received child termination.\n");
}


x86 assembly (clang, -O0):
<manage_parent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1060 <close@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
je     11c9 <manage_parent+0x69>
lea    0xe73(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
jmp    1195 <manage_parent+0x35>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1060 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<manage_parent>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe76(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r15),%edi
call   1070 <close@plt>
movl   $0x0,0xc(%rsp)
lea    0xe6f(%rip),%r14
lea    0xc(%rsp),%rbx
nop
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    0x4(%r15),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
cmpl   $0xffffffff,0xc(%rsp)
jne    11b0 <manage_parent+0x40>
mov    0x4(%r15),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   1090 <wait@plt>
lea    0xe32(%rip),%rdi
call   1030 <puts@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Parent process (PID %d)\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [41 x i8] c"Parent: has received child termination.\0A\00"
define void @manage_parent(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 ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32*, i32** %2
%7 = getelementptr inbounds i32, i32* %6, i64 0
%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 %19
13: ; preds = %10
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%15 = load i32*, i32** %2
%16 = getelementptr inbounds i32, i32* %15, i64 1
%17 = load i32, i32* %16
%18 = call i32 @write(i32 %17, i32* %3, i32 4)
br label %10
19: ; preds = %10
%20 = load i32*, i32** %2
%21 = getelementptr inbounds i32, i32* %20, i64 1
%22 = load i32, i32* %21
%23 = call i32 @close(i32 %22)
%24 = call i32 @wait(i32* null)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"Parent process (PID %d)\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@str = [40 x i8] c"Parent: has received child termination.\00"
define void @manage_parent(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 ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* %0
%7 = tail call i32 @close(i32 %6)
store i32 0, i32* %2
%8 = getelementptr inbounds i32, i32* %0, i64 1
br label %9
9: ; preds = %1, %9
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %8
%12 = call i32 @write(i32 %11, i32* %2, i32 4)
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %9
15: ; preds = %9
%16 = load i32, i32* %8
%17 = call i32 @close(i32 %16)
%18 = call i32 @wait(i32* null)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
ret void
}