#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 /*<<< orphan*/ check();
int dofork();
int /*<<< orphan*/ dowait(int, int);
int /*<<< orphan*/ putchar(char);
void test(int nowait) {
  int pid0, pid1, pid2, pid3;
  pid0 = dofork();
  putchar('0');
  check();
  pid1 = dofork();
  putchar('1');
  check();
  pid2 = dofork();
  putchar('2');
  check();
  pid3 = dofork();
  putchar('3');
  check();
  dowait(nowait, pid3);
  dowait(nowait, pid2);
  dowait(nowait, pid1);
  dowait(nowait, pid0);
  putchar('\n');
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1050 <dofork@plt>
mov    %eax,-0x8(%rbp)
mov    $0x30,%edi
call   1040 <putchar@plt>
mov    $0x0,%al
call   1060 <check@plt>
mov    $0x0,%al
call   1050 <dofork@plt>
mov    %eax,-0xc(%rbp)
mov    $0x31,%edi
call   1040 <putchar@plt>
mov    $0x0,%al
call   1060 <check@plt>
mov    $0x0,%al
call   1050 <dofork@plt>
mov    %eax,-0x10(%rbp)
mov    $0x32,%edi
call   1040 <putchar@plt>
mov    $0x0,%al
call   1060 <check@plt>
mov    $0x0,%al
call   1050 <dofork@plt>
mov    %eax,-0x14(%rbp)
mov    $0x33,%edi
call   1040 <putchar@plt>
mov    $0x0,%al
call   1060 <check@plt>
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <dowait@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <dowait@plt>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <dowait@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <dowait@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1050 <dofork@plt>
mov    %eax,%r14d
mov    $0x30,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
call   1060 <check@plt>
xor    %eax,%eax
call   1050 <dofork@plt>
mov    %eax,%r15d
mov    $0x31,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
call   1060 <check@plt>
xor    %eax,%eax
call   1050 <dofork@plt>
mov    %eax,%r12d
mov    $0x32,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
call   1060 <check@plt>
xor    %eax,%eax
call   1050 <dofork@plt>
mov    %eax,%ebp
mov    $0x33,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
call   1060 <check@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <dowait@plt>
mov    %ebx,%edi
mov    %r12d,%esi
call   1030 <dowait@plt>
mov    %ebx,%edi
mov    %r15d,%esi
call   1030 <dowait@plt>
mov    %ebx,%edi
mov    %r14d,%esi
call   1030 <dowait@plt>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <putchar@plt>

LLVM IR (-O0):
define void @test(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = call i32 (...) @dofork()
store i32 %7, i32* %3
%8 = call i32 @putchar(i8 signext 48)
%9 = call i32 (...) @check()
%10 = call i32 (...) @dofork()
store i32 %10, i32* %4
%11 = call i32 @putchar(i8 signext 49)
%12 = call i32 (...) @check()
%13 = call i32 (...) @dofork()
store i32 %13, i32* %5
%14 = call i32 @putchar(i8 signext 50)
%15 = call i32 (...) @check()
%16 = call i32 (...) @dofork()
store i32 %16, i32* %6
%17 = call i32 @putchar(i8 signext 51)
%18 = call i32 (...) @check()
%19 = load i32, i32* %2
%20 = load i32, i32* %6
%21 = call i32 @dowait(i32 %19, i32 %20)
%22 = load i32, i32* %2
%23 = load i32, i32* %5
%24 = call i32 @dowait(i32 %22, i32 %23)
%25 = load i32, i32* %2
%26 = load i32, i32* %4
%27 = call i32 @dowait(i32 %25, i32 %26)
%28 = load i32, i32* %2
%29 = load i32, i32* %3
%30 = call i32 @dowait(i32 %28, i32 %29)
%31 = call i32 @putchar(i8 signext 10)
ret void
}

LLVM IR (-O2):
define void @test(i32 %0) {
%2 = tail call i32 (...) @dofork()
%3 = tail call i32 @putchar(i8 signext 48)
%4 = tail call i32 (...) @check()
%5 = tail call i32 (...) @dofork()
%6 = tail call i32 @putchar(i8 signext 49)
%7 = tail call i32 (...) @check()
%8 = tail call i32 (...) @dofork()
%9 = tail call i32 @putchar(i8 signext 50)
%10 = tail call i32 (...) @check()
%11 = tail call i32 (...) @dofork()
%12 = tail call i32 @putchar(i8 signext 51)
%13 = tail call i32 (...) @check()
%14 = tail call i32 @dowait(i32 %0, i32 %11)
%15 = tail call i32 @dowait(i32 %0, i32 %8)
%16 = tail call i32 @dowait(i32 %0, i32 %5)
%17 = tail call i32 @dowait(i32 %0, i32 %2)
%18 = tail call i32 @putchar(i8 signext 10)
ret void
}