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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int O_CREAT;
int O_RDONLY;
int O_SYNC;
int O_TRUNC;
int O_WRONLY;
int SCHED_FIFO;
int SCHED_OTHER;
int SCHED_RR;
int /*<<< orphan*/ SEEK_SET;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWUSR;
scalar_t__ WIFEXITED(int);
int atoi(char *);
scalar_t__ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int getpid();
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
char *malloc(int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ sched_get_priority_max(int);
int sched_getscheduler(int /*<<< orphan*/);
scalar_t__ sched_setscheduler(int /*<<< orphan*/, int, struct sched_param *);
int snprintf(char *, int, char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int wait(int *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int rv;
  int inputFD;
  int outputFD;
  char inputFilename[80];
  char outputFilename[80];
  char outputFilenameBase[80];
  ssize_t transfersize = 0;
  ssize_t blocksize = 0;
  char *transferBuffer = NULL;
  ssize_t buffersize;
  ssize_t bytesRead = 0;
  ssize_t totalBytesRead = 0;
  int totalReads = 0;
  ssize_t bytesWritten = 0;
  ssize_t totalBytesWritten = 0;
  int totalWrites = 0;
  int inputFileResets = 0;
  pid_t pid;
  int test;
  int pro;
  int policy;
  struct sched_param param;
  blocksize = 1024;
  transfersize = 1024 * 100;
  strncpy(inputFilename, "rwinput", 80);
  strncpy(outputFilenameBase, "rwoutput", 80);
  if (argc < 2) {
    exit(EXIT_FAILURE);
  } else {
    pro = atoi(argv[1]);
    if (pro < 1) {
      fprintf(stderr, "Need more processes\n");
      exit(EXIT_FAILURE);
    }
  }
  if (argc < 3) {
    policy = SCHED_OTHER;
  } else {
    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);
    }
  }
  param.sched_priority = sched_get_priority_max(policy);
  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 forked with PID %d\n", i, pid);
      if (blocksize > transfersize) {
        fprintf(stderr, "blocksize can not exceed transfersize\n");
        exit(EXIT_FAILURE);
      }
      if (transfersize % blocksize) {
        fprintf(stderr, "blocksize must be multiple of transfersize\n");
        exit(EXIT_FAILURE);
      }
      buffersize = blocksize;
      if (!(transferBuffer = malloc(buffersize * sizeof(*transferBuffer)))) {
        perror("Failed to allocate transfer buffer");
        exit(EXIT_FAILURE);
      }
      if ((inputFD = open(inputFilename, O_RDONLY | O_SYNC)) < 0) {
        perror("Failed to open input file");
        exit(EXIT_FAILURE);
      }
      rv = snprintf(outputFilename, 80, "%s-%d", outputFilenameBase, getpid());
      if (rv > 80) {
        fprintf(stderr,
                "Output filenmae length exceeds limit of %d characters.\n", 80);
        exit(EXIT_FAILURE);
      } else if (rv < 0) {
        perror("Failed to generate output filename");
        exit(EXIT_FAILURE);
      }
      if ((outputFD =
               open(outputFilename, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC,
                    S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)) < 0) {
        perror("Failed to open output file");
        exit(EXIT_FAILURE);
      }
      fprintf(stdout, "Reading from %s and writing to %s\n", inputFilename,
              outputFilename);
      do {
        bytesRead = read(inputFD, transferBuffer, buffersize);
        if (bytesRead < 0) {
          perror("Error reading input file");
          exit(EXIT_FAILURE);
        } else {
          totalBytesRead += bytesRead;
          totalReads++;
        }
        if (bytesRead == blocksize) {
          bytesWritten = write(outputFD, transferBuffer, bytesRead);
          if (bytesWritten < 0) {
            perror("Error writing output file");
            exit(EXIT_FAILURE);
          } else {
            totalBytesWritten += bytesWritten;
            totalWrites++;
          }
        } else {
          if (lseek(inputFD, 0, SEEK_SET)) {
            perror("Error resetting to beginning of file");
            exit(EXIT_FAILURE);
          }
          inputFileResets++;
        }
      } while (totalBytesWritten < transfersize);
      fprintf(stdout, "Read:    %zd bytes in %d reads\n", totalBytesRead,
              totalReads);
      fprintf(stdout, "Written: %zd bytes in %d writes\n", totalBytesWritten,
              totalWrites);
      fprintf(stdout, "Read input file in %d pass%s\n", (inputFileResets + 1),
              (inputFileResets ? "es" : ""));
      fprintf(stdout, "Processed %zd bytes in blocks of %zd bytes\n",
              transfersize, blocksize);
      free(transferBuffer);
      if (close(outputFD)) {
        perror("Failed to close output file");
        exit(EXIT_FAILURE);
      }
      if (close(inputFD)) {
        perror("Failed to close input file");
        exit(EXIT_FAILURE);
      }
      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)) {
      fprintf(stdout, "Child process %d has been reaped correctly.\n", pid);
      reap++;
    }
  }
  if (reap == pro) {
    fprintf(stdout, "%d child process forked, %d have been reaped.\n", pro,
            reap);
    exit(EXIT_SUCCESS);
  } else {
    fprintf(stderr, "Something went wrong.\n");
    exit(EXIT_FAILURE);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x114(%rbp)
movl   $0x0,-0x118(%rbp)
movq   $0x0,-0x120(%rbp)
movl   $0x0,-0x128(%rbp)
movl   $0x0,-0x12c(%rbp)
movl   $0x0,-0x130(%rbp)
movl   $0x0,-0x134(%rbp)
movl   $0x0,-0x138(%rbp)
movl   $0x0,-0x13c(%rbp)
movl   $0x0,-0x140(%rbp)
movl   $0x400,-0x118(%rbp)
movl   $0x19000,-0x114(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xd13(%rip),%rsi
mov    $0x50,%edx
call   1050 <strncpy@plt>
lea    -0x110(%rbp),%rdi
lea    0xd03(%rip),%rsi
mov    $0x50,%edx
call   1050 <strncpy@plt>
cmpl   $0x2,-0x8(%rbp)
jge    1327 <main+0xd7>
mov    0x2c60(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1120 <atoi@plt>
mov    %eax,-0x14c(%rbp)
cmpl   $0x1,-0x14c(%rbp)
jge    136c <main+0x11c>
mov    0x2c5a(%rip),%rax
mov    (%rax),%edi
lea    0xcba(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x2c1b(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
jmp    1371 <main+0x121>
cmpl   $0x3,-0x8(%rbp)
jge    138f <main+0x13f>
mov    0x2c1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x150(%rbp)
jmp    1456 <main+0x206>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xc88(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%eax
jne    13c0 <main+0x170>
mov    0x2bed(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x150(%rbp)
jmp    1451 <main+0x201>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xc63(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%eax
jne    13f1 <main+0x1a1>
mov    0x2bd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x150(%rbp)
jmp    144c <main+0x1fc>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xc3d(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%eax
jne    1422 <main+0x1d2>
mov    0x2b43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x150(%rbp)
jmp    1447 <main+0x1f7>
mov    0x2b7f(%rip),%rax
mov    (%rax),%edi
lea    0xc14(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x2b40(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
jmp    144c <main+0x1fc>
jmp    1451 <main+0x201>
jmp    1456 <main+0x206>
mov    -0x150(%rbp),%edi
call   1150 <sched_get_priority_max@plt>
mov    %eax,-0x158(%rbp)
mov    0x2b02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x164(%rbp)
xor    %edi,%edi
call   1040 <sched_getscheduler@plt>
mov    -0x164(%rbp),%edi
mov    %eax,%edx
lea    0xbd8(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x2ad6(%rip),%rax
mov    (%rax),%edi
mov    -0x150(%rbp),%edx
lea    0xbda(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x150(%rbp),%esi
xor    %edi,%edi
lea    -0x158(%rbp),%rdx
call   10a0 <sched_setscheduler@plt>
cmp    $0x0,%rax
je     14e8 <main+0x298>
lea    0xbd0(%rip),%rdi
call   1110 <perror@plt>
mov    0x2a9f(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
mov    0x2a81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x168(%rbp)
xor    %edi,%edi
call   1040 <sched_getscheduler@plt>
mov    -0x168(%rbp),%edi
mov    %eax,%edx
lea    0xbb7(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x2a55(%rip),%rax
mov    (%rax),%edi
mov    -0x14c(%rbp),%edx
lea    0xbb5(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
movl   $0x0,-0x15c(%rbp)
mov    -0x15c(%rbp),%eax
cmp    -0x14c(%rbp),%eax
jge    1a6f <main+0x81f>
mov    $0x0,%al
call   1170 <fork@plt>
mov    %eax,-0x144(%rbp)
cmp    $0xffffffff,%eax
jne    158e <main+0x33e>
mov    0x2a3e(%rip),%rax
mov    (%rax),%edi
mov    -0x15c(%rbp),%edx
lea    0xb8a(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x29f9(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
cmpl   $0x0,-0x144(%rbp)
jne    1a51 <main+0x801>
mov    0x29ce(%rip),%rax
mov    (%rax),%edi
mov    -0x15c(%rbp),%edx
mov    -0x144(%rbp),%ecx
lea    0xb76(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x118(%rbp),%eax
cmp    -0x114(%rbp),%eax
jle    15f5 <main+0x3a5>
mov    0x29d1(%rip),%rax
mov    (%rax),%edi
lea    0xb6c(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x2992(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
mov    -0x114(%rbp),%eax
cltd
idivl  -0x118(%rbp)
cmp    $0x0,%edx
je     1630 <main+0x3e0>
mov    0x2996(%rip),%rax
mov    (%rax),%edi
lea    0xb58(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x2957(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
mov    -0x118(%rbp),%eax
mov    %eax,-0x124(%rbp)
movslq -0x124(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10f0 <malloc@plt>
mov    %rax,-0x120(%rbp)
cmp    $0x0,%rax
jne    1679 <main+0x429>
lea    0xb39(%rip),%rdi
call   1110 <perror@plt>
mov    0x290e(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
lea    -0x70(%rbp),%rdi
mov    0x294c(%rip),%rax
mov    (%rax),%esi
mov    0x294b(%rip),%rax
or     (%rax),%esi
mov    $0x0,%al
call   1100 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    16bc <main+0x46c>
lea    0xb19(%rip),%rdi
call   1110 <perror@plt>
mov    0x28cb(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
lea    -0xc0(%rbp),%rax
mov    %rax,-0x178(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x170(%rbp)
mov    $0x0,%al
call   1070 <getpid@plt>
mov    -0x178(%rbp),%rdi
mov    -0x170(%rbp),%rcx
mov    %eax,%r8d
mov    $0x50,%esi
lea    0xae0(%rip),%rdx
call   1080 <snprintf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x50,-0x14(%rbp)
jle    1738 <main+0x4e8>
mov    0x2893(%rip),%rax
mov    (%rax),%edi
lea    0xac4(%rip),%rsi
mov    $0x50,%edx
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x284f(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jge    175c <main+0x50c>
lea    0xad1(%rip),%rdi
call   1110 <perror@plt>
mov    0x282b(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
jmp    1761 <main+0x511>
lea    -0xc0(%rbp),%rdi
mov    0x27e1(%rip),%rax
mov    (%rax),%esi
mov    0x2880(%rip),%rax
or     (%rax),%esi
mov    0x286f(%rip),%rax
or     (%rax),%esi
mov    0x284e(%rip),%rax
or     (%rax),%esi
mov    0x27e5(%rip),%rax
mov    (%rax),%edx
mov    0x2824(%rip),%rax
or     (%rax),%edx
mov    0x27eb(%rip),%rax
or     (%rax),%edx
mov    0x281a(%rip),%rax
or     (%rax),%edx
mov    0x27d1(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1100 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    17e6 <main+0x596>
lea    0xa6a(%rip),%rdi
call   1110 <perror@plt>
mov    0x27a1(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
mov    0x2783(%rip),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rdx
lea    -0xc0(%rbp),%rcx
lea    0xa57(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x18(%rbp),%edi
mov    -0x120(%rbp),%rsi
mov    -0x124(%rbp),%edx
call   10c0 <read@plt>
mov    %eax,-0x128(%rbp)
cmpl   $0x0,-0x128(%rbp)
jge    184a <main+0x5fa>
lea    0xa44(%rip),%rdi
call   1110 <perror@plt>
mov    0x273d(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
mov    -0x128(%rbp),%eax
add    -0x12c(%rbp),%eax
mov    %eax,-0x12c(%rbp)
mov    -0x130(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x130(%rbp)
mov    -0x128(%rbp),%eax
cmp    -0x118(%rbp),%eax
jne    18e5 <main+0x695>
mov    -0x1c(%rbp),%edi
mov    -0x120(%rbp),%rsi
mov    -0x128(%rbp),%edx
call   1060 <write@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0x0,-0x134(%rbp)
jge    18bf <main+0x66f>
lea    0x9e8(%rip),%rdi
call   1110 <perror@plt>
mov    0x26c8(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
mov    -0x134(%rbp),%eax
add    -0x138(%rbp),%eax
mov    %eax,-0x138(%rbp)
mov    -0x13c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13c(%rbp)
jmp    192b <main+0x6db>
mov    -0x18(%rbp),%edi
mov    0x26a9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <lseek@plt>
cmp    $0x0,%rax
je     191c <main+0x6cc>
lea    0x9a5(%rip),%rdi
call   1110 <perror@plt>
mov    0x266b(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
mov    -0x140(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x140(%rbp)
jmp    1930 <main+0x6e0>
mov    -0x138(%rbp),%eax
cmp    -0x114(%rbp),%eax
jl     1808 <main+0x5b8>
mov    0x2627(%rip),%rax
mov    (%rax),%edi
mov    -0x12c(%rbp),%edx
mov    -0x130(%rbp),%ecx
lea    0x975(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x2604(%rip),%rax
mov    (%rax),%edi
mov    -0x138(%rbp),%edx
mov    -0x13c(%rbp),%ecx
lea    0x972(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x25e1(%rip),%rax
mov    (%rax),%edi
mov    -0x140(%rbp),%edx
add    $0x1,%edx
mov    -0x140(%rbp),%esi
lea    0xa7f(%rip),%rcx
lea    0x984(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
lea    0x958(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x25a6(%rip),%rax
mov    (%rax),%edi
mov    -0x114(%rbp),%edx
mov    -0x118(%rbp),%ecx
lea    0x956(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x120(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%edi
call   10b0 <close@plt>
cmp    $0x0,%rax
je     1a1e <main+0x7ce>
lea    0x956(%rip),%rdi
call   1110 <perror@plt>
mov    0x2569(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
mov    -0x18(%rbp),%edi
call   10b0 <close@plt>
cmp    $0x0,%rax
je     1a4a <main+0x7fa>
lea    0x946(%rip),%rdi
call   1110 <perror@plt>
mov    0x253d(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
xor    %edi,%edi
call   1140 <exit@plt>
jmp    1a56 <main+0x806>
jmp    1a5b <main+0x80b>
mov    -0x15c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x15c(%rbp)
jmp    153b <main+0x2eb>
mov    0x24fa(%rip),%rax
mov    (%rax),%edi
lea    0x919(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
movl   $0x0,-0x160(%rbp)
lea    -0x148(%rbp),%rdi
call   1160 <wait@plt>
mov    %eax,-0x144(%rbp)
cmp    $0x0,%eax
jle    1af1 <main+0x8a1>
mov    -0x148(%rbp),%edi
call   1130 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1aec <main+0x89c>
mov    0x24a9(%rip),%rax
mov    (%rax),%edi
mov    -0x144(%rbp),%edx
lea    0x8f5(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x160(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x160(%rbp)
jmp    1a90 <main+0x840>
mov    -0x160(%rbp),%eax
cmp    -0x14c(%rbp),%eax
jne    1b34 <main+0x8e4>
mov    0x2466(%rip),%rax
mov    (%rax),%edi
mov    -0x14c(%rbp),%edx
mov    -0x160(%rbp),%ecx
lea    0x8d9(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x243b(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
mov    0x246d(%rip),%rax
mov    (%rax),%edi
lea    0x8e3(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x242e(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xd93(%rip),%rsi
lea    0x70(%rsp),%rdi
mov    $0x50,%edx
call   1050 <strncpy@plt>
lea    0xd85(%rip),%rsi
lea    0xc0(%rsp),%rdi
mov    $0x50,%edx
call   1050 <strncpy@plt>
cmp    $0x1,%ebp
jle    14b4 <main+0x264>
mov    0x8(%r14),%rdi
call   1120 <atoi@plt>
test   %eax,%eax
jg     12c7 <main+0x77>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
lea    0xd56(%rip),%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
jmp    14b4 <main+0x264>
mov    %eax,%r13d
mov    0x2ccf(%rip),%rbx
cmp    $0x3,%ebp
jb     1327 <main+0xd7>
mov    0x10(%r14),%rbp
lea    0xd45(%rip),%rsi
mov    %rbp,%rdi
call   10d0 <strcmp@plt>
test   %eax,%eax
je     1327 <main+0xd7>
lea    0xd3e(%rip),%rsi
mov    %rbp,%rdi
call   10d0 <strcmp@plt>
test   %eax,%eax
jne    1309 <main+0xb9>
mov    0x2cb1(%rip),%rbx
jmp    1327 <main+0xd7>
lea    0xd2d(%rip),%rsi
mov    %rbp,%rdi
call   10d0 <strcmp@plt>
test   %eax,%eax
jne    1535 <main+0x2e5>
mov    0x2c31(%rip),%rbx
mov    (%rbx),%ebp
mov    %ebp,%edi
call   1150 <sched_get_priority_max@plt>
mov    %eax,0x18(%rsp)
mov    0x2c35(%rip),%r12
mov    (%r12),%r14d
xor    %edi,%edi
call   1040 <sched_getscheduler@plt>
lea    0xd17(%rip),%rsi
mov    %r14d,%edi
mov    %eax,%edx
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    (%r12),%edi
lea    0xd1f(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   10e0 <fprintf@plt>
lea    0x18(%rsp),%rdx
xor    %edi,%edi
mov    %ebp,%esi
call   10a0 <sched_setscheduler@plt>
test   %rax,%rax
jne    1455 <main+0x205>
mov    (%r12),%ebp
xor    %edi,%edi
call   1040 <sched_getscheduler@plt>
lea    0xd2e(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    (%r12),%edi
lea    0xd33(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   10e0 <fprintf@plt>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1170 <fork@plt>
test   %eax,%eax
je     1463 <main+0x213>
cmp    $0xffffffff,%eax
je     149b <main+0x24b>
add    $0x1,%ebp
cmp    %ebp,%r13d
jne    13c0 <main+0x170>
mov    (%r12),%edi
lea    0xf5a(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   10e0 <fprintf@plt>
lea    0x20(%rsp),%rdi
call   1160 <wait@plt>
test   %eax,%eax
jle    14c2 <main+0x272>
mov    %eax,%ebp
lea    0x20(%rsp),%r15
lea    0xf64(%rip),%r14
xor    %ebx,%ebx
jmp    1432 <main+0x1e2>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1160 <wait@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    14c2 <main+0x272>
mov    0x20(%rsp),%edi
call   1130 <WIFEXITED@plt>
test   %rax,%rax
je     1420 <main+0x1d0>
mov    (%r12),%edi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   10e0 <fprintf@plt>
add    $0x1,%ebx
jmp    1420 <main+0x1d0>
lea    0xc49(%rip),%rdi
call   1110 <perror@plt>
jmp    14b4 <main+0x264>
mov    (%r12),%edi
lea    0xcbf(%rip),%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    $0x400,%edi
call   10f0 <malloc@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
jne    14ed <main+0x29d>
lea    0xcb8(%rip),%rdi
call   1110 <perror@plt>
jmp    14b4 <main+0x264>
mov    0x2b06(%rip),%rax
mov    (%rax),%edi
lea    0xc58(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    0x2ac5(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
cmp    %r13d,%ebx
jne    1520 <main+0x2d0>
mov    (%r12),%edi
lea    0xed3(%rip),%rsi
mov    %r13d,%edx
mov    %r13d,%ecx
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    0x2a82(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
mov    0x2adc(%rip),%rax
mov    0x2add(%rip),%rbx
mov    (%rbx),%esi
or     (%rax),%esi
lea    0x70(%rsp),%rdi
xor    %eax,%eax
call   1100 <open@plt>
mov    %eax,(%rsp)
test   %eax,%eax
jns    154a <main+0x2fa>
lea    0xc56(%rip),%rdi
call   1110 <perror@plt>
jmp    14b4 <main+0x264>
mov    0x2a81(%rip),%rax
mov    (%rax),%edi
lea    0xea4(%rip),%rsi
jmp    12bb <main+0x6b>
mov    0x2a6c(%rip),%rax
mov    (%rax),%edi
lea    0xb01(%rip),%rsi
jmp    12bb <main+0x6b>
xor    %eax,%eax
call   1070 <getpid@plt>
lea    0xc31(%rip),%rdx
lea    0x20(%rsp),%rdi
lea    0xc0(%rsp),%rcx
mov    $0x50,%esi
mov    %eax,%r8d
call   1080 <snprintf@plt>
cmp    $0x51,%eax
jl     1591 <main+0x341>
mov    0x2a2a(%rip),%rax
mov    (%rax),%edi
lea    0xc08(%rip),%rsi
mov    $0x50,%edx
jmp    14ad <main+0x25d>
test   %eax,%eax
jns    15a6 <main+0x356>
lea    0xc2b(%rip),%rdi
call   1110 <perror@plt>
jmp    14b4 <main+0x264>
mov    0x29a3(%rip),%rax
mov    0x2a44(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2a31(%rip),%rax
or     (%rax),%esi
or     (%rbx),%esi
mov    0x29ae(%rip),%rax
mov    0x29ef(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x29b4(%rip),%rax
or     (%rax),%edx
mov    0x29e3(%rip),%rax
or     (%rax),%edx
mov    0x299a(%rip),%rax
or     (%rax),%edx
xor    %ebx,%ebx
lea    0x20(%rsp),%rdi
xor    %eax,%eax
call   1100 <open@plt>
mov    %eax,0x4(%rsp)
test   %eax,%eax
jns    1617 <main+0x3c7>
lea    0xbdd(%rip),%rdi
call   1110 <perror@plt>
jmp    14b4 <main+0x264>
mov    (%r12),%edi
lea    0xbe3(%rip),%rsi
lea    0x70(%rsp),%rdx
lea    0x20(%rsp),%rcx
xor    %eax,%eax
call   10e0 <fprintf@plt>
xor    %r14d,%r14d
xor    %ebp,%ebp
xor    %r13d,%r13d
xor    %eax,%eax
mov    %rax,0x8(%rsp)
jmp    1688 <main+0x438>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x2941(%rip),%rax
mov    (%rax),%edx
mov    (%rsp),%edi
xor    %esi,%esi
call   1090 <lseek@plt>
test   %rax,%rax
jne    1780 <main+0x530>
mov    0x8(%rsp),%rax
add    $0x1,%eax
mov    %rax,0x8(%rsp)
add    %r15d,%ebx
add    $0x1,%r14d
cmp    $0x19000,%ebp
jge    16dc <main+0x48c>
mov    (%rsp),%edi
mov    0x10(%rsp),%rsi
mov    $0x400,%edx
call   10c0 <read@plt>
test   %eax,%eax
js     16cb <main+0x47b>
mov    %eax,%r15d
cmp    $0x400,%eax
jne    1650 <main+0x400>
mov    0x4(%rsp),%edi
mov    0x10(%rsp),%rsi
mov    $0x400,%edx
call   1060 <write@plt>
test   %eax,%eax
js     1791 <main+0x541>
add    %eax,%ebp
add    $0x1,%r13d
jmp    1679 <main+0x429>
lea    0xb56(%rip),%rdi
call   1110 <perror@plt>
jmp    14b4 <main+0x264>
mov    (%r12),%edi
lea    0xb99(%rip),%rsi
mov    %ebx,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    (%r12),%edi
lea    0xba2(%rip),%rsi
mov    %ebp,%edx
mov    %r13d,%ecx
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    (%r12),%edi
mov    0x8(%rsp),%rax
lea    0x1(%rax),%edx
test   %eax,%eax
lea    0xcb4(%rip),%rax
lea    0xbb9(%rip),%rcx
cmove  %rax,%rcx
lea    0xb90(%rip),%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    (%r12),%edi
lea    0xb9f(%rip),%rsi
mov    $0x19000,%edx
mov    $0x400,%ecx
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x4(%rsp),%edi
call   10b0 <close@plt>
test   %rax,%rax
jne    17a2 <main+0x552>
mov    (%rsp),%edi
call   10b0 <close@plt>
test   %rax,%rax
jne    17b3 <main+0x563>
xor    %edi,%edi
call   1140 <exit@plt>
lea    0xad4(%rip),%rdi
call   1110 <perror@plt>
jmp    14b4 <main+0x264>
lea    0xaa9(%rip),%rdi
call   1110 <perror@plt>
jmp    14b4 <main+0x264>
lea    0xb65(%rip),%rdi
call   1110 <perror@plt>
jmp    14b4 <main+0x264>
lea    0xb70(%rip),%rdi
call   1110 <perror@plt>
jmp    14b4 <main+0x264>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [8 x i8] c"rwinput\00"
@.str.1 = [9 x i8] c"rwoutput\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.2 = [21 x i8] c"Need more processes\0A\00"
@SCHED_OTHER = global i32 0
@.str.3 = [12 x i8] c"SCHED_OTHER\00"
@.str.4 = [11 x i8] c"SCHED_FIFO\00"
@SCHED_FIFO = global i32 0
@.str.5 = [9 x i8] c"SCHED_RR\00"
@SCHED_RR = global i32 0
@.str.6 = [30 x i8] c"Unhandeled scheduling policy\0A\00"
@stdout = global i32 0
@.str.7 = [31 x i8] c"Current Scheduling Policy: %d\0A\00"
@.str.8 = [34 x i8] c"Setting Scheduling Policy to: %d\0A\00"
@.str.9 = [31 x i8] c"Error setting scheduler policy\00"
@.str.10 = [27 x i8] c"New Scheduling Policy: %d\0A\00"
@.str.11 = [36 x i8] c"Creating %d simultanious processes\0A\00"
@.str.12 = [42 x i8] c"The child process %d could not be forked\0A\00"
@.str.13 = [31 x i8] c"Process %d forked with PID %d\0A\00"
@.str.14 = [39 x i8] c"blocksize can not exceed transfersize\0A\00"
@.str.15 = [44 x i8] c"blocksize must be multiple of transfersize\0A\00"
@.str.16 = [35 x i8] c"Failed to allocate transfer buffer\00"
@O_RDONLY = global i32 0
@O_SYNC = global i32 0
@.str.17 = [26 x i8] c"Failed to open input file\00"
@.str.18 = [6 x i8] c"%s-%d\00"
@.str.19 = [56 x i8] c"Output filenmae length exceeds limit of %d characters.\0A\00"
@.str.20 = [35 x i8] c"Failed to generate output filename\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@.str.21 = [27 x i8] c"Failed to open output file\00"
@.str.22 = [35 x i8] c"Reading from %s and writing to %s\0A\00"
@.str.23 = [25 x i8] c"Error reading input file\00"
@.str.24 = [26 x i8] c"Error writing output file\00"
@SEEK_SET = global i32 0
@.str.25 = [37 x i8] c"Error resetting to beginning of file\00"
@.str.26 = [32 x i8] c"Read: %zd bytes in %d reads\0A\00"
@.str.27 = [33 x i8] c"Written: %zd bytes in %d writes\0A\00"
@.str.28 = [30 x i8] c"Read input file in %d pass%s\0A\00"
@.str.29 = [3 x i8] c"es\00"
@.str.30 = [1 x i8] zeroinitializer
@.str.31 = [44 x i8] c"Processed %zd bytes in blocks of %zd bytes\0A\00"
@.str.32 = [28 x i8] c"Failed to close output file\00"
@.str.33 = [27 x i8] c"Failed to close input file\00"
@.str.34 = [51 x i8] c"\0AWaiting for all of the running processes to exit\0A\00"
@.str.35 = [45 x i8] c"Child process %d has been reaped correctly.\0A\00"
@.str.36 = [47 x i8] c"%d child process forked, %d have been reaped.\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.37 = [23 x i8] c"Something went wrong.\0A\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 [80 x i8]
%10 = alloca [80 x i8]
%11 = alloca [80 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca %struct.sched_param
%28 = alloca i32
%29 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %12
store i32 0, i32* %13
store i8* null, i8** %14
store i32 0, i32* %16
store i32 0, i32* %17
store i32 0, i32* %18
store i32 0, i32* %19
store i32 0, i32* %20
store i32 0, i32* %21
store i32 0, i32* %22
store i32 1024, i32* %13
store i32 102400, i32* %12
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%31 = call i32 @strncpy(i8* %30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 80)
%32 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%33 = call i32 @strncpy(i8* %32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 80)
%34 = load i32, i32* %4
%35 = icmp slt i32 %34, 2
br i1 %35, label %36, label %39
36: ; preds = %2
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %2
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
store i32 %43, i32* %25
%44 = load i32, i32* %25
%45 = icmp slt i32 %44, 1
br i1 %45, label %46, label %51
46: ; preds = %39
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %39
br label %52
52: ; preds = %51
%53 = load i32, i32* %4
%54 = icmp slt i32 %53, 3
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = load i32, i32* @SCHED_OTHER
store i32 %56, i32* %26
br label %89
57: ; preds = %52
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 2
%60 = load i8*, i8** %59
%61 = call i32 @strcmp(i8* %60, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%62 = icmp ne i32 %61, 0
br i1 %62, label %65, label %63
63: ; preds = %57
%64 = load i32, i32* @SCHED_OTHER
store i32 %64, i32* %26
br label %88
65: ; preds = %57
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 2
%68 = load i8*, i8** %67
%69 = call i32 @strcmp(i8* %68, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%70 = icmp ne i32 %69, 0
br i1 %70, label %73, label %71
71: ; preds = %65
%72 = load i32, i32* @SCHED_FIFO
store i32 %72, i32* %26
br label %87
73: ; preds = %65
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 2
%76 = load i8*, i8** %75
%77 = call i32 @strcmp(i8* %76, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%78 = icmp ne i32 %77, 0
br i1 %78, label %81, label %79
79: ; preds = %73
%80 = load i32, i32* @SCHED_RR
store i32 %80, i32* %26
br label %86
81: ; preds = %73
%82 = load i32, i32* @stderr
%83 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%84 = load i32, i32* @EXIT_FAILURE
%85 = call i32 @exit(i32 %84)
unreachable
86: ; preds = %79
br label %87
87: ; preds = %86, %71
br label %88
88: ; preds = %87, %63
br label %89
89: ; preds = %88, %55
%90 = load i32, i32* %26
%91 = call i32 @sched_get_priority_max(i32 %90)
%92 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %27, i32 0, i32 0
store i32 %91, i32* %92
%93 = load i32, i32* @stdout
%94 = call i32 @sched_getscheduler(i32 0)
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %94)
%96 = load i32, i32* @stdout
%97 = load i32, i32* %26
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i32 %97)
%99 = load i32, i32* %26
%100 = call i64 @sched_setscheduler(i32 0, i32 %99, %struct.sched_param* %27)
%101 = icmp ne i64 %100, 0
br i1 %101, label %102, label %106
102: ; preds = %89
%103 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
%104 = load i32, i32* @EXIT_FAILURE
%105 = call i32 @exit(i32 %104)
unreachable
106: ; preds = %89
%107 = load i32, i32* @stdout
%108 = call i32 @sched_getscheduler(i32 0)
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %108)
%110 = load i32, i32* @stdout
%111 = load i32, i32* %25
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.11, i64 0, i64 0), i32 %111)
store i32 0, i32* %28
br label %113
113: ; preds = %322, %106
%114 = load i32, i32* %28
%115 = load i32, i32* %25
%116 = icmp slt i32 %114, %115
br i1 %116, label %117, label %325
117: ; preds = %113
%118 = call i32 (...) @fork()
store i32 %118, i32* %23
%119 = icmp eq i32 %118, -1
br i1 %119, label %120, label %126
120: ; preds = %117
%121 = load i32, i32* @stderr
%122 = load i32, i32* %28
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.12, i64 0, i64 0), i32 %122)
%124 = load i32, i32* @EXIT_FAILURE
%125 = call i32 @exit(i32 %124)
unreachable
126: ; preds = %117
%127 = load i32, i32* %23
%128 = icmp eq i32 %127, 0
br i1 %128, label %129, label %320
129: ; preds = %126
%130 = load i32, i32* @stdout
%131 = load i32, i32* %28
%132 = load i32, i32* %23
%133 = call i32 (i32, i8*, ...) @fprintf(i32 %130, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0), i32 %131, i32 %132)
%134 = load i32, i32* %13
%135 = load i32, i32* %12
%136 = icmp sgt i32 %134, %135
br i1 %136, label %137, label %142
137: ; preds = %129
%138 = load i32, i32* @stderr
%139 = call i32 (i32, i8*, ...) @fprintf(i32 %138, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.14, i64 0, i64 0))
%140 = load i32, i32* @EXIT_FAILURE
%141 = call i32 @exit(i32 %140)
unreachable
142: ; preds = %129
%143 = load i32, i32* %12
%144 = load i32, i32* %13
%145 = srem i32 %143, %144
%146 = icmp ne i32 %145, 0
br i1 %146, label %147, label %152
147: ; preds = %142
%148 = load i32, i32* @stderr
%149 = call i32 (i32, i8*, ...) @fprintf(i32 %148, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.15, i64 0, i64 0))
%150 = load i32, i32* @EXIT_FAILURE
%151 = call i32 @exit(i32 %150)
unreachable
152: ; preds = %142
%153 = load i32, i32* %13
store i32 %153, i32* %15
%154 = load i32, i32* %15
%155 = sext i32 %154 to i64
%156 = mul i64 %155, 1
%157 = trunc i64 %156 to i32
%158 = call i8* @malloc(i32 %157)
store i8* %158, i8** %14
%159 = icmp ne i8* %158, null
br i1 %159, label %164, label %160
160: ; preds = %152
%161 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.16, i64 0, i64 0))
%162 = load i32, i32* @EXIT_FAILURE
%163 = call i32 @exit(i32 %162)
unreachable
164: ; preds = %152
%165 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%166 = load i32, i32* @O_RDONLY
%167 = load i32, i32* @O_SYNC
%168 = or i32 %166, %167
%169 = call i32 (i8*, i32, ...) @open(i8* %165, i32 %168)
store i32 %169, i32* %7
%170 = icmp slt i32 %169, 0
br i1 %170, label %171, label %175
171: ; preds = %164
%172 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.17, i64 0, i64 0))
%173 = load i32, i32* @EXIT_FAILURE
%174 = call i32 @exit(i32 %173)
unreachable
175: ; preds = %164
%176 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%177 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%178 = call i32 (...) @getpid()
%179 = call i32 @snprintf(i8* %176, i32 80, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.18, i64 0, i64 0), i8* %177, i32 %178)
store i32 %179, i32* %6
%180 = load i32, i32* %6
%181 = icmp sgt i32 %180, 80
br i1 %181, label %182, label %187
182: ; preds = %175
%183 = load i32, i32* @stderr
%184 = call i32 (i32, i8*, ...) @fprintf(i32 %183, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.19, i64 0, i64 0), i32 80)
%185 = load i32, i32* @EXIT_FAILURE
%186 = call i32 @exit(i32 %185)
unreachable
187: ; preds = %175
%188 = load i32, i32* %6
%189 = icmp slt i32 %188, 0
br i1 %189, label %190, label %194
190: ; preds = %187
%191 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.20, i64 0, i64 0))
%192 = load i32, i32* @EXIT_FAILURE
%193 = call i32 @exit(i32 %192)
unreachable
194: ; preds = %187
br label %195
195: ; preds = %194
%196 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%197 = load i32, i32* @O_WRONLY
%198 = load i32, i32* @O_CREAT
%199 = or i32 %197, %198
%200 = load i32, i32* @O_TRUNC
%201 = or i32 %199, %200
%202 = load i32, i32* @O_SYNC
%203 = or i32 %201, %202
%204 = load i32, i32* @S_IRUSR
%205 = load i32, i32* @S_IWUSR
%206 = or i32 %204, %205
%207 = load i32, i32* @S_IRGRP
%208 = or i32 %206, %207
%209 = load i32, i32* @S_IWGRP
%210 = or i32 %208, %209
%211 = load i32, i32* @S_IROTH
%212 = or i32 %210, %211
%213 = call i32 (i8*, i32, ...) @open(i8* %196, i32 %203, i32 %212)
store i32 %213, i32* %8
%214 = icmp slt i32 %213, 0
br i1 %214, label %215, label %219
215: ; preds = %195
%216 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.21, i64 0, i64 0))
%217 = load i32, i32* @EXIT_FAILURE
%218 = call i32 @exit(i32 %217)
unreachable
219: ; preds = %195
%220 = load i32, i32* @stdout
%221 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%222 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%223 = call i32 (i32, i8*, ...) @fprintf(i32 %220, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.22, i64 0, i64 0), i8* %221, i8* %222)
br label %224
224: ; preds = %276, %219
%225 = load i32, i32* %7
%226 = load i8*, i8** %14
%227 = load i32, i32* %15
%228 = call i32 @read(i32 %225, i8* %226, i32 %227)
store i32 %228, i32* %16
%229 = load i32, i32* %16
%230 = icmp slt i32 %229, 0
br i1 %230, label %231, label %235
231: ; preds = %224
%232 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.23, i64 0, i64 0))
%233 = load i32, i32* @EXIT_FAILURE
%234 = call i32 @exit(i32 %233)
unreachable
235: ; preds = %224
%236 = load i32, i32* %16
%237 = load i32, i32* %17
%238 = add nsw i32 %237, %236
store i32 %238, i32* %17
%239 = load i32, i32* %18
%240 = add nsw i32 %239, 1
store i32 %240, i32* %18
br label %241
241: ; preds = %235
%242 = load i32, i32* %16
%243 = load i32, i32* %13
%244 = icmp eq i32 %242, %243
br i1 %244, label %245, label %263
245: ; preds = %241
%246 = load i32, i32* %8
%247 = load i8*, i8** %14
%248 = load i32, i32* %16
%249 = call i32 @write(i32 %246, i8* %247, i32 %248)
store i32 %249, i32* %19
%250 = load i32, i32* %19
%251 = icmp slt i32 %250, 0
br i1 %251, label %252, label %256
252: ; preds = %245
%253 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.24, i64 0, i64 0))
%254 = load i32, i32* @EXIT_FAILURE
%255 = call i32 @exit(i32 %254)
unreachable
256: ; preds = %245
%257 = load i32, i32* %19
%258 = load i32, i32* %20
%259 = add nsw i32 %258, %257
store i32 %259, i32* %20
%260 = load i32, i32* %21
%261 = add nsw i32 %260, 1
store i32 %261, i32* %21
br label %262
262: ; preds = %256
br label %275
263: ; preds = %241
%264 = load i32, i32* %7
%265 = load i32, i32* @SEEK_SET
%266 = call i64 @lseek(i32 %264, i32 0, i32 %265)
%267 = icmp ne i64 %266, 0
br i1 %267, label %268, label %272
268: ; preds = %263
%269 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.25, i64 0, i64 0))
%270 = load i32, i32* @EXIT_FAILURE
%271 = call i32 @exit(i32 %270)
unreachable
272: ; preds = %263
%273 = load i32, i32* %22
%274 = add nsw i32 %273, 1
store i32 %274, i32* %22
br label %275
275: ; preds = %272, %262
br label %276
276: ; preds = %275
%277 = load i32, i32* %20
%278 = load i32, i32* %12
%279 = icmp slt i32 %277, %278
br i1 %279, label %224, label %280
280: ; preds = %276
%281 = load i32, i32* @stdout
%282 = load i32, i32* %17
%283 = load i32, i32* %18
%284 = call i32 (i32, i8*, ...) @fprintf(i32 %281, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.26, i64 0, i64 0), i32 %282, i32 %283)
%285 = load i32, i32* @stdout
%286 = load i32, i32* %20
%287 = load i32, i32* %21
%288 = call i32 (i32, i8*, ...) @fprintf(i32 %285, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.27, i64 0, i64 0), i32 %286, i32 %287)
%289 = load i32, i32* @stdout
%290 = load i32, i32* %22
%291 = add nsw i32 %290, 1
%292 = load i32, i32* %22
%293 = icmp ne i32 %292, 0
%294 = zext i1 %293 to i64
%295 = select i1 %293, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.29, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.30, i64 0, i64 0)
%296 = call i32 (i32, i8*, ...) @fprintf(i32 %289, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.28, i64 0, i64 0), i32 %291, i8* %295)
%297 = load i32, i32* @stdout
%298 = load i32, i32* %12
%299 = load i32, i32* %13
%300 = call i32 (i32, i8*, ...) @fprintf(i32 %297, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.31, i64 0, i64 0), i32 %298, i32 %299)
%301 = load i8*, i8** %14
%302 = call i32 @free(i8* %301)
%303 = load i32, i32* %8
%304 = call i64 @close(i32 %303)
%305 = icmp ne i64 %304, 0
br i1 %305, label %306, label %310
306: ; preds = %280
%307 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.32, i64 0, i64 0))
%308 = load i32, i32* @EXIT_FAILURE
%309 = call i32 @exit(i32 %308)
unreachable
310: ; preds = %280
%311 = load i32, i32* %7
%312 = call i64 @close(i32 %311)
%313 = icmp ne i64 %312, 0
br i1 %313, label %314, label %318
314: ; preds = %310
%315 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.33, i64 0, i64 0))
%316 = load i32, i32* @EXIT_FAILURE
%317 = call i32 @exit(i32 %316)
unreachable
318: ; preds = %310
%319 = call i32 @exit(i32 0)
unreachable
320: ; preds = %126
br label %321
321: ; preds = %320
br label %322
322: ; preds = %321
%323 = load i32, i32* %28
%324 = add nsw i32 %323, 1
store i32 %324, i32* %28
br label %113
325: ; preds = %113
%326 = load i32, i32* @stdout
%327 = call i32 (i32, i8*, ...) @fprintf(i32 %326, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.34, i64 0, i64 0))
store i32 0, i32* %29
br label %328
328: ; preds = %341, %325
%329 = call i32 @wait(i32* %24)
store i32 %329, i32* %23
%330 = icmp sgt i32 %329, 0
br i1 %330, label %331, label %342
331: ; preds = %328
%332 = load i32, i32* %24
%333 = call i64 @WIFEXITED(i32 %332)
%334 = icmp ne i64 %333, 0
br i1 %334, label %335, label %341
335: ; preds = %331
%336 = load i32, i32* @stdout
%337 = load i32, i32* %23
%338 = call i32 (i32, i8*, ...) @fprintf(i32 %336, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.35, i64 0, i64 0), i32 %337)
%339 = load i32, i32* %29
%340 = add nsw i32 %339, 1
store i32 %340, i32* %29
br label %341
341: ; preds = %335, %331
br label %328
342: ; preds = %328
%343 = load i32, i32* %29
%344 = load i32, i32* %25
%345 = icmp eq i32 %343, %344
br i1 %345, label %346, label %353
346: ; preds = %342
%347 = load i32, i32* @stdout
%348 = load i32, i32* %25
%349 = load i32, i32* %29
%350 = call i32 (i32, i8*, ...) @fprintf(i32 %347, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.36, i64 0, i64 0), i32 %348, i32 %349)
%351 = load i32, i32* @EXIT_SUCCESS
%352 = call i32 @exit(i32 %351)
unreachable
353: ; preds = %342
%354 = load i32, i32* @stderr
%355 = call i32 (i32, i8*, ...) @fprintf(i32 %354, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.37, i64 0, i64 0))
%356 = load i32, i32* @EXIT_FAILURE
%357 = call i32 @exit(i32 %356)
unreachable
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@.str = [8 x i8] c"rwinput\00"
@.str.1 = [9 x i8] c"rwoutput\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.2 = [21 x i8] c"Need more processes\0A\00"
@SCHED_OTHER = global i32 0
@.str.3 = [12 x i8] c"SCHED_OTHER\00"
@.str.4 = [11 x i8] c"SCHED_FIFO\00"
@SCHED_FIFO = global i32 0
@.str.5 = [9 x i8] c"SCHED_RR\00"
@SCHED_RR = global i32 0
@.str.6 = [30 x i8] c"Unhandeled scheduling policy\0A\00"
@stdout = global i32 0
@.str.7 = [31 x i8] c"Current Scheduling Policy: %d\0A\00"
@.str.8 = [34 x i8] c"Setting Scheduling Policy to: %d\0A\00"
@.str.9 = [31 x i8] c"Error setting scheduler policy\00"
@.str.10 = [27 x i8] c"New Scheduling Policy: %d\0A\00"
@.str.11 = [36 x i8] c"Creating %d simultanious processes\0A\00"
@.str.12 = [42 x i8] c"The child process %d could not be forked\0A\00"
@.str.13 = [31 x i8] c"Process %d forked with PID %d\0A\00"
@.str.16 = [35 x i8] c"Failed to allocate transfer buffer\00"
@O_RDONLY = global i32 0
@O_SYNC = global i32 0
@.str.17 = [26 x i8] c"Failed to open input file\00"
@.str.18 = [6 x i8] c"%s-%d\00"
@.str.19 = [56 x i8] c"Output filenmae length exceeds limit of %d characters.\0A\00"
@.str.20 = [35 x i8] c"Failed to generate output filename\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@.str.21 = [27 x i8] c"Failed to open output file\00"
@.str.22 = [35 x i8] c"Reading from %s and writing to %s\0A\00"
@.str.23 = [25 x i8] c"Error reading input file\00"
@.str.24 = [26 x i8] c"Error writing output file\00"
@SEEK_SET = global i32 0
@.str.25 = [37 x i8] c"Error resetting to beginning of file\00"
@.str.26 = [32 x i8] c"Read: %zd bytes in %d reads\0A\00"
@.str.27 = [33 x i8] c"Written: %zd bytes in %d writes\0A\00"
@.str.28 = [30 x i8] c"Read input file in %d pass%s\0A\00"
@.str.29 = [3 x i8] c"es\00"
@.str.30 = [1 x i8] zeroinitializer
@.str.31 = [44 x i8] c"Processed %zd bytes in blocks of %zd bytes\0A\00"
@.str.32 = [28 x i8] c"Failed to close output file\00"
@.str.33 = [27 x i8] c"Failed to close input file\00"
@.str.34 = [51 x i8] c"\0AWaiting for all of the running processes to exit\0A\00"
@.str.35 = [45 x i8] c"Child process %d has been reaped correctly.\0A\00"
@.str.36 = [47 x i8] c"%d child process forked, %d have been reaped.\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.37 = [23 x i8] c"Something went wrong.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = alloca [80 x i8]
%6 = alloca i32
%7 = alloca %struct.sched_param
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%11 = bitcast i32* %6 to i8*
%12 = bitcast %struct.sched_param* %7 to i8*
%13 = call i32 @strncpy(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 80)
%14 = call i32 @strncpy(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 80)
%15 = icmp slt i32 %0, 2
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
%23 = icmp slt i32 %22, 1
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %19
%30 = icmp ult i32 %0, 3
br i1 %30, label %47, label %31
31: ; preds = %29
%32 = getelementptr inbounds i8*, i8** %1, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @strcmp(i8* dereferenceable(1) %33, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%35 = icmp eq i32 %34, 0
br i1 %35, label %47, label %36
36: ; preds = %31
%37 = call i32 @strcmp(i8* dereferenceable(1) %33, i8* dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%38 = icmp eq i32 %37, 0
br i1 %38, label %47, label %39
39: ; preds = %36
%40 = call i32 @strcmp(i8* dereferenceable(1) %33, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%41 = icmp eq i32 %40, 0
br i1 %41, label %47, label %42
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %39, %36, %31, %29
%48 = phi i32* [ @SCHED_OTHER, %29 ], [ @SCHED_OTHER, %31 ], [ @SCHED_FIFO, %36 ], [ @SCHED_RR, %39 ]
%49 = load i32, i32* %48
%50 = call i32 @sched_get_priority_max(i32 %49)
%51 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %7, i64 0, i32 0
store i32 %50, i32* %51
%52 = load i32, i32* @stdout
%53 = call i32 @sched_getscheduler(i32 0)
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %53)
%55 = load i32, i32* @stdout
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i32 %49)
%57 = call i64 @sched_setscheduler(i32 0, i32 %49, %struct.sched_param* %7)
%58 = icmp eq i64 %57, 0
br i1 %58, label %63, label %59
59: ; preds = %47
%60 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
%61 = load i32, i32* @EXIT_FAILURE
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %47
%64 = load i32, i32* @stdout
%65 = call i32 @sched_getscheduler(i32 0)
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %65)
%67 = load i32, i32* @stdout
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.11, i64 0, i64 0), i32 %22)
br label %74
69: ; preds = %211
%70 = load i32, i32* @stdout
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.34, i64 0, i64 0))
%72 = call i32 @wait(i32* %6)
%73 = icmp sgt i32 %72, 0
br i1 %73, label %214, label %228
74: ; preds = %63, %211
%75 = phi i32 [ %212, %211 ], [ 0, %63 ]
%76 = call i32 (...) @fork()
switch i32 %76, label %211 [
i32 -1, label %77
i32 0, label %82
]
77: ; preds = %74
%78 = load i32, i32* @stderr
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.12, i64 0, i64 0), i32 %75)
%80 = load i32, i32* @EXIT_FAILURE
%81 = call i32 @exit(i32 %80)
unreachable
82: ; preds = %74
%83 = load i32, i32* @stdout
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0), i32 %75, i32 0)
%85 = call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%86 = icmp eq i8* %85, null
br i1 %86, label %87, label %91
87: ; preds = %82
%88 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.16, i64 0, i64 0))
%89 = load i32, i32* @EXIT_FAILURE
%90 = call i32 @exit(i32 %89)
unreachable
91: ; preds = %82
%92 = load i32, i32* @O_RDONLY
%93 = load i32, i32* @O_SYNC
%94 = or i32 %93, %92
%95 = call i32 (i8*, i32, ...) @open(i8* %8, i32 %94)
%96 = icmp slt i32 %95, 0
br i1 %96, label %97, label %101
97: ; preds = %91
%98 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.17, i64 0, i64 0))
%99 = load i32, i32* @EXIT_FAILURE
%100 = call i32 @exit(i32 %99)
unreachable
101: ; preds = %91
%102 = call i32 (...) @getpid()
%103 = call i32 @snprintf(i8* %9, i32 80, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.18, i64 0, i64 0), i8* %10, i32 %102)
%104 = icmp sgt i32 %103, 80
br i1 %104, label %105, label %110
105: ; preds = %101
%106 = load i32, i32* @stderr
%107 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.19, i64 0, i64 0), i32 80)
%108 = load i32, i32* @EXIT_FAILURE
%109 = call i32 @exit(i32 %108)
unreachable
110: ; preds = %101
%111 = icmp slt i32 %103, 0
br i1 %111, label %112, label %116
112: ; preds = %110
%113 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.20, i64 0, i64 0))
%114 = load i32, i32* @EXIT_FAILURE
%115 = call i32 @exit(i32 %114)
unreachable
116: ; preds = %110
%117 = load i32, i32* @O_WRONLY
%118 = load i32, i32* @O_CREAT
%119 = or i32 %118, %117
%120 = load i32, i32* @O_TRUNC
%121 = or i32 %119, %120
%122 = load i32, i32* @O_SYNC
%123 = or i32 %121, %122
%124 = load i32, i32* @S_IRUSR
%125 = load i32, i32* @S_IWUSR
%126 = or i32 %125, %124
%127 = load i32, i32* @S_IRGRP
%128 = or i32 %126, %127
%129 = load i32, i32* @S_IWGRP
%130 = or i32 %128, %129
%131 = load i32, i32* @S_IROTH
%132 = or i32 %130, %131
%133 = call i32 (i8*, i32, ...) @open(i8* %9, i32 %123, i32 %132)
%134 = icmp slt i32 %133, 0
br i1 %134, label %135, label %139
135: ; preds = %116
%136 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.21, i64 0, i64 0))
%137 = load i32, i32* @EXIT_FAILURE
%138 = call i32 @exit(i32 %137)
unreachable
139: ; preds = %116
%140 = load i32, i32* @stdout
%141 = call i32 (i32, i8*, ...) @fprintf(i32 %140, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.22, i64 0, i64 0), i8* %8, i8* %9)
br label %142
142: ; preds = %178, %139
%143 = phi i32 [ 0, %139 ], [ %155, %178 ]
%144 = phi i32 [ 0, %139 ], [ %156, %178 ]
%145 = phi i32 [ 0, %139 ], [ %179, %178 ]
%146 = phi i32 [ 0, %139 ], [ %180, %178 ]
%147 = phi i32 [ 0, %139 ], [ %181, %178 ]
%148 = call i32 @read(i32 %95, i8* %85, i32 1024)
%149 = icmp slt i32 %148, 0
br i1 %149, label %150, label %154
150: ; preds = %142
%151 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.23, i64 0, i64 0))
%152 = load i32, i32* @EXIT_FAILURE
%153 = call i32 @exit(i32 %152)
unreachable
154: ; preds = %142
%155 = add nsw i32 %148, %143
%156 = add nuw nsw i32 %144, 1
%157 = icmp eq i32 %148, 1024
br i1 %157, label %158, label %168
158: ; preds = %154
%159 = call i32 @write(i32 %133, i8* %85, i32 1024)
%160 = icmp slt i32 %159, 0
br i1 %160, label %161, label %165
161: ; preds = %158
%162 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.24, i64 0, i64 0))
%163 = load i32, i32* @EXIT_FAILURE
%164 = call i32 @exit(i32 %163)
unreachable
165: ; preds = %158
%166 = add nsw i32 %159, %145
%167 = add nsw i32 %146, 1
br label %178
168: ; preds = %154
%169 = load i32, i32* @SEEK_SET
%170 = call i64 @lseek(i32 %95, i32 0, i32 %169)
%171 = icmp eq i64 %170, 0
br i1 %171, label %176, label %172
172: ; preds = %168
%173 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.25, i64 0, i64 0))
%174 = load i32, i32* @EXIT_FAILURE
%175 = call i32 @exit(i32 %174)
unreachable
176: ; preds = %168
%177 = add nsw i32 %147, 1
br label %178
178: ; preds = %165, %176
%179 = phi i32 [ %166, %165 ], [ %145, %176 ]
%180 = phi i32 [ %167, %165 ], [ %146, %176 ]
%181 = phi i32 [ %147, %165 ], [ %177, %176 ]
%182 = icmp slt i32 %179, 102400
br i1 %182, label %142, label %183
183: ; preds = %178
%184 = load i32, i32* @stdout
%185 = call i32 (i32, i8*, ...) @fprintf(i32 %184, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.26, i64 0, i64 0), i32 %155, i32 %156)
%186 = load i32, i32* @stdout
%187 = call i32 (i32, i8*, ...) @fprintf(i32 %186, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.27, i64 0, i64 0), i32 %179, i32 %180)
%188 = load i32, i32* @stdout
%189 = add nsw i32 %181, 1
%190 = icmp eq i32 %181, 0
%191 = select i1 %190, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.30, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.29, i64 0, i64 0)
%192 = call i32 (i32, i8*, ...) @fprintf(i32 %188, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.28, i64 0, i64 0), i32 %189, i8* %191)
%193 = load i32, i32* @stdout
%194 = call i32 (i32, i8*, ...) @fprintf(i32 %193, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.31, i64 0, i64 0), i32 102400, i32 1024)
%195 = call i32 @free(i8* %85)
%196 = call i64 @close(i32 %133)
%197 = icmp eq i64 %196, 0
br i1 %197, label %202, label %198
198: ; preds = %183
%199 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.32, i64 0, i64 0))
%200 = load i32, i32* @EXIT_FAILURE
%201 = call i32 @exit(i32 %200)
unreachable
202: ; preds = %183
%203 = call i64 @close(i32 %95)
%204 = icmp eq i64 %203, 0
br i1 %204, label %209, label %205
205: ; preds = %202
%206 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.33, i64 0, i64 0))
%207 = load i32, i32* @EXIT_FAILURE
%208 = call i32 @exit(i32 %207)
unreachable
209: ; preds = %202
%210 = call i32 @exit(i32 0)
unreachable
211: ; preds = %74
%212 = add nuw nsw i32 %75, 1
%213 = icmp eq i32 %212, %22
br i1 %213, label %69, label %74
214: ; preds = %69, %224
%215 = phi i32 [ %226, %224 ], [ %72, %69 ]
%216 = phi i32 [ %225, %224 ], [ 0, %69 ]
%217 = load i32, i32* %6
%218 = call i64 @WIFEXITED(i32 %217)
%219 = icmp eq i64 %218, 0
br i1 %219, label %224, label %220
220: ; preds = %214
%221 = load i32, i32* @stdout
%222 = call i32 (i32, i8*, ...) @fprintf(i32 %221, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.35, i64 0, i64 0), i32 %215)
%223 = add nsw i32 %216, 1
br label %224
224: ; preds = %220, %214
%225 = phi i32 [ %223, %220 ], [ %216, %214 ]
%226 = call i32 @wait(i32* %6)
%227 = icmp sgt i32 %226, 0
br i1 %227, label %214, label %228
228: ; preds = %224, %69
%229 = phi i32 [ 0, %69 ], [ %225, %224 ]
%230 = icmp eq i32 %229, %22
br i1 %230, label %231, label %236
231: ; preds = %228
%232 = load i32, i32* @stdout
%233 = call i32 (i32, i8*, ...) @fprintf(i32 %232, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.36, i64 0, i64 0), i32 %22, i32 %22)
%234 = load i32, i32* @EXIT_SUCCESS
%235 = call i32 @exit(i32 %234)
unreachable
236: ; preds = %228
%237 = load i32, i32* @stderr
%238 = call i32 (i32, i8*, ...) @fprintf(i32 %237, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.37, i64 0, i64 0))
%239 = load i32, i32* @EXIT_FAILURE
%240 = call i32 @exit(i32 %239)
unreachable
}