#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 INT_MAX;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int fork();
char getchar();
int getpid();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ usleep(int);
int wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  printf("Pid: %d, Should I start? ", getpid());
  while (getchar() != 'y') {
    usleep(100);
  }
  int i;
  for (i = 0; i < 10; i++) {
    int pid = fork();
    if (pid == 0) {
      printf("I'm child %d.\n", getpid());
      system("chrt -p $$");
      int j;
      for (j = 0; j < INT_MAX; j++) {
        if (j == INT_MAX / 2) {
          printf("child %d\n half way done", getpid());
        }
      }
      _exit(0);
    }
  }
  int wpid;
  while ((wpid = wait(NULL)) > 0)
    ;
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe5a(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
movsbl %al,%eax
cmp    $0x79,%eax
je     11cd <main+0x4d>
mov    $0x64,%edi
call   10a0 <usleep@plt>
jmp    11ab <main+0x2b>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    1292 <main+0x112>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    127f <main+0xff>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe18(%rip),%rdi
call   1060 <printf@plt>
lea    0xe1b(%rip),%rdi
call   1050 <system@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2dc4(%rip),%rcx
cmp    (%rcx),%eax
jge    1278 <main+0xf8>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jne    1265 <main+0xe5>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xdd4(%rip),%rdi
call   1060 <printf@plt>
jmp    126a <main+0xea>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    121a <main+0x9a>
xor    %edi,%edi
call   1030 <_exit@plt>
jmp    1284 <main+0x104>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d4 <main+0x54>
jmp    1297 <main+0x117>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jle    12b1 <main+0x131>
jmp    1297 <main+0x117>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe6e(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0x79,%al
je     11b7 <main+0x37>
mov    $0x64,%edi
call   10a0 <usleep@plt>
jmp    11a0 <main+0x20>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1245 <main+0xc5>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1245 <main+0xc5>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1245 <main+0xc5>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1245 <main+0xc5>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1245 <main+0xc5>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1245 <main+0xc5>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1245 <main+0xc5>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1245 <main+0xc5>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1245 <main+0xc5>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1245 <main+0xc5>
nopl   0x0(%rax)
xor    %edi,%edi
call   1080 <wait@plt>
test   %eax,%eax
jg     1230 <main+0xb0>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xdc7(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
lea    0xdc8(%rip),%rdi
call   1050 <system@plt>
mov    0x2d7b(%rip),%r14
mov    (%r14),%eax
test   %eax,%eax
jle    12aa <main+0x12a>
lea    0xdb9(%rip),%rbx
xor    %ebp,%ebp
jmp    1287 <main+0x107>
nop
add    $0x1,%ebp
cmp    %eax,%ebp
jge    12aa <main+0x12a>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
cmp    %ecx,%ebp
jne    1280 <main+0x100>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    (%r14),%eax
jmp    1280 <main+0x100>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Pid: %d, Should I start? \00"
@.str.1 = [15 x i8] c"I'm child %d.\0A\00"
@.str.2 = [11 x i8] c"chrt -p $$\00"
@INT_MAX = global i32 0
@.str.3 = [24 x i8] c"child %d\0A half way done\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (...) @getpid()
%11 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %16, %2
%13 = call signext i8 (...) @getchar()
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 121
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @usleep(i32 100)
br label %12
18: ; preds = %12
store i32 0, i32* %6
br label %19
19: ; preds = %49, %18
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 10
br i1 %21, label %22, label %52
22: ; preds = %19
%23 = call i32 (...) @fork()
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %48
26: ; preds = %22
%27 = call i32 (...) @getpid()
%28 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = call i32 @system(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %8
br label %30
30: ; preds = %43, %26
%31 = load i32, i32* %8
%32 = load i32, i32* @INT_MAX
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %46
34: ; preds = %30
%35 = load i32, i32* %8
%36 = load i32, i32* @INT_MAX
%37 = sdiv i32 %36, 2
%38 = icmp eq i32 %35, %37
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = call i32 (...) @getpid()
%41 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %39, %34
br label %43
43: ; preds = %42
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %30
46: ; preds = %30
%47 = call i32 @_exit(i32 0)
unreachable
48: ; preds = %22
br label %49
49: ; preds = %48
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
br label %19
52: ; preds = %19
br label %53
53: ; preds = %56, %52
%54 = call i32 @wait(i32* null)
store i32 %54, i32* %9
%55 = icmp sgt i32 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %53
br label %53
57: ; preds = %53
ret i32 1
}

LLVM IR (-O2):
@.str = [26 x i8] c"Pid: %d, Should I start? \00"
@.str.1 = [15 x i8] c"I'm child %d.\0A\00"
@.str.2 = [11 x i8] c"chrt -p $$\00"
@INT_MAX = global i32 0
@.str.3 = [24 x i8] c"child %d\0A half way done\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @getpid()
%4 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call signext i8 (...) @getchar()
%6 = icmp eq i8 %5, 121
br i1 %6, label %7, label %10
7: ; preds = %10, %2
%8 = tail call i32 (...) @fork()
%9 = icmp eq i32 %8, 0
br i1 %9, label %41, label %14
10: ; preds = %2, %10
%11 = tail call i32 @usleep(i32 100)
%12 = tail call signext i8 (...) @getchar()
%13 = icmp eq i8 %12, 121
br i1 %13, label %7, label %10
14: ; preds = %7
%15 = tail call i32 (...) @fork()
%16 = icmp eq i32 %15, 0
br i1 %16, label %41, label %17
17: ; preds = %14
%18 = tail call i32 (...) @fork()
%19 = icmp eq i32 %18, 0
br i1 %19, label %41, label %20
20: ; preds = %17
%21 = tail call i32 (...) @fork()
%22 = icmp eq i32 %21, 0
br i1 %22, label %41, label %23
23: ; preds = %20
%24 = tail call i32 (...) @fork()
%25 = icmp eq i32 %24, 0
br i1 %25, label %41, label %26
26: ; preds = %23
%27 = tail call i32 (...) @fork()
%28 = icmp eq i32 %27, 0
br i1 %28, label %41, label %29
29: ; preds = %26
%30 = tail call i32 (...) @fork()
%31 = icmp eq i32 %30, 0
br i1 %31, label %41, label %32
32: ; preds = %29
%33 = tail call i32 (...) @fork()
%34 = icmp eq i32 %33, 0
br i1 %34, label %41, label %35
35: ; preds = %32
%36 = tail call i32 (...) @fork()
%37 = icmp eq i32 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %35
%39 = tail call i32 (...) @fork()
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %62
41: ; preds = %38, %35, %32, %29, %26, %23, %20, %17, %14, %7
%42 = tail call i32 (...) @getpid()
%43 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = tail call i32 @system(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%45 = load i32, i32* @INT_MAX
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %60
47: ; preds = %41, %56
%48 = phi i32 [ %57, %56 ], [ %45, %41 ]
%49 = phi i32 [ %58, %56 ], [ 0, %41 ]
%50 = sdiv i32 %48, 2
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = tail call i32 (...) @getpid()
%54 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %53)
%55 = load i32, i32* @INT_MAX
br label %56
56: ; preds = %47, %52
%57 = phi i32 [ %48, %47 ], [ %55, %52 ]
%58 = add nuw nsw i32 %49, 1
%59 = icmp slt i32 %58, %57
br i1 %59, label %47, label %60
60: ; preds = %56, %41
%61 = tail call i32 @_exit(i32 0)
unreachable
62: ; preds = %38, %62
%63 = tail call i32 @wait(i32* null)
%64 = icmp sgt i32 %63, 0
br i1 %64, label %62, label %65
65: ; preds = %62
ret i32 1
}