#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 */
scalar_t__ EINTR;
int /*<<< orphan*/ _exit(int);
scalar_t__ errno;
int /*<<< orphan*/ exec_prntout();
int fork();
int /*<<< orphan*/ printf(char *, char *);
char *strerror(scalar_t__);
int waitpid(int, int *, int /*<<< orphan*/);
int forkexec_prntout() {
  int status;
  pid_t p;
  p = fork();
  if (p == -1)
    return -1;
  else if (p == 0) {
    exec_prntout();
    _exit(-1);
  }
  while (1) {
    pid_t r;
    r = waitpid(p, &status, 0);
    if (r == p) {
      break;
    } else if (r == -1) {
      if (errno != EINTR) {
        printf("waitpid: %s\n", strerror(errno));
        return -1;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<forkexec_prntout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1188 <forkexec_prntout+0x28>
movl   $0xffffffff,-0x4(%rbp)
jmp    1233 <forkexec_prntout+0xd3>
cmpl   $0x0,-0xc(%rbp)
jne    11a3 <forkexec_prntout+0x43>
mov    $0x0,%al
call   1050 <exec_prntout@plt>
mov    $0xffffffff,%edi
call   1030 <_exit@plt>
jmp    11a8 <forkexec_prntout+0x48>
jmp    11ad <forkexec_prntout+0x4d>
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11cf <forkexec_prntout+0x6f>
jmp    122c <forkexec_prntout+0xcc>
cmpl   $0xffffffff,-0x10(%rbp)
jne    1222 <forkexec_prntout+0xc2>
mov    0x2e00(%rip),%rax
mov    (%rax),%rax
mov    0x2dee(%rip),%rcx
cmp    (%rcx),%rax
je     121d <forkexec_prntout+0xbd>
mov    0x2de6(%rip),%rax
mov    (%rax),%rdi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xdf4(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1233 <forkexec_prntout+0xd3>
jmp    1222 <forkexec_prntout+0xc2>
jmp    1227 <forkexec_prntout+0xc7>
jmp    11ad <forkexec_prntout+0x4d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<forkexec_prntout>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     11e9 <forkexec_prntout+0x89>
test   %ebx,%ebx
je     11fa <forkexec_prntout+0x9a>
lea    0xc(%rsp),%rsi
xor    %ebp,%ebp
mov    %ebx,%edi
xor    %edx,%edx
call   1060 <waitpid@plt>
cmp    %ebx,%eax
je     11eb <forkexec_prntout+0x8b>
mov    0x2e47(%rip),%r15
mov    0x2e38(%rip),%r12
lea    0xc(%rsp),%r14
xor    %ebp,%ebp
jmp    11c0 <forkexec_prntout+0x60>
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
cmp    %ebx,%eax
je     11eb <forkexec_prntout+0x8b>
cmp    $0xffffffff,%eax
jne    11b0 <forkexec_prntout+0x50>
mov    (%r15),%rdi
cmp    (%r12),%rdi
je     11b0 <forkexec_prntout+0x50>
call   1070 <strerror@plt>
lea    0xe26(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%ebp
jmp    11eb <forkexec_prntout+0x8b>
mov    %ebx,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1050 <exec_prntout@plt>
mov    $0xffffffff,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@.str = [13 x i8] c"waitpid: %s\0A\00"
define i32 @forkexec_prntout() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 (...) @fork()
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 -1, i32* %1
br label %39
9: ; preds = %0
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = call i32 (...) @exec_prntout()
%14 = call i32 @_exit(i32 -1)
unreachable
15: ; preds = %9
br label %16
16: ; preds = %15
br label %17
17: ; preds = %16, %37
%18 = load i32, i32* %3
%19 = call i32 @waitpid(i32 %18, i32* %2, i32 0)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = load i32, i32* %3
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %17
br label %38
24: ; preds = %17
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = load i64, i64* @errno
%29 = load i64, i64* @EINTR
%30 = icmp ne i64 %28, %29
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i64, i64* @errno
%33 = call i8* @strerror(i64 %32)
%34 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %33)
store i32 -1, i32* %1
br label %39
35: ; preds = %27
br label %36
36: ; preds = %35, %24
br label %37
37: ; preds = %36
br label %17
38: ; preds = %23
store i32 0, i32* %1
br label %39
39: ; preds = %38, %31, %8
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@.str = [13 x i8] c"waitpid: %s\0A\00"
define i32 @forkexec_prntout() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
switch i32 %3, label %4 [
i32 -1, label %23
i32 0, label %7
]
4: ; preds = %0
%5 = call i32 @waitpid(i32 %3, i32* %1, i32 0)
%6 = icmp eq i32 %5, %3
br i1 %6, label %23, label %10
7: ; preds = %0
%8 = tail call i32 (...) @exec_prntout()
%9 = tail call i32 @_exit(i32 -1)
unreachable
10: ; preds = %4, %20
%11 = phi i32 [ %21, %20 ], [ %5, %4 ]
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp eq i64 %14, %15
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = call i8* @strerror(i64 %14)
%19 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %23
20: ; preds = %13, %10
%21 = call i32 @waitpid(i32 %3, i32* %1, i32 0)
%22 = icmp eq i32 %21, %3
br i1 %22, label %23, label %10
23: ; preds = %20, %4, %17, %0
%24 = phi i32 [ %3, %0 ], [ -1, %17 ], [ 0, %4 ], [ 0, %20 ]
ret i32 %24
}