#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 */
struct sched_param {
  int /*<<< orphan*/ sched_priority;
};
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int RAND_MAX;
int SCHED_FIFO;
int SCHED_OTHER;
int SCHED_RR;
scalar_t__ WIFEXITED(int);
int atol(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int random();
int /*<<< orphan*/ sched_get_priority_max(int);
int /*<<< orphan*/ sched_get_priority_min(int);
int sched_getscheduler(int /*<<< orphan*/);
scalar_t__ sched_setscheduler(int /*<<< orphan*/, int, struct sched_param *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
int wait(int *);
int zeroDist(double, double);
int main(int argc, char *argv[]) {
  long it = 1000000;
  double x, y;
  double inCircle = 0.0;
  double inSquare = 0.0;
  double pCircle = 0.0;
  double piCalc = 0.0;
  pid_t pid;
  int test;
  int pro;
  int policy;
  struct sched_param param;
  if (argc < 2) {
    pro = 1000000;
  }
  if (argc < 3) {
    policy = SCHED_OTHER;
  }
  if (argc > 1) {
    pro = atol(argv[1]);
    if (pro < 1) {
      fprintf(stderr, "Bad pro value\n");
      exit(EXIT_FAILURE);
    }
  }
  if (argc > 2) {
    if (!strcmp(argv[2], "SCHED_OTHER")) {
      policy = SCHED_OTHER;
    } else if (!strcmp(argv[2], "SCHED_FIFO")) {
      policy = SCHED_FIFO;
    } else if (!strcmp(argv[2], "SCHED_RR")) {
      policy = SCHED_RR;
    } else {
      fprintf(stderr, "Unhandeled scheduling policy\n");
      exit(EXIT_FAILURE);
    }
  }
  fprintf(stdout, "Current Scheduling Policy: %d\n", sched_getscheduler(0));
  fprintf(stdout, "Setting Scheduling Policy to: %d\n", policy);
  if (sched_setscheduler(0, policy, &param)) {
    perror("Error setting scheduler policy");
    exit(EXIT_FAILURE);
  }
  fprintf(stdout, "New Scheduling Policy: %d\n", sched_getscheduler(0));
  fprintf(stdout, "Creating %d simultanious processes\n", pro);
  for (int i = 0; i < pro; i++) {
    if ((pid = fork()) == -1) {
      fprintf(stderr, "The child process %d could not be forked\n", i);
      exit(EXIT_FAILURE);
    } else if (pid == 0) {
      fprintf(stdout, "Process %d correctly forked with PID %d\n", i, pid);
      if (i % 2 == 0) {
        param.sched_priority = sched_get_priority_max(policy);
      } else {
        param.sched_priority = sched_get_priority_min(policy);
      }
      for (i = 0; i < it; i++) {
        x = (random() % ((RAND_MAX / 2) * 2)) - (RAND_MAX / 2);
        y = (random() % ((RAND_MAX / 2) * 2)) - (RAND_MAX / 2);
        if (zeroDist(x, y) < (RAND_MAX / 2)) {
          inCircle++;
        }
        inSquare++;
      }
      pCircle = inCircle / inSquare;
      piCalc = pCircle * 4.0;
      fprintf(stdout, "pi = %f\n", piCalc);
      exit(0);
    }
  }
  fprintf(stdout, "\nWaiting for all of the running processes to exit\n");
  int reap = 0;
  while ((pid = wait(&test)) > 0) {
    if (WIFEXITED(test)) {
      reap++;
    }
  }
  if (reap == pro) {
    exit(EXIT_SUCCESS);
  } else {
    exit(EXIT_FAILURE);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0xf4240,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1232 <main+0x52>
movl   $0xf4240,-0x54(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1248 <main+0x68>
mov    0x2d85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1296 <main+0xb6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atol@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x1,-0x54(%rbp)
jge    1291 <main+0xb1>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
lea    0xd94(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    1296 <main+0xb6>
cmpl   $0x2,-0x8(%rbp)
jle    135e <main+0x17e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd70(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    12ce <main+0xee>
mov    0x2d04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
jmp    1359 <main+0x179>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd4e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    12fc <main+0x11c>
mov    0x2cee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
jmp    1354 <main+0x174>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd2b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    132a <main+0x14a>
mov    0x2c80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
jmp    134f <main+0x16f>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
lea    0xd05(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    1354 <main+0x174>
jmp    1359 <main+0x179>
jmp    135e <main+0x17e>
mov    0x2c53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
xor    %edi,%edi
call   1030 <sched_getscheduler@plt>
mov    -0x6c(%rbp),%edi
mov    %eax,%edx
lea    0xce0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c2d(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%edx
lea    0xce5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x58(%rbp),%esi
xor    %edi,%edi
lea    -0x60(%rbp),%rdx
call   1040 <sched_setscheduler@plt>
cmp    $0x0,%rax
je     13d0 <main+0x1f0>
lea    0xce1(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2bf7(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    0x2be1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
xor    %edi,%edi
call   1030 <sched_getscheduler@plt>
mov    -0x70(%rbp),%edi
mov    %eax,%edx
lea    0xcce(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2bbb(%rip),%rax
mov    (%rax),%edi
mov    -0x54(%rbp),%edx
lea    0xccf(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    161d <main+0x43d>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0xffffffff,%eax
jne    145e <main+0x27e>
mov    0x2b93(%rip),%rax
mov    (%rax),%edi
mov    -0x64(%rbp),%edx
lea    0xcb3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2b69(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x4c(%rbp)
jne    1605 <main+0x425>
mov    0x2b49(%rip),%rax
mov    (%rax),%edi
mov    -0x64(%rbp),%edx
mov    -0x4c(%rbp),%ecx
lea    0xca8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x64(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    14a9 <main+0x2c9>
mov    -0x58(%rbp),%edi
call   10e0 <sched_get_priority_max@plt>
mov    %eax,-0x60(%rbp)
jmp    14b4 <main+0x2d4>
mov    -0x58(%rbp),%edi
call   1090 <sched_get_priority_min@plt>
mov    %eax,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
movslq -0x64(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    15c1 <main+0x3e1>
mov    $0x0,%al
call   1080 <random@plt>
mov    %eax,-0x84(%rbp)
mov    0x2b0b(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x84(%rbp),%eax
shl    $0x1,%ecx
cltd
idiv   %ecx
mov    %edx,-0x80(%rbp)
mov    0x2ae9(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x80(%rbp),%edx
sub    %eax,%edx
cvtsi2sd %edx,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1080 <random@plt>
mov    %eax,-0x7c(%rbp)
mov    0x2ac0(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x7c(%rbp),%eax
shl    $0x1,%ecx
cltd
idiv   %ecx
mov    %edx,-0x78(%rbp)
mov    0x2aa1(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x78(%rbp),%edx
sub    %eax,%edx
cvtsi2sd %edx,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1070 <zeroDist@plt>
mov    %eax,-0x74(%rbp)
mov    0x2a70(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x74(%rbp),%eax
cmp    %ecx,%eax
jge    15a1 <main+0x3c1>
movsd  0xa71(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xa5f(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    14bb <main+0x2db>
movsd  -0x30(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xa28(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    0x29cf(%rip),%rax
mov    (%rax),%edi
movsd  -0x48(%rbp),%xmm0
lea    0xb58(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
jmp    160a <main+0x42a>
jmp    160f <main+0x42f>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1417 <main+0x237>
mov    0x2994(%rip),%rax
mov    (%rax),%edi
lea    0xb2b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x68(%rbp)
lea    -0x50(%rbp),%rdi
call   10f0 <wait@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
jle    1670 <main+0x490>
mov    -0x50(%rbp),%edi
call   10c0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     166b <main+0x48b>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    163b <main+0x45b>
mov    -0x68(%rbp),%eax
cmp    -0x54(%rbp),%eax
jne    168a <main+0x4aa>
mov    0x292d(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    0x292f(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    0x2dd5(%rip),%rax
mov    (%rax),%r14d
mov    $0xf4240,%r12d
cmp    $0x2,%edi
jl     128f <main+0xaf>
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
call   10a0 <atol@plt>
test   %eax,%eax
jg     1233 <main+0x53>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
lea    0xde9(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    13db <main+0x1fb>
mov    %eax,%r12d
cmp    $0x3,%ebp
jb     128f <main+0xaf>
mov    0x10(%r15),%rbp
lea    0xdd9(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     128f <main+0xaf>
lea    0xdd2(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    126e <main+0x8e>
mov    0x2d74(%rip),%rax
jmp    128c <main+0xac>
lea    0xdc1(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    14eb <main+0x30b>
mov    0x2d14(%rip),%rax
mov    (%rax),%r14d
mov    0x2d22(%rip),%r15
mov    (%r15),%ebp
xor    %edi,%edi
call   1030 <sched_getscheduler@plt>
lea    0xdb6(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r15),%edi
lea    0xdc0(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0x18(%rsp),%rdx
xor    %edi,%edi
mov    %r14d,%esi
call   1040 <sched_setscheduler@plt>
test   %rax,%rax
jne    138f <main+0x1af>
mov    (%r15),%ebp
xor    %edi,%edi
call   1030 <sched_getscheduler@plt>
lea    0xdce(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r15),%edi
lea    0xdd4(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1100 <fork@plt>
test   %eax,%eax
je     139d <main+0x1bd>
cmp    $0xffffffff,%eax
je     13c2 <main+0x1e2>
add    $0x1,%ebp
cmp    %ebp,%r12d
jne    1310 <main+0x130>
mov    (%r15),%edi
lea    0xe1e(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xc(%rsp),%rdi
call   10f0 <wait@plt>
test   %eax,%eax
jle    137c <main+0x19c>
xor    %ebx,%ebx
lea    0xc(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%edi
call   10c0 <WIFEXITED@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebx
mov    %rbp,%rdi
call   10f0 <wait@plt>
test   %eax,%eax
jg     1360 <main+0x180>
cmp    %r12d,%ebx
jne    13db <main+0x1fb>
mov    0x2c28(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    0xd08(%rip),%rdi
call   10b0 <perror@plt>
jmp    13db <main+0x1fb>
mov    (%r15),%edi
lea    0xd7f(%rip),%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14d,%edi
test   $0x1,%bpl
jne    13e9 <main+0x209>
call   10e0 <sched_get_priority_max@plt>
jmp    13ee <main+0x20e>
mov    0x2c07(%rip),%rax
mov    (%rax),%edi
lea    0xd2a(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2bde(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
call   1090 <sched_get_priority_min@plt>
mov    %eax,0x18(%rsp)
xorpd  %xmm1,%xmm1
mov    $0xf4240,%ebx
mov    0x2be6(%rip),%rbp
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
jmp    142b <main+0x24b>
xchg   %ax,%ax
movsd  0x20(%rsp),%xmm1
movsd  0xbe2(%rip),%xmm2
addsd  %xmm2,%xmm1
add    $0xffffffff,%ebx
je     14c1 <main+0x2e1>
movsd  %xmm1,0x20(%rsp)
xor    %eax,%eax
call   1080 <random@plt>
mov    0x0(%rbp),%ecx
mov    %ecx,%esi
shr    $0x1f,%esi
add    %ecx,%esi
mov    %esi,%ecx
sar    %ecx
and    $0xfffffffe,%esi
cltd
idiv   %esi
sub    %ecx,%edx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
movsd  %xmm0,0x28(%rsp)
xor    %eax,%eax
call   1080 <random@plt>
mov    0x0(%rbp),%ecx
mov    %ecx,%esi
shr    $0x1f,%esi
add    %ecx,%esi
mov    %esi,%ecx
sar    %ecx
and    $0xfffffffe,%esi
cltd
idiv   %esi
sub    %ecx,%edx
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
movsd  0x28(%rsp),%xmm0
call   1070 <zeroDist@plt>
mov    0x0(%rbp),%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
cmp    %edx,%eax
jge    1410 <main+0x230>
movsd  0x10(%rsp),%xmm0
movsd  0xb54(%rip),%xmm2
addsd  %xmm2,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x20(%rsp),%xmm1
jmp    141e <main+0x23e>
movsd  0x10(%rsp),%xmm0
divsd  %xmm1,%xmm0
mulsd  0xb35(%rip),%xmm0
mov    (%r15),%edi
lea    0xc72(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    0x2ade(%rip),%rax
mov    (%rax),%edi
lea    0xb44(%rip),%rsi
jmp    1227 <main+0x47>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_OTHER = global i32 0
@stderr = global i32 0
@.str = [15 x i8] c"Bad pro value\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [12 x i8] c"SCHED_OTHER\00"
@.str.2 = [11 x i8] c"SCHED_FIFO\00"
@SCHED_FIFO = global i32 0
@.str.3 = [9 x i8] c"SCHED_RR\00"
@SCHED_RR = global i32 0
@.str.4 = [30 x i8] c"Unhandeled scheduling policy\0A\00"
@stdout = global i32 0
@.str.5 = [31 x i8] c"Current Scheduling Policy: %d\0A\00"
@.str.6 = [34 x i8] c"Setting Scheduling Policy to: %d\0A\00"
@.str.7 = [31 x i8] c"Error setting scheduler policy\00"
@.str.8 = [27 x i8] c"New Scheduling Policy: %d\0A\00"
@.str.9 = [36 x i8] c"Creating %d simultanious processes\0A\00"
@.str.10 = [42 x i8] c"The child process %d could not be forked\0A\00"
@.str.11 = [41 x i8] c"Process %d correctly forked with PID %d\0A\00"
@RAND_MAX = global i32 0
@.str.12 = [9 x i8] c"pi = %f\0A\00"
@.str.13 = [51 x i8] c"\0AWaiting for all of the running processes to exit\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca %struct.sched_param
%18 = alloca i32
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 1000000, i64* %6
store double 0.000000e+00, double* %9
store double 0.000000e+00, double* %10
store double 0.000000e+00, double* %11
store double 0.000000e+00, double* %12
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 2
br i1 %21, label %22, label %23
22: ; preds = %2
store i32 1000000, i32* %15
br label %23
23: ; preds = %22, %2
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 3
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = load i32, i32* @SCHED_OTHER
store i32 %27, i32* %16
br label %28
28: ; preds = %26, %23
%29 = load i32, i32* %4
%30 = icmp sgt i32 %29, 1
br i1 %30, label %31, label %44
31: ; preds = %28
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @atol(i8* %34)
store i32 %35, i32* %15
%36 = load i32, i32* %15
%37 = icmp slt i32 %36, 1
br i1 %37, label %38, label %43
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %31
br label %44
44: ; preds = %43, %28
%45 = load i32, i32* %4
%46 = icmp sgt i32 %45, 2
br i1 %46, label %47, label %79
47: ; preds = %44
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = call i32 @strcmp(i8* %50, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%52 = icmp ne i32 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %47
%54 = load i32, i32* @SCHED_OTHER
store i32 %54, i32* %16
br label %78
55: ; preds = %47
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 2
%58 = load i8*, i8** %57
%59 = call i32 @strcmp(i8* %58, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%60 = icmp ne i32 %59, 0
br i1 %60, label %63, label %61
61: ; preds = %55
%62 = load i32, i32* @SCHED_FIFO
store i32 %62, i32* %16
br label %77
63: ; preds = %55
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 2
%66 = load i8*, i8** %65
%67 = call i32 @strcmp(i8* %66, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%68 = icmp ne i32 %67, 0
br i1 %68, label %71, label %69
69: ; preds = %63
%70 = load i32, i32* @SCHED_RR
store i32 %70, i32* %16
br label %76
71: ; preds = %63
%72 = load i32, i32* @stderr
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %69
br label %77
77: ; preds = %76, %61
br label %78
78: ; preds = %77, %53
br label %79
79: ; preds = %78, %44
%80 = load i32, i32* @stdout
%81 = call i32 @sched_getscheduler(i32 0)
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %81)
%83 = load i32, i32* @stdout
%84 = load i32, i32* %16
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 %84)
%86 = load i32, i32* %16
%87 = call i64 @sched_setscheduler(i32 0, i32 %86, %struct.sched_param* %17)
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %93
89: ; preds = %79
%90 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%91 = load i32, i32* @EXIT_FAILURE
%92 = call i32 @exit(i32 %91)
unreachable
93: ; preds = %79
%94 = load i32, i32* @stdout
%95 = call i32 @sched_getscheduler(i32 0)
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i32 %95)
%97 = load i32, i32* @stdout
%98 = load i32, i32* %15
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.9, i64 0, i64 0), i32 %98)
store i32 0, i32* %18
br label %100
100: ; preds = %184, %93
%101 = load i32, i32* %18
%102 = load i32, i32* %15
%103 = icmp slt i32 %101, %102
br i1 %103, label %104, label %187
104: ; preds = %100
%105 = call i32 (...) @fork()
store i32 %105, i32* %13
%106 = icmp eq i32 %105, -1
br i1 %106, label %107, label %113
107: ; preds = %104
%108 = load i32, i32* @stderr
%109 = load i32, i32* %18
%110 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0), i32 %109)
%111 = load i32, i32* @EXIT_FAILURE
%112 = call i32 @exit(i32 %111)
unreachable
113: ; preds = %104
%114 = load i32, i32* %13
%115 = icmp eq i32 %114, 0
br i1 %115, label %116, label %182
116: ; preds = %113
%117 = load i32, i32* @stdout
%118 = load i32, i32* %18
%119 = load i32, i32* %13
%120 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.11, i64 0, i64 0), i32 %118, i32 %119)
%121 = load i32, i32* %18
%122 = srem i32 %121, 2
%123 = icmp eq i32 %122, 0
br i1 %123, label %124, label %128
124: ; preds = %116
%125 = load i32, i32* %16
%126 = call i32 @sched_get_priority_max(i32 %125)
%127 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %17, i32 0, i32 0
store i32 %126, i32* %127
br label %132
128: ; preds = %116
%129 = load i32, i32* %16
%130 = call i32 @sched_get_priority_min(i32 %129)
%131 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %17, i32 0, i32 0
store i32 %130, i32* %131
br label %132
132: ; preds = %128, %124
store i32 0, i32* %18
br label %133
133: ; preds = %169, %132
%134 = load i32, i32* %18
%135 = sext i32 %134 to i64
%136 = load i64, i64* %6
%137 = icmp slt i64 %135, %136
br i1 %137, label %138, label %172
138: ; preds = %133
%139 = call i32 (...) @random()
%140 = load i32, i32* @RAND_MAX
%141 = sdiv i32 %140, 2
%142 = mul nsw i32 %141, 2
%143 = srem i32 %139, %142
%144 = load i32, i32* @RAND_MAX
%145 = sdiv i32 %144, 2
%146 = sub nsw i32 %143, %145
%147 = sitofp i32 %146 to double
store double %147, double* %7
%148 = call i32 (...) @random()
%149 = load i32, i32* @RAND_MAX
%150 = sdiv i32 %149, 2
%151 = mul nsw i32 %150, 2
%152 = srem i32 %148, %151
%153 = load i32, i32* @RAND_MAX
%154 = sdiv i32 %153, 2
%155 = sub nsw i32 %152, %154
%156 = sitofp i32 %155 to double
store double %156, double* %8
%157 = load double, double* %7
%158 = load double, double* %8
%159 = call i32 @zeroDist(double %157, double %158)
%160 = load i32, i32* @RAND_MAX
%161 = sdiv i32 %160, 2
%162 = icmp slt i32 %159, %161
br i1 %162, label %163, label %166
163: ; preds = %138
%164 = load double, double* %9
%165 = fadd double %164, 1.000000e+00
store double %165, double* %9
br label %166
166: ; preds = %163, %138
%167 = load double, double* %10
%168 = fadd double %167, 1.000000e+00
store double %168, double* %10
br label %169
169: ; preds = %166
%170 = load i32, i32* %18
%171 = add nsw i32 %170, 1
store i32 %171, i32* %18
br label %133
172: ; preds = %133
%173 = load double, double* %9
%174 = load double, double* %10
%175 = fdiv double %173, %174
store double %175, double* %11
%176 = load double, double* %11
%177 = fmul double %176, 4.000000e+00
store double %177, double* %12
%178 = load i32, i32* @stdout
%179 = load double, double* %12
%180 = call i32 (i32, i8*, ...) @fprintf(i32 %178, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), double %179)
%181 = call i32 @exit(i32 0)
unreachable
182: ; preds = %113
br label %183
183: ; preds = %182
br label %184
184: ; preds = %183
%185 = load i32, i32* %18
%186 = add nsw i32 %185, 1
store i32 %186, i32* %18
br label %100
187: ; preds = %100
%188 = load i32, i32* @stdout
%189 = call i32 (i32, i8*, ...) @fprintf(i32 %188, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.13, i64 0, i64 0))
store i32 0, i32* %19
br label %190
190: ; preds = %200, %187
%191 = call i32 @wait(i32* %14)
store i32 %191, i32* %13
%192 = icmp sgt i32 %191, 0
br i1 %192, label %193, label %201
193: ; preds = %190
%194 = load i32, i32* %14
%195 = call i64 @WIFEXITED(i32 %194)
%196 = icmp ne i64 %195, 0
br i1 %196, label %197, label %200
197: ; preds = %193
%198 = load i32, i32* %19
%199 = add nsw i32 %198, 1
store i32 %199, i32* %19
br label %200
200: ; preds = %197, %193
br label %190
201: ; preds = %190
%202 = load i32, i32* %19
%203 = load i32, i32* %15
%204 = icmp eq i32 %202, %203
br i1 %204, label %205, label %208
205: ; preds = %201
%206 = load i32, i32* @EXIT_SUCCESS
%207 = call i32 @exit(i32 %206)
unreachable
208: ; preds = %201
%209 = load i32, i32* @EXIT_FAILURE
%210 = call i32 @exit(i32 %209)
unreachable
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_OTHER = global i32 0
@stderr = global i32 0
@.str = [15 x i8] c"Bad pro value\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [12 x i8] c"SCHED_OTHER\00"
@.str.2 = [11 x i8] c"SCHED_FIFO\00"
@SCHED_FIFO = global i32 0
@.str.3 = [9 x i8] c"SCHED_RR\00"
@SCHED_RR = global i32 0
@.str.4 = [30 x i8] c"Unhandeled scheduling policy\0A\00"
@stdout = global i32 0
@.str.5 = [31 x i8] c"Current Scheduling Policy: %d\0A\00"
@.str.6 = [34 x i8] c"Setting Scheduling Policy to: %d\0A\00"
@.str.7 = [31 x i8] c"Error setting scheduler policy\00"
@.str.8 = [27 x i8] c"New Scheduling Policy: %d\0A\00"
@.str.9 = [36 x i8] c"Creating %d simultanious processes\0A\00"
@.str.10 = [42 x i8] c"The child process %d could not be forked\0A\00"
@.str.11 = [41 x i8] c"Process %d correctly forked with PID %d\0A\00"
@RAND_MAX = global i32 0
@.str.12 = [9 x i8] c"pi = %f\0A\00"
@.str.13 = [51 x i8] c"\0AWaiting for all of the running processes to exit\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sched_param
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.sched_param* %4 to i8*
%7 = icmp slt i32 %0, 3
%8 = load i32, i32* @SCHED_OTHER
%9 = select i1 %7, i32 %8, i32 undef
%10 = icmp sgt i32 %0, 1
br i1 %10, label %11, label %43
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @atol(i8* %13)
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %11
%22 = icmp ugt i32 %0, 2
br i1 %22, label %23, label %43
23: ; preds = %21
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = tail call i32 @strcmp(i8* dereferenceable(1) %25, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i32 %26, 0
br i1 %27, label %43, label %28
28: ; preds = %23
%29 = tail call i32 @strcmp(i8* dereferenceable(1) %25, i8* dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = load i32, i32* @SCHED_FIFO
br label %43
33: ; preds = %28
%34 = tail call i32 @strcmp(i8* dereferenceable(1) %25, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = load i32, i32* @SCHED_RR
br label %43
38: ; preds = %33
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = tail call i32 @exit(i32 %41)
unreachable
43: ; preds = %2, %23, %36, %31, %21
%44 = phi i32 [ %14, %36 ], [ %14, %31 ], [ %14, %21 ], [ %14, %23 ], [ 1000000, %2 ]
%45 = phi i32 [ %37, %36 ], [ %32, %31 ], [ %9, %21 ], [ %8, %23 ], [ %9, %2 ]
%46 = load i32, i32* @stdout
%47 = tail call i32 @sched_getscheduler(i32 0)
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %47)
%49 = load i32, i32* @stdout
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 %45)
%51 = call i64 @sched_setscheduler(i32 0, i32 %45, %struct.sched_param* %4)
%52 = icmp eq i64 %51, 0
br i1 %52, label %57, label %53
53: ; preds = %43
%54 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %43
%58 = load i32, i32* @stdout
%59 = call i32 @sched_getscheduler(i32 0)
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i32 %59)
%61 = load i32, i32* @stdout
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.9, i64 0, i64 0), i32 %44)
br label %68
63: ; preds = %121
%64 = load i32, i32* @stdout
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.13, i64 0, i64 0))
%66 = call i32 @wait(i32* %3)
%67 = icmp sgt i32 %66, 0
br i1 %67, label %124, label %133
68: ; preds = %57, %121
%69 = phi i32 [ %122, %121 ], [ 0, %57 ]
%70 = call i32 (...) @fork()
switch i32 %70, label %121 [
i32 -1, label %71
i32 0, label %76
]
71: ; preds = %68
%72 = load i32, i32* @stderr
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0), i32 %69)
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %68
%77 = load i32, i32* @stdout
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.11, i64 0, i64 0), i32 %69, i32 0)
%79 = and i32 %69, 1
%80 = icmp eq i32 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %76
%82 = call i32 @sched_get_priority_max(i32 %45)
br label %85
83: ; preds = %76
%84 = call i32 @sched_get_priority_min(i32 %45)
br label %85
85: ; preds = %83, %81
%86 = phi i32 [ %82, %81 ], [ %84, %83 ]
%87 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i64 0, i32 0
store i32 %86, i32* %87
br label %88
88: ; preds = %85, %88
%89 = phi i32 [ 0, %85 ], [ %113, %88 ]
%90 = phi double [ 0.000000e+00, %85 ], [ %112, %88 ]
%91 = phi double [ 0.000000e+00, %85 ], [ %111, %88 ]
%92 = call i32 (...) @random()
%93 = load i32, i32* @RAND_MAX
%94 = sdiv i32 %93, 2
%95 = shl nsw i32 %94, 1
%96 = srem i32 %92, %95
%97 = sub nsw i32 %96, %94
%98 = sitofp i32 %97 to double
%99 = call i32 (...) @random()
%100 = load i32, i32* @RAND_MAX
%101 = sdiv i32 %100, 2
%102 = shl nsw i32 %101, 1
%103 = srem i32 %99, %102
%104 = sub nsw i32 %103, %101
%105 = sitofp i32 %104 to double
%106 = call i32 @zeroDist(double %98, double %105)
%107 = load i32, i32* @RAND_MAX
%108 = sdiv i32 %107, 2
%109 = icmp slt i32 %106, %108
%110 = fadd double %91, 1.000000e+00
%111 = select i1 %109, double %110, double %91
%112 = fadd double %90, 1.000000e+00
%113 = add nuw nsw i32 %89, 1
%114 = icmp eq i32 %113, 1000000
br i1 %114, label %115, label %88
115: ; preds = %88
%116 = fdiv double %111, %112
%117 = fmul double %116, 4.000000e+00
%118 = load i32, i32* @stdout
%119 = call i32 (i32, i8*, ...) @fprintf(i32 %118, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), double %117)
%120 = call i32 @exit(i32 0)
unreachable
121: ; preds = %68
%122 = add nuw nsw i32 %69, 1
%123 = icmp eq i32 %122, %44
br i1 %123, label %63, label %68
124: ; preds = %63, %124
%125 = phi i32 [ %130, %124 ], [ 0, %63 ]
%126 = load i32, i32* %3
%127 = call i64 @WIFEXITED(i32 %126)
%128 = icmp ne i64 %127, 0
%129 = zext i1 %128 to i32
%130 = add nuw nsw i32 %125, %129
%131 = call i32 @wait(i32* %3)
%132 = icmp sgt i32 %131, 0
br i1 %132, label %124, label %133
133: ; preds = %124, %63
%134 = phi i32 [ 0, %63 ], [ %130, %124 ]
%135 = icmp eq i32 %134, %44
br i1 %135, label %136, label %139
136: ; preds = %133
%137 = load i32, i32* @EXIT_SUCCESS
%138 = call i32 @exit(i32 %137)
unreachable
139: ; preds = %133
%140 = load i32, i32* @EXIT_FAILURE
%141 = call i32 @exit(i32 %140)
unreachable
}