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

/* Variables and functions */
int /*<<< orphan*/ EINTR;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ WNOHANG;
int WTERMSIG(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ pause();
int waitpid(int, int *, int /*<<< orphan*/);
int parent_procedure(pid_t child) {
  int rc = 0;
  pid_t pid;
  pause();
  pid = waitpid(child, &rc, WNOHANG);
  if (pid == -1)
    rc = -1;
  else if (pid != 0) {
    rc = WIFEXITED(rc) ? WEXITSTATUS(rc) : WTERMSIG(rc);
    errno = EINTR;
  }
  return rc;
}


x86 assembly (clang, -O0):
<parent_procedure>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <pause@plt>
mov    -0x4(%rbp),%edi
mov    0x2e75(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rsi
call   1060 <waitpid@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1197 <parent_procedure+0x47>
movl   $0xffffffff,-0x8(%rbp)
jmp    11eb <parent_procedure+0x9b>
cmpl   $0x0,-0xc(%rbp)
je     11e6 <parent_procedure+0x96>
mov    -0x8(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11c3 <parent_procedure+0x73>
mov    -0x8(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
mov    %eax,-0x10(%rbp)
jmp    11ce <parent_procedure+0x7e>
mov    -0x8(%rbp),%edi
call   1040 <WTERMSIG@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2df5(%rip),%rax
mov    (%rax),%ecx
mov    0x2df4(%rip),%rax
mov    %ecx,(%rax)
jmp    11eb <parent_procedure+0x9b>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parent_procedure>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x0,0xc(%rsp)
xor    %eax,%eax
call   1030 <pause@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
call   1060 <waitpid@plt>
cmp    $0xffffffff,%eax
je     11ba <parent_procedure+0x6a>
test   %eax,%eax
jne    118a <parent_procedure+0x3a>
mov    0xc(%rsp),%eax
jmp    11ba <parent_procedure+0x6a>
mov    0xc(%rsp),%edi
call   1070 <WIFEXITED@plt>
mov    0xc(%rsp),%edi
test   %rax,%rax
je     11a3 <parent_procedure+0x53>
call   1050 <WEXITSTATUS@plt>
jmp    11a8 <parent_procedure+0x58>
call   1040 <WTERMSIG@plt>
mov    0x2e21(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2e20(%rip),%rdx
mov    %ecx,(%rdx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@WNOHANG = global i32 0
@EINTR = global i32 0
@errno = global i32 0
define i32 @parent_procedure(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%5 = call i32 (...) @pause()
%6 = load i32, i32* %2
%7 = load i32, i32* @WNOHANG
%8 = call i32 @waitpid(i32 %6, i32* %3, i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %3
br label %29
12: ; preds = %1
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %12
%16 = load i32, i32* %3
%17 = call i64 @WIFEXITED(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* %3
%21 = call i32 @WEXITSTATUS(i32 %20)
br label %25
22: ; preds = %15
%23 = load i32, i32* %3
%24 = call i32 @WTERMSIG(i32 %23)
br label %25
25: ; preds = %22, %19
%26 = phi i32 [ %21, %19 ], [ %24, %22 ]
store i32 %26, i32* %3
%27 = load i32, i32* @EINTR
store i32 %27, i32* @errno
br label %28
28: ; preds = %25, %12
br label %29
29: ; preds = %28, %11
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@WNOHANG = global i32 0
@EINTR = global i32 0
@errno = global i32 0
define i32 @parent_procedure(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = tail call i32 (...) @pause()
%5 = load i32, i32* @WNOHANG
%6 = call i32 @waitpid(i32 %0, i32* %2, i32 %5)
switch i32 %6, label %9 [
i32 -1, label %21
i32 0, label %7
]
7: ; preds = %1
%8 = load i32, i32* %2
br label %21
9: ; preds = %1
%10 = load i32, i32* %2
%11 = call i64 @WIFEXITED(i32 %10)
%12 = icmp eq i64 %11, 0
%13 = load i32, i32* %2
br i1 %12, label %16, label %14
14: ; preds = %9
%15 = call i32 @WEXITSTATUS(i32 %13)
br label %18
16: ; preds = %9
%17 = call i32 @WTERMSIG(i32 %13)
br label %18
18: ; preds = %16, %14
%19 = phi i32 [ %15, %14 ], [ %17, %16 ]
%20 = load i32, i32* @EINTR
store i32 %20, i32* @errno
br label %21
21: ; preds = %1, %7, %18
%22 = phi i32 [ %8, %7 ], [ %19, %18 ], [ %6, %1 ]
ret i32 %22
}