#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int errno;
int execl(char *, char *, char *);
int /*<<< orphan*/ exit(int);
int fork();
int getpid();
int *malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int read(int, int *, int const);
int /*<<< orphan*/ waitpid(int, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int i;
  int n;
  int plik = open("proc.conf", O_RDONLY);
  const int a = 1;
  int tab[a];
  int b = 0;
  if ((b = read(plik, tab, a)) > 0) {
    for (i = 0; i < 10; i++) {
      n = tab[0];
      if (n == (48 + i)) {
        n = i;
        printf("Liczba rdzeni: %d\n", n);
        break;
      }
    }
  }
  int *child = malloc(n);
  int rodzic;
  int dziecko = 0;
  rodzic = getpid();
  for (i = 0; i < n; i++) {
    child[i] = fork();
    if (child[i] == 0) {
      dziecko = getpid();
      break;
    }
  }
  if (dziecko == getpid()) {
    int k;
    k = execl("./workerbeta", "workerbeta", (char *)NULL);
    printf("%d\n", errno);
    exit(k);
  }
  if (rodzic == getpid()) {
    for (i = 0; i < n; i++) {
      waitpid(child[i], 0, 0);
    }
  }
  close(plik);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
lea    0xe3a(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    %rsp,%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jle    125a <main+0xba>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    1255 <main+0xb5>
mov    -0x50(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x30,%ecx
cmp    %ecx,%eax
jne    1242 <main+0xa2>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xdd2(%rip),%rdi
call   1040 <printf@plt>
jmp    1255 <main+0xb5>
jmp    1247 <main+0xa7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1207 <main+0x67>
jmp    125a <main+0xba>
mov    -0x18(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x40(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12d2 <main+0x132>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,%edx
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    12bf <main+0x11f>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x40(%rbp)
jmp    12d2 <main+0x132>
jmp    12c4 <main+0x124>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    127e <main+0xde>
mov    -0x40(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
cmp    %ecx,%eax
jne    1323 <main+0x183>
lea    0xd2a(%rip),%rdi
lea    0xd25(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10b0 <execl@plt>
mov    %eax,-0x44(%rbp)
mov    0x2ccb(%rip),%rax
mov    (%rax),%esi
lea    0xd03(%rip),%rdi
call   1040 <printf@plt>
mov    -0x44(%rbp),%edi
call   10a0 <exit@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%eax
cmp    %ecx,%eax
jne    1377 <main+0x1d7>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1372 <main+0x1d2>
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1080 <waitpid@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1344 <main+0x1a4>
jmp    1377 <main+0x1d7>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
lea    0xe45(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1060 <read@plt>
test   %eax,%eax
mov    %ebx,0x4(%rsp)
jle    11fa <main+0x5a>
mov    (%rsp),%r12d
lea    -0x30(%r12),%ebx
cmp    $0x9,%ebx
ja     11fa <main+0x5a>
lea    0xe1c(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    %ebx,%r12d
jmp    11fa <main+0x5a>
mov    %r12d,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
xor    %r13d,%r13d
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%r15d
mov    %r12d,%ebp
test   %r12d,%r12d
jle    1247 <main+0xa7>
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %eax,(%r14,%rbx,4)
test   %eax,%eax
je     123d <main+0x9d>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1220 <main+0x80>
xor    %r13d,%r13d
jmp    1247 <main+0xa7>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%r13d
xor    %eax,%eax
call   1030 <getpid@plt>
cmp    %eax,%r13d
je     12a0 <main+0x100>
xor    %eax,%eax
call   1030 <getpid@plt>
cmp    %eax,%r15d
jne    1286 <main+0xe6>
test   %r12d,%r12d
jle    1286 <main+0xe6>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    (%r14,%rbx,4),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <waitpid@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1270 <main+0xd0>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd76(%rip),%rdi
lea    0xd71(%rip),%rsi
xor    %edx,%edx
call   10b0 <execl@plt>
mov    %eax,%ebx
mov    0x2d1a(%rip),%rax
mov    (%rax),%esi
lea    0xd52(%rip),%rdi
call   1040 <printf@plt>
mov    %ebx,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"proc.conf\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"Liczba rdzeni: %d\0A\00"
@.str.2 = [13 x i8] c"./workerbeta\00"
@.str.3 = [11 x i8] c"workerbeta\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@errno = global i32 0
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
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 %17, i32* %8
store i32 1, i32* %9
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %10
%19 = alloca i32, i64 1
store i32 0, i32* %11
%20 = load i32, i32* %8
%21 = call i32 @read(i32 %20, i32* %19, i32 1)
store i32 %21, i32* %11
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %43
23: ; preds = %2
store i32 0, i32* %6
br label %24
24: ; preds = %39, %23
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 10
br i1 %26, label %27, label %42
27: ; preds = %24
%28 = getelementptr inbounds i32, i32* %19, i64 0
%29 = load i32, i32* %28
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = load i32, i32* %6
%32 = add nsw i32 48, %31
%33 = icmp eq i32 %30, %32
br i1 %33, label %34, label %38
34: ; preds = %27
%35 = load i32, i32* %6
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %36)
br label %42
38: ; preds = %27
br label %39
39: ; preds = %38
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %24
42: ; preds = %34, %24
br label %43
43: ; preds = %42, %2
%44 = load i32, i32* %7
%45 = call i32* @malloc(i32 %44)
store i32* %45, i32** %12
store i32 0, i32* %14
%46 = call i32 (...) @getpid()
store i32 %46, i32* %13
store i32 0, i32* %6
br label %47
47: ; preds = %66, %43
%48 = load i32, i32* %6
%49 = load i32, i32* %7
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %69
51: ; preds = %47
%52 = call i32 (...) @fork()
%53 = load i32*, i32** %12
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
store i32 %52, i32* %56
%57 = load i32*, i32** %12
%58 = load i32, i32* %6
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
%61 = load i32, i32* %60
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %51
%64 = call i32 (...) @getpid()
store i32 %64, i32* %14
br label %69
65: ; preds = %51
br label %66
66: ; preds = %65
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 1
store i32 %68, i32* %6
br label %47
69: ; preds = %63, %47
%70 = load i32, i32* %14
%71 = call i32 (...) @getpid()
%72 = icmp eq i32 %70, %71
br i1 %72, label %73, label %79
73: ; preds = %69
%74 = call i32 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* null)
store i32 %74, i32* %15
%75 = load i32, i32* @errno
%76 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %75)
%77 = load i32, i32* %15
%78 = call i32 @exit(i32 %77)
unreachable
79: ; preds = %69
%80 = load i32, i32* %13
%81 = call i32 (...) @getpid()
%82 = icmp eq i32 %80, %81
br i1 %82, label %83, label %99
83: ; preds = %79
store i32 0, i32* %6
br label %84
84: ; preds = %95, %83
%85 = load i32, i32* %6
%86 = load i32, i32* %7
%87 = icmp slt i32 %85, %86
br i1 %87, label %88, label %98
88: ; preds = %84
%89 = load i32*, i32** %12
%90 = load i32, i32* %6
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i32, i32* %89, i64 %91
%93 = load i32, i32* %92
%94 = call i32 @waitpid(i32 %93, i32 0, i32 0)
br label %95
95: ; preds = %88
%96 = load i32, i32* %6
%97 = add nsw i32 %96, 1
store i32 %97, i32* %6
br label %84
98: ; preds = %84
br label %99
99: ; preds = %98, %79
%100 = load i32, i32* %8
%101 = call i32 @close(i32 %100)
store i32 0, i32* %3
%102 = load i8*, i8** %10
%103 = load i32, i32* %3
ret i32 %103
}

LLVM IR (-O2):
@.str = [10 x i8] c"proc.conf\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"Liczba rdzeni: %d\0A\00"
@.str.2 = [13 x i8] c"./workerbeta\00"
@.str.3 = [11 x i8] c"workerbeta\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = alloca i32
%6 = call i32 @read(i32 %4, i32* %5, i32 1)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i32, i32* %5
%10 = add i32 %9, -48
%11 = icmp ult i32 %10, 10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %14
14: ; preds = %8, %12, %2
%15 = phi i32 [ %10, %12 ], [ undef, %2 ], [ %9, %8 ]
%16 = tail call i32* @malloc(i32 %15)
%17 = tail call i32 (...) @getpid()
%18 = icmp sgt i32 %15, 0
br i1 %18, label %19, label %31
19: ; preds = %14
%20 = zext i32 %15 to i64
br label %23
21: ; preds = %23
%22 = icmp eq i64 %28, %20
br i1 %22, label %31, label %23
23: ; preds = %19, %21
%24 = phi i64 [ 0, %19 ], [ %28, %21 ]
%25 = tail call i32 (...) @fork()
%26 = getelementptr inbounds i32, i32* %16, i64 %24
store i32 %25, i32* %26
%27 = icmp eq i32 %25, 0
%28 = add nuw nsw i64 %24, 1
br i1 %27, label %29, label %21
29: ; preds = %23
%30 = tail call i32 (...) @getpid()
br label %31
31: ; preds = %21, %14, %29
%32 = phi i32 [ %30, %29 ], [ 0, %14 ], [ 0, %21 ]
%33 = tail call i32 (...) @getpid()
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = tail call i32 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* null)
%37 = load i32, i32* @errno
%38 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = tail call i32 @exit(i32 %36)
unreachable
40: ; preds = %31
%41 = tail call i32 (...) @getpid()
%42 = icmp eq i32 %17, %41
%43 = and i1 %42, %18
br i1 %43, label %44, label %53
44: ; preds = %40
%45 = zext i32 %15 to i64
br label %46
46: ; preds = %44, %46
%47 = phi i64 [ 0, %44 ], [ %51, %46 ]
%48 = getelementptr inbounds i32, i32* %16, i64 %47
%49 = load i32, i32* %48
%50 = tail call i32 @waitpid(i32 %49, i32 0, i32 0)
%51 = add nuw nsw i64 %47, 1
%52 = icmp eq i64 %51, %45
br i1 %52, label %53, label %46
53: ; preds = %46, %40
%54 = tail call i32 @close(i32 %4)
ret i32 0
}