#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 WEXITSTATUS(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int *);
void parent(int *pid) {
  int ret = 0;
  printf("Alpha: forked process with ID %d\n", *pid);
  printf("Alpha: waiting for process [%d].\n", *pid);
  wait(&ret);
  int ret_Val = WEXITSTATUS(ret);
  if (ret_Val == 1) {
    printf("Alpha: error input was not valid.\n");
  } else {
    printf("Alpha: child process %d returned %d.\n", *pid, ret_Val);
  }
}


x86 assembly (clang, -O0):
<parent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xc(%rbp),%rdi
call   1050 <wait@plt>
mov    -0xc(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    119c <parent+0x6c>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b3 <parent+0x83>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parent>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
mov    (%rdi),%esi
lea    0xea7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%esi
lea    0xeb9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rdi
call   1060 <wait@plt>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
cmp    $0x1,%eax
jne    1196 <parent+0x56>
lea    0xedb(%rip),%rdi
call   1030 <puts@plt>
jmp    11a8 <parent+0x68>
mov    (%rbx),%esi
lea    0xea5(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Alpha: forked process with ID %d\0A\00"
@.str.1 = [34 x i8] c"Alpha: waiting for process [%d].\0A\00"
@.str.2 = [35 x i8] c"Alpha: error input was not valid.\0A\00"
@.str.3 = [38 x i8] c"Alpha: child process %d returned %d.\0A\00"
define void @parent(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %3
%5 = load i32*, i32** %2
%6 = load i32, i32* %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32*, i32** %2
%9 = load i32, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = call i32 @wait(i32* %3)
%12 = load i32, i32* %3
%13 = call i32 @WEXITSTATUS(i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %23
18: ; preds = %1
%19 = load i32*, i32** %2
%20 = load i32, i32* %19
%21 = load i32, i32* %4
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %20, i32 %21)
br label %23
23: ; preds = %18, %16
ret void
}

LLVM IR (-O2):
@.str = [34 x i8] c"Alpha: forked process with ID %d\0A\00"
@.str.1 = [34 x i8] c"Alpha: waiting for process [%d].\0A\00"
@.str.3 = [38 x i8] c"Alpha: child process %d returned %d.\0A\00"
@str = [34 x i8] c"Alpha: error input was not valid.\00"
define void @parent(i32* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = load i32, i32* %0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* %0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = call i32 @wait(i32* %2)
%9 = load i32, i32* %2
%10 = call i32 @WEXITSTATUS(i32 %9)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %17
14: ; preds = %1
%15 = load i32, i32* %0
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %15, i32 %10)
br label %17
17: ; preds = %14, %12
ret void
}