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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ process_exitstatus(int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ wait(int *);
int main(int argc, char *argv[]) {
  pid_t pid;
  int status;
  if ((pid = fork()) < 0) {
    fprintf(stderr, "Err.(%s) fork failed\n", strerror(errno));
    exit(EXIT_FAILURE);
  } else if (pid == 0)
    exit(7);
  if (wait(&status) != pid) {
    fprintf(stderr, "Err.(%s) wait failed\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  process_exitstatus(status);
  if ((pid = fork()) < 0) {
    fprintf(stderr, "Err.(%s) fork failed\n", strerror(errno));
    exit(EXIT_FAILURE);
  } else if (pid == 0)
    abort();
  if (wait(&status) != pid) {
    fprintf(stderr, "Err.(%s) wait failed\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  process_exitstatus(status);
  if ((pid = fork()) < 0) {
    fprintf(stderr, "Err.(%s) fork failed\n", strerror(errno));
    exit(EXIT_FAILURE);
  } else if (pid == 0)
    status /= 0;
  if (wait(&status) != pid) {
    fprintf(stderr, "Err.(%s) wait failed\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  process_exitstatus(status);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    11d5 <main+0x65>
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe3e(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11ea <main+0x7a>
mov    $0x7,%edi
call   1060 <exit@plt>
jmp    11ef <main+0x7f>
lea    -0x1c(%rbp),%rdi
call   1080 <wait@plt>
cmp    -0x18(%rbp),%rax
je     123c <main+0xcc>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xded(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1040 <process_exitstatus@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    1293 <main+0x123>
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xd80(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    12a5 <main+0x135>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    12aa <main+0x13a>
lea    -0x1c(%rbp),%rdi
call   1080 <wait@plt>
cmp    -0x18(%rbp),%rax
je     12f7 <main+0x187>
mov    0x2d1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xd32(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1040 <process_exitstatus@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    134e <main+0x1de>
mov    0x2cc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rdx
lea    0xcc5(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1364 <main+0x1f4>
mov    -0x1c(%rbp),%eax
xor    %ecx,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
jmp    1369 <main+0x1f9>
lea    -0x1c(%rbp),%rdi
call   1080 <wait@plt>
cmp    -0x18(%rbp),%rax
je     13b6 <main+0x246>
mov    0x2c5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2c49(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xc73(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2c21(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1040 <process_exitstatus@plt>
mov    0x2c03(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     120d <main+0x9d>
je     1263 <main+0xf3>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
call   1080 <wait@plt>
cmp    %rbx,%rax
jne    122d <main+0xbd>
mov    0xc(%rsp),%edi
call   1040 <process_exitstatus@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     120d <main+0x9d>
je     126d <main+0xfd>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
call   1080 <wait@plt>
cmp    %rbx,%rax
jne    122d <main+0xbd>
mov    0xc(%rsp),%edi
call   1040 <process_exitstatus@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     120d <main+0x9d>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
call   1080 <wait@plt>
cmp    %rbx,%rax
jne    122d <main+0xbd>
mov    0xc(%rsp),%edi
call   1040 <process_exitstatus@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2dcc(%rip),%rax
mov    (%rax),%ebx
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xdd5(%rip),%rsi
jmp    124b <main+0xdb>
mov    0x2dac(%rip),%rax
mov    (%rax),%ebx
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xdcb(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    $0x7,%edi
call   1060 <exit@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Err.(%s) fork failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [22 x i8] c"Err.(%s) wait failed\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 (...) @fork()
store i64 %8, i64* %6
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i64, i64* %6
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @exit(i32 7)
unreachable
22: ; preds = %17
br label %23
23: ; preds = %22
%24 = call i64 @wait(i32* %7)
%25 = load i64, i64* %6
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %34
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %23
%35 = load i32, i32* %7
%36 = call i32 @process_exitstatus(i32 %35)
%37 = call i64 (...) @fork()
store i64 %37, i64* %6
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %46
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %34
%47 = load i64, i64* %6
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 (...) @abort()
unreachable
51: ; preds = %46
br label %52
52: ; preds = %51
%53 = call i64 @wait(i32* %7)
%54 = load i64, i64* %6
%55 = icmp ne i64 %53, %54
br i1 %55, label %56, label %63
56: ; preds = %52
%57 = load i32, i32* @stderr
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %59)
%61 = load i32, i32* @EXIT_FAILURE
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %52
%64 = load i32, i32* %7
%65 = call i32 @process_exitstatus(i32 %64)
%66 = call i64 (...) @fork()
store i64 %66, i64* %6
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %75
68: ; preds = %63
%69 = load i32, i32* @stderr
%70 = load i32, i32* @errno
%71 = call i8* @strerror(i32 %70)
%72 = call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %71)
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %63
%76 = load i64, i64* %6
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %75
%79 = load i32, i32* %7
%80 = sdiv i32 %79, 0
store i32 %80, i32* %7
br label %81
81: ; preds = %78, %75
br label %82
82: ; preds = %81
%83 = call i64 @wait(i32* %7)
%84 = load i64, i64* %6
%85 = icmp ne i64 %83, %84
br i1 %85, label %86, label %93
86: ; preds = %82
%87 = load i32, i32* @stderr
%88 = load i32, i32* @errno
%89 = call i8* @strerror(i32 %88)
%90 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %89)
%91 = load i32, i32* @EXIT_FAILURE
%92 = call i32 @exit(i32 %91)
unreachable
93: ; preds = %82
%94 = load i32, i32* %7
%95 = call i32 @process_exitstatus(i32 %94)
%96 = load i32, i32* @EXIT_SUCCESS
ret i32 %96
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Err.(%s) fork failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [22 x i8] c"Err.(%s) wait failed\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 (...) @fork()
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = icmp eq i64 %5, 0
br i1 %15, label %16, label %18
16: ; preds = %14
%17 = tail call i32 @exit(i32 7)
unreachable
18: ; preds = %14
%19 = call i64 @wait(i32* %3)
%20 = icmp eq i64 %19, %5
br i1 %20, label %28, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %18
%29 = load i32, i32* %3
%30 = call i32 @process_exitstatus(i32 %29)
%31 = call i64 (...) @fork()
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %36)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %28
%41 = icmp eq i64 %31, 0
br i1 %41, label %42, label %44
42: ; preds = %40
%43 = call i32 (...) @abort()
unreachable
44: ; preds = %40
%45 = call i64 @wait(i32* %3)
%46 = icmp eq i64 %45, %31
br i1 %46, label %54, label %47
47: ; preds = %44
%48 = load i32, i32* @stderr
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %50)
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %44
%55 = load i32, i32* %3
%56 = call i32 @process_exitstatus(i32 %55)
%57 = call i64 (...) @fork()
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %66
59: ; preds = %54
%60 = load i32, i32* @stderr
%61 = load i32, i32* @errno
%62 = call i8* @strerror(i32 %61)
%63 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %62)
%64 = load i32, i32* @EXIT_FAILURE
%65 = call i32 @exit(i32 %64)
unreachable
66: ; preds = %54
%67 = call i64 @wait(i32* %3)
%68 = icmp eq i64 %67, %57
br i1 %68, label %76, label %69
69: ; preds = %66
%70 = load i32, i32* @stderr
%71 = load i32, i32* @errno
%72 = call i8* @strerror(i32 %71)
%73 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %72)
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %66
%77 = load i32, i32* %3
%78 = call i32 @process_exitstatus(i32 %77)
%79 = load i32, i32* @EXIT_SUCCESS
ret i32 %79
}