#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 WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ assert(int);
scalar_t__ fork();
int process();
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(void) {
  int i, s;
  pid_t p;
  for (i = 0; i < 16; ++i) {
    assert((p = fork()) >= 0);
    if (p == 0)
      return process();
    assert(waitpid(p, &s, 0) == p && WIFEXITED(s));
    if (WEXITSTATUS(s))
      return WEXITSTATUS(s);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x10,-0x8(%rbp)
jge    122a <main+0xca>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11b6 <main+0x56>
mov    $0x0,%al
call   1030 <process@plt>
mov    %eax,-0x4(%rbp)
jmp    1231 <main+0xd1>
mov    -0x18(%rbp),%rdi
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x19(%rbp)
jne    11e9 <main+0x89>
mov    -0xc(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0xc(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     1217 <main+0xb7>
mov    -0xc(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
jmp    1231 <main+0xd1>
jmp    121c <main+0xbc>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1176 <main+0x16>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x10,%ebp
lea    0x4(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <fork@plt>
mov    %rax,%rbx
mov    %rax,%rdi
shr    $0x3f,%rdi
xor    $0x1,%edi
call   1040 <assert@plt>
test   %rbx,%rbx
je     11e2 <main+0x82>
xor    %r15d,%r15d
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
cmp    %rbx,%rax
jne    11c3 <main+0x63>
mov    0x4(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %rax,%rax
setne  %r15b
movzbl %r15b,%edi
call   1040 <assert@plt>
mov    0x4(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
test   %eax,%eax
jne    11eb <main+0x8b>
add    $0xffffffff,%ebp
jne    1180 <main+0x20>
xor    %eax,%eax
jmp    11f4 <main+0x94>
xor    %eax,%eax
call   1030 <process@plt>
jmp    11f4 <main+0x94>
mov    0x4(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %2
br label %5
5: ; preds = %37, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 16
br i1 %7, label %8, label %40
8: ; preds = %5
%9 = call i64 (...) @fork()
store i64 %9, i64* %4
%10 = icmp sge i64 %9, 0
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i64, i64* %4
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = call i32 (...) @process()
store i32 %16, i32* %1
br label %41
17: ; preds = %8
%18 = load i64, i64* %4
%19 = call i64 @waitpid(i64 %18, i32* %3, i32 0)
%20 = load i64, i64* %4
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* %3
%24 = call i64 @WIFEXITED(i32 %23)
%25 = icmp ne i64 %24, 0
br label %26
26: ; preds = %22, %17
%27 = phi i1 [ false, %17 ], [ %25, %22 ]
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i32, i32* %3
%31 = call i32 @WEXITSTATUS(i32 %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %26
%34 = load i32, i32* %3
%35 = call i32 @WEXITSTATUS(i32 %34)
store i32 %35, i32* %1
br label %41
36: ; preds = %26
br label %37
37: ; preds = %36
%38 = load i32, i32* %2
%39 = add nsw i32 %38, 1
store i32 %39, i32* %2
br label %5
40: ; preds = %5
store i32 0, i32* %1
br label %41
41: ; preds = %40, %33, %15
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %6
3: ; preds = %23
%4 = add nuw nsw i32 %7, 1
%5 = icmp eq i32 %4, 16
br i1 %5, label %33, label %6
6: ; preds = %0, %3
%7 = phi i32 [ 0, %0 ], [ %4, %3 ]
%8 = call i64 (...) @fork()
%9 = lshr i64 %8, 63
%10 = trunc i64 %9 to i32
%11 = xor i32 %10, 1
%12 = call i32 @assert(i32 %11)
%13 = icmp eq i64 %8, 0
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = call i32 (...) @process()
br label %33
16: ; preds = %6
%17 = call i64 @waitpid(i64 %8, i32* %1, i32 0)
%18 = icmp eq i64 %17, %8
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* %1
%21 = call i64 @WIFEXITED(i32 %20)
%22 = icmp ne i64 %21, 0
br label %23
23: ; preds = %19, %16
%24 = phi i1 [ false, %16 ], [ %22, %19 ]
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i32, i32* %1
%28 = call i32 @WEXITSTATUS(i32 %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %3, label %30
30: ; preds = %23
%31 = load i32, i32* %1
%32 = call i32 @WEXITSTATUS(i32 %31)
br label %33
33: ; preds = %3, %30, %14
%34 = phi i32 [ %15, %14 ], [ %32, %30 ], [ 0, %3 ]
ret i32 %34
}