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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int getpid();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int start_child(int, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, int *, int);
int main(void) {
  srand(time(NULL));
  pid_t pid = getpid();
  int i, fd[2], buf;
  printf("Please enter how many processes you want(between 6 and 15): ");
  scanf("%d", &i);
  while (i < 6 || i > 15)
    scanf("%d", &i);
  printf("I'm parent - my pid is %d", pid);
  pipe(fd);
  close(fd[0]);
  buf = (rand() % 9001) + 1000;
  printf("the initial nr %d", buf);
  write(fd[1], &buf, sizeof(int));
  close(fd[1]);
  int cr = start_child(i, fd[0]);
  if (pid == getpid())
    printf("End of parent");
  return cr;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1090 <srand@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,-0x8(%rbp)
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe88(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   10b0 <scanf@plt>
mov    $0x1,%al
cmpl   $0x6,-0xc(%rbp)
mov    %al,-0x1d(%rbp)
jl     1200 <main+0x60>
cmpl   $0xf,-0xc(%rbp)
setg   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1210 <main+0x70>
jmp    1225 <main+0x85>
lea    0xe4f(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   10b0 <scanf@plt>
jmp    11e7 <main+0x47>
mov    -0x8(%rbp),%esi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x14(%rbp),%rdi
call   1080 <pipe@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    $0x0,%al
call   10c0 <rand@plt>
mov    $0x2329,%ecx
cltd
idiv   %ecx
add    $0x3e8,%edx
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%edi
call   1070 <close@plt>
mov    -0xc(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <start_child@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jne    12bf <main+0x11f>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1090 <srand@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%r14d
lea    0xe39(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe91(%rip),%rdi
mov    %rsp,%rsi
call   10b0 <scanf@plt>
mov    (%rsp),%eax
add    $0xfffffff0,%eax
cmp    $0xfffffff5,%eax
ja     1216 <main+0x76>
lea    0xe77(%rip),%rbp
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10b0 <scanf@plt>
mov    (%rsp),%eax
add    $0xfffffff0,%eax
cmp    $0xfffffff6,%eax
jb     1200 <main+0x60>
lea    0xe20(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x4(%rsp),%rdi
call   1080 <pipe@plt>
mov    0x4(%rsp),%edi
call   1070 <close@plt>
xor    %eax,%eax
call   10c0 <rand@plt>
cltq
imul   $0x747ed91f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rcx
add    %edx,%ecx
imul   $0x2329,%ecx,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%esi
add    $0x3e8,%esi
mov    %esi,0xc(%rsp)
lea    0xde4(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%edi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    (%rsp),%edi
mov    0x4(%rsp),%esi
call   1040 <start_child@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getpid@plt>
cmp    %eax,%r14d
jne    12be <main+0x11e>
lea    0xdb2(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [61 x i8] c"Please enter how many processes you want(between 6 and 15): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [26 x i8] c"I'm parent - my pid is %d\00"
@.str.3 = [18 x i8] c"the initial nr %d\00"
@.str.4 = [14 x i8] c"End of parent\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x i32]
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @time(i32* null)
%8 = call i32 @srand(i32 %7)
%9 = call i32 (...) @getpid()
store i32 %9, i32* %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %12
12: ; preds = %20, %0
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 6
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 15
br label %18
18: ; preds = %15, %12
%19 = phi i1 [ true, %12 ], [ %17, %15 ]
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %12
22: ; preds = %18
%23 = load i32, i32* %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%26 = call i32 @pipe(i32* %25)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
%30 = call i32 (...) @rand()
%31 = srem i32 %30, 9001
%32 = add nsw i32 %31, 1000
store i32 %32, i32* %5
%33 = load i32, i32* %5
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @write(i32 %36, i32* %5, i32 4)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%39 = load i32, i32* %38
%40 = call i32 @close(i32 %39)
%41 = load i32, i32* %3
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%43 = load i32, i32* %42
%44 = call i32 @start_child(i32 %41, i32 %43)
store i32 %44, i32* %6
%45 = load i32, i32* %2
%46 = call i32 (...) @getpid()
%47 = icmp eq i32 %45, %46
br i1 %47, label %48, label %50
48: ; preds = %22
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %48, %22
%51 = load i32, i32* %6
ret i32 %51
}

LLVM IR (-O2):
@.str = [61 x i8] c"Please enter how many processes you want(between 6 and 15): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [26 x i8] c"I'm parent - my pid is %d\00"
@.str.3 = [18 x i8] c"the initial nr %d\00"
@.str.4 = [14 x i8] c"End of parent\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = tail call i32 @time(i32* null)
%5 = tail call i32 @srand(i32 %4)
%6 = tail call i32 (...) @getpid()
%7 = bitcast i32* %1 to i8*
%8 = bitcast [2 x i32]* %2 to i8*
%9 = bitcast i32* %3 to i8*
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
%13 = add i32 %12, -16
%14 = icmp ult i32 %13, -10
br i1 %14, label %15, label %20
15: ; preds = %0, %15
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%17 = load i32, i32* %1
%18 = add i32 %17, -16
%19 = icmp ult i32 %18, -10
br i1 %19, label %15, label %20
20: ; preds = %15, %0
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%23 = call i32 @pipe(i32* %22)
%24 = load i32, i32* %22
%25 = call i32 @close(i32 %24)
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 9001
%28 = add nsw i32 %27, 1000
store i32 %28, i32* %3
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%31 = load i32, i32* %30
%32 = call i32 @write(i32 %31, i32* %3, i32 4)
%33 = load i32, i32* %30
%34 = call i32 @close(i32 %33)
%35 = load i32, i32* %1
%36 = load i32, i32* %22
%37 = call i32 @start_child(i32 %35, i32 %36)
%38 = call i32 (...) @getpid()
%39 = icmp eq i32 %6, %38
br i1 %39, label %40, label %42
40: ; preds = %20
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %40, %20
ret i32 %37
}