#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*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ rdtsctask();
int /*<<< orphan*/ segvtask();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int n_tasks = 100, i;
  fprintf(stderr, "[No further output means we're allright]\n");
  for (i = 0; i < n_tasks; i++)
    if (fork() == 0) {
      if (i & 1)
        segvtask();
      else
        rdtsctask();
    }
  for (i = 0; i < n_tasks; i++)
    wait(NULL);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x64,-0x14(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f0 <main+0x90>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%rax
jne    11dd <main+0x7d>
mov    -0x18(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11d1 <main+0x71>
mov    $0x0,%al
call   1040 <segvtask@plt>
jmp    11d8 <main+0x78>
mov    $0x0,%al
call   1030 <rdtsctask@plt>
jmp    11dd <main+0x7d>
jmp    11e2 <main+0x82>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1199 <main+0x39>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    121a <main+0xba>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11f7 <main+0x97>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1050 <fprintf@plt>
xor    %ebx,%ebx
jmp    1188 <main+0x28>
call   1030 <rdtsctask@plt>
nop
add    $0x1,%ebx
cmp    $0x64,%ebx
je     11a2 <main+0x42>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    1180 <main+0x20>
xor    %eax,%eax
test   $0x1,%bl
je     117a <main+0x1a>
call   1040 <segvtask@plt>
jmp    1180 <main+0x20>
mov    $0x64,%ebx
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
call   1070 <wait@plt>
add    $0xffffffff,%ebx
jne    11b0 <main+0x50>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [42 x i8] c"[No further output means we're allright]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 100, i32* %6
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %10
10: ; preds = %27, %2
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %30
14: ; preds = %10
%15 = call i64 (...) @fork()
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = load i32, i32* %7
%19 = and i32 %18, 1
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 (...) @segvtask()
br label %25
23: ; preds = %17
%24 = call i32 (...) @rdtsctask()
br label %25
25: ; preds = %23, %21
br label %26
26: ; preds = %25, %14
br label %27
27: ; preds = %26
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %10
30: ; preds = %10
store i32 0, i32* %7
br label %31
31: ; preds = %37, %30
%32 = load i32, i32* %7
%33 = load i32, i32* %6
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = call i32 @wait(i32* null)
br label %37
37: ; preds = %35
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %31
40: ; preds = %31
%41 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [42 x i8] c"[No further output means we're allright]\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @stderr
%4 = tail call i32 @fprintf(i32 %3, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %2, %16
%6 = phi i32 [ 0, %2 ], [ %17, %16 ]
%7 = tail call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %5
%10 = and i32 %6, 1
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 (...) @segvtask()
br label %16
14: ; preds = %9
%15 = tail call i32 (...) @rdtsctask()
br label %16
16: ; preds = %5, %14, %12
%17 = add nuw nsw i32 %6, 1
%18 = icmp eq i32 %17, 100
br i1 %18, label %19, label %5
19: ; preds = %16, %19
%20 = phi i32 [ %22, %19 ], [ 0, %16 ]
%21 = tail call i32 @wait(i32* null)
%22 = add nuw nsw i32 %20, 1
%23 = icmp eq i32 %22, 100
br i1 %23, label %24, label %19
24: ; preds = %19
%25 = tail call i32 @exit(i32 0)
unreachable
}