#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ key_t;

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int atoi(char *);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ ftok(char *, int);
int getpid();
scalar_t__ malloc(int);
int /*<<< orphan*/ quickSort(int *, int, int);
scalar_t__ shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ shmdt(int *);
int shmget(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ sprintf(char *, char *, int, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ waitpid(int, int *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int shmid_qsort;
  int *shm_qsort;
  if (argc <= 4) {
    int m, i;
    int children[2], left, right;
    char *n_argv[6];
    char *buf;
    left = atoi(argv[1]);
    right = atoi(argv[2]);
    m = right / 2;
    shm_qsort = NULL;
    buf = (char *)malloc(sizeof(char) * 100);
    sprintf(buf, "   ### QSORT (%d): started with a[%d ... %d]\n", getpid(),
            left, right);
    write(STDOUT_FILENO, buf, strlen(buf));
    sprintf(buf, "   ### QSORT (%d): initial partition: %d\n", getpid(), m);
    write(STDOUT_FILENO, buf, strlen(buf));
    for (i = 0; i < 3; ++i) {
      n_argv[i] = (char *)malloc(sizeof(char) * 32);
    }
    strcpy(n_argv[0], "./qsort");
    if ((children[0] = fork()) == 0) {
      sprintf(n_argv[1], "%d", left);
      sprintf(n_argv[2], "%d", m);
      n_argv[3] = argv[3];
      n_argv[4] = "child";
      n_argv[5] = NULL;
      execvp(n_argv[0], n_argv);
    } else if ((children[1] = fork()) == 0) {
      sprintf(n_argv[1], "%d", m + 1);
      sprintf(n_argv[2], "%d", right);
      n_argv[3] = argv[3];
      n_argv[4] = "child";
      n_argv[5] = NULL;
      execvp(n_argv[0], n_argv);
    } else {
      int status;
      while (waitpid(-1, &status, 0) > 0)
        ;
      key_t key_q;
      key_q = ftok("./main", 1340);
      shmid_qsort = shmget(key_q, sizeof(int) * right, 0666);
      shm_qsort = (int *)shmat(shmid_qsort, NULL, 0);
      sprintf(buf,
              "   ### QSORT (%d): Children done sorting. Merging arrays.\n",
              getpid());
      write(STDOUT_FILENO, buf, strlen(buf));
      quickSort(shm_qsort, 0, right);
      shmdt(shm_qsort);
      exit(0);
    }
  } else {
    int left, right, size;
    left = atoi(argv[1]);
    right = atoi(argv[2]);
    size = atoi(argv[3]);
    char *buf;
    key_t key_q;
    key_q = ftok("./main", 1340);
    shmid_qsort = shmget(key_q, sizeof(int) * size, 0666);
    shm_qsort = (int *)shmat(shmid_qsort, NULL, 0);
    buf = (char *)malloc(sizeof(char) * 100);
    sprintf(buf, "   ### QSORT CHILD(%d): started with a[%d ... %d]\n",
            getpid(), left, right);
    write(STDOUT_FILENO, buf, strlen(buf));
    quickSort(shm_qsort, left, right);
    sprintf(buf, "   ### QSORT (%d): exiting.\n", getpid());
    write(STDOUT_FILENO, buf, strlen(buf));
    shmdt(shm_qsort);
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jg     1541 <main+0x341>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0xd0(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0xd0(%rbp),%rdi
mov    %eax,%edx
mov    -0x34(%rbp),%ecx
mov    -0x38(%rbp),%r8d
lea    0xd70(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    -0x78(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0xc4(%rbp),%edi
mov    -0xc0(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    -0x78(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0xb8(%rbp),%rdi
mov    %eax,%edx
mov    -0x24(%rbp),%ecx
lea    0xd3b(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
mov    0x2cef(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x78(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0xac(%rbp),%edi
mov    -0xa8(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x28(%rbp)
jge    1366 <main+0x166>
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,%rcx
movslq -0x28(%rbp),%rax
mov    %rcx,-0x70(%rbp,%rax,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1338 <main+0x138>
mov    -0x70(%rbp),%rdi
lea    0xce7(%rip),%rsi
call   1030 <strcpy@plt>
mov    $0x0,%al
call   1120 <fork@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jne    13e4 <main+0x1e4>
mov    -0x68(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xcc9(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xcb4(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x58(%rbp)
lea    0xc9d(%rip),%rax
mov    %rax,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x70(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   10d0 <execvp@plt>
jmp    153c <main+0x33c>
mov    $0x0,%al
call   1120 <fork@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jne    1455 <main+0x255>
mov    -0x68(%rbp),%rdi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
lea    0xc58(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x38(%rbp),%edx
lea    0xc43(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x58(%rbp)
lea    0xc2c(%rip),%rax
mov    %rax,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x70(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   10d0 <execvp@plt>
jmp    1537 <main+0x337>
jmp    145a <main+0x25a>
mov    $0xffffffff,%edi
lea    -0x7c(%rbp),%rsi
xor    %edx,%edx
call   10a0 <waitpid@plt>
cmp    $0x0,%rax
jle    1479 <main+0x279>
jmp    145a <main+0x25a>
lea    0xbe9(%rip),%rdi
mov    $0x53c,%esi
call   1110 <ftok@plt>
mov    %eax,-0x80(%rbp)
mov    -0x80(%rbp),%edi
movslq -0x38(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
mov    $0x1b6,%edx
call   10c0 <shmget@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10b0 <shmat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0xe8(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0xe8(%rbp),%rdi
mov    %eax,%edx
lea    0xb95(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
mov    0x2b07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xdc(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0xd8(%rbp)
mov    -0x78(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0xdc(%rbp),%edi
mov    -0xd8(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%edx
xor    %esi,%esi
call   1090 <quickSort@plt>
mov    -0x20(%rbp),%rdi
call   1040 <shmdt@plt>
xor    %edi,%edi
call   1100 <exit@plt>
jmp    153c <main+0x33c>
jmp    16d8 <main+0x4d8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x84(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x88(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x8c(%rbp)
lea    0xae8(%rip),%rdi
mov    $0x53c,%esi
call   1110 <ftok@plt>
mov    %eax,-0x9c(%rbp)
mov    -0x9c(%rbp),%edi
movslq -0x8c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
mov    $0x1b6,%edx
call   10c0 <shmget@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10b0 <shmat@plt>
mov    %rax,-0x20(%rbp)
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0x118(%rbp),%rdi
mov    %eax,%edx
mov    -0x84(%rbp),%ecx
mov    -0x88(%rbp),%r8d
lea    0xaa5(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
mov    0x29dc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10c(%rbp)
mov    -0x98(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x98(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x10c(%rbp),%edi
mov    -0x108(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    -0x20(%rbp),%rdi
mov    -0x84(%rbp),%esi
mov    -0x88(%rbp),%edx
call   1090 <quickSort@plt>
mov    -0x98(%rbp),%rax
mov    %rax,-0x100(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0x100(%rbp),%rdi
mov    %eax,%edx
lea    0xa5a(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
mov    0x295e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xf4(%rbp)
mov    -0x98(%rbp),%rax
mov    %rax,-0xf0(%rbp)
mov    -0x98(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0xf4(%rbp),%edi
mov    -0xf0(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    -0x20(%rbp),%rdi
call   1040 <shmdt@plt>
xor    %edi,%edi
call   1100 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
jg     1398 <main+0x198>
mov    0x8(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%r14d
mov    %rbx,0x10(%rsp)
mov    0x10(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%ebx
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xda6(%rip),%rsi
mov    %r13,%rdi
mov    %eax,%edx
mov    %r14d,0xc(%rsp)
mov    %r14d,%ecx
mov    %ebx,0x8(%rsp)
mov    %ebx,%r8d
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    0x2d74(%rip),%r14
mov    (%r14),%ebx
mov    %r13,%rdi
call   1070 <strlen@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1050 <write@plt>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xd8d(%rip),%rsi
mov    %r13,%rdi
mov    %eax,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    (%r14),%ebx
mov    %r13,%rdi
call   1070 <strlen@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %rax,0x20(%rsp)
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rax,0x28(%rsp)
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,0x30(%rsp)
lea    0xd55(%rip),%rsi
mov    %r12,%rdi
call   1030 <strcpy@plt>
xor    %eax,%eax
call   1120 <fork@plt>
test   %eax,%eax
je     1330 <main+0x130>
xor    %eax,%eax
call   1120 <fork@plt>
test   %eax,%eax
jne    147f <main+0x27f>
add    $0x1,%ebp
mov    %ebp,%edx
mov    0x8(%rsp),%ebp
jmp    1334 <main+0x134>
mov    0xc(%rsp),%edx
lea    0xd25(%rip),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    0x10(%rsp),%rax
mov    0x18(%rax),%rax
mov    %rax,0x38(%rsp)
lea    0xcf7(%rip),%rax
mov    %rax,0x40(%rsp)
movq   $0x0,0x48(%rsp)
lea    0x20(%rsp),%rsi
mov    %r12,%rdi
call   10d0 <execvp@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%r12d
mov    0x18(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%ebx
lea    0xca7(%rip),%rdi
mov    $0x53c,%esi
call   1110 <ftok@plt>
shl    $0x2,%ebx
mov    %eax,%edi
mov    %ebx,%esi
mov    $0x1b6,%edx
call   10c0 <shmget@plt>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <shmat@plt>
mov    %rax,%r14
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xca5(%rip),%rsi
mov    %rbp,%rdi
mov    %eax,%edx
mov    %r15d,%ecx
mov    %r12d,%r8d
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    0x2bd1(%rip),%r13
mov    0x0(%r13),%ebx
mov    %rbp,%rdi
call   1070 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
call   1090 <quickSort@plt>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xc8b(%rip),%rsi
mov    %rbp,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    0x0(%r13),%ebx
mov    %rbp,%rdi
call   1070 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %r14,%rdi
jmp    1521 <main+0x321>
lea    0x1c(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0xffffffff,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   10a0 <waitpid@plt>
test   %rax,%rax
jg     1490 <main+0x290>
lea    0xbbe(%rip),%rdi
mov    $0x53c,%esi
call   1110 <ftok@plt>
mov    0x8(%rsp),%r14d
mov    %r14d,%esi
shl    $0x2,%esi
mov    %eax,%edi
mov    $0x1b6,%edx
call   10c0 <shmget@plt>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <shmat@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xb88(%rip),%rsi
mov    %r13,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    0x2af5(%rip),%rax
mov    (%rax),%ebp
mov    %r13,%rdi
call   1070 <strlen@plt>
mov    %ebp,%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1090 <quickSort@plt>
mov    %rbx,%rdi
call   1040 <shmdt@plt>
xor    %edi,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@.str = [46 x i8] c" ### QSORT (%d): started with a[%d ... %d]\0A\00"
@STDOUT_FILENO = global i32 0
@.str.1 = [42 x i8] c" ### QSORT (%d): initial partition: %d\0A\00"
@.str.2 = [8 x i8] c"./qsort\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [6 x i8] c"child\00"
@.str.5 = [7 x i8] c"./main\00"
@.str.6 = [59 x i8] c" ### QSORT (%d): Children done sorting. Merging arrays.\0A\00"
@.str.7 = [51 x i8] c" ### QSORT CHILD(%d): started with a[%d ... %d]\0A\00"
@.str.8 = [29 x i8] c" ### QSORT (%d): exiting.\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 i32
%10 = alloca [2 x i32]
%11 = alloca i32
%12 = alloca i32
%13 = alloca [6 x i8*]
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i8*
%21 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%22 = load i32, i32* %4
%23 = icmp sle i32 %22, 4
br i1 %23, label %24, label %150
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %11
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %12
%33 = load i32, i32* %12
%34 = sdiv i32 %33, 2
store i32 %34, i32* %8
store i32* null, i32** %7
%35 = call i64 @malloc(i32 100)
%36 = inttoptr i64 %35 to i8*
store i8* %36, i8** %14
%37 = load i8*, i8** %14
%38 = call i32 (...) @getpid()
%39 = load i32, i32* %11
%40 = load i32, i32* %12
%41 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %37, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %38, i32 %39, i32 %40)
%42 = load i32, i32* @STDOUT_FILENO
%43 = load i8*, i8** %14
%44 = load i8*, i8** %14
%45 = call i32 @strlen(i8* %44)
%46 = call i32 @write(i32 %42, i8* %43, i32 %45)
%47 = load i8*, i8** %14
%48 = call i32 (...) @getpid()
%49 = load i32, i32* %8
%50 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %47, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %48, i32 %49)
%51 = load i32, i32* @STDOUT_FILENO
%52 = load i8*, i8** %14
%53 = load i8*, i8** %14
%54 = call i32 @strlen(i8* %53)
%55 = call i32 @write(i32 %51, i8* %52, i32 %54)
store i32 0, i32* %9
br label %56
56: ; preds = %65, %24
%57 = load i32, i32* %9
%58 = icmp slt i32 %57, 3
br i1 %58, label %59, label %68
59: ; preds = %56
%60 = call i64 @malloc(i32 32)
%61 = inttoptr i64 %60 to i8*
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i64 0, i64 %63
store i8* %61, i8** %64
br label %65
65: ; preds = %59
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 1
store i32 %67, i32* %9
br label %56
68: ; preds = %56
%69 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i64 0, i64 0
%70 = load i8*, i8** %69
%71 = call i32 @strcpy(i8* %70, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%72 = call i32 (...) @fork()
%73 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
store i32 %72, i32* %73
%74 = icmp eq i32 %72, 0
br i1 %74, label %75, label %94
75: ; preds = %68
%76 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i64 0, i64 1
%77 = load i8*, i8** %76
%78 = load i32, i32* %11
%79 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %77, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %78)
%80 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i64 0, i64 2
%81 = load i8*, i8** %80
%82 = load i32, i32* %8
%83 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %81, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %82)
%84 = load i8**, i8*** %5
%85 = getelementptr inbounds i8*, i8** %84, i64 3
%86 = load i8*, i8** %85
%87 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i64 0, i64 3
store i8* %86, i8** %87
%88 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i64 0, i64 4
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %88
%89 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i64 0, i64 5
store i8* null, i8** %89
%90 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i64 0, i64 0
%91 = load i8*, i8** %90
%92 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i64 0, i64 0
%93 = call i32 @execvp(i8* %91, i8** %92)
br label %149
94: ; preds = %68
%95 = call i32 (...) @fork()
%96 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
store i32 %95, i32* %96
%97 = icmp eq i32 %95, 0
br i1 %97, label %98, label %118
98: ; preds = %94
%99 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i64 0, i64 1
%100 = load i8*, i8** %99
%101 = load i32, i32* %8
%102 = add nsw i32 %101, 1
%103 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %102)
%104 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i64 0, i64 2
%105 = load i8*, i8** %104
%106 = load i32, i32* %12
%107 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %105, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %106)
%108 = load i8**, i8*** %5
%109 = getelementptr inbounds i8*, i8** %108, i64 3
%110 = load i8*, i8** %109
%111 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i64 0, i64 3
store i8* %110, i8** %111
%112 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i64 0, i64 4
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %112
%113 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i64 0, i64 5
store i8* null, i8** %113
%114 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i64 0, i64 0
%115 = load i8*, i8** %114
%116 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i64 0, i64 0
%117 = call i32 @execvp(i8* %115, i8** %116)
br label %148
118: ; preds = %94
br label %119
119: ; preds = %122, %118
%120 = call i64 @waitpid(i32 -1, i32* %15, i32 0)
%121 = icmp sgt i64 %120, 0
br i1 %121, label %122, label %123
122: ; preds = %119
br label %119
123: ; preds = %119
%124 = call i32 @ftok(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 1340)
store i32 %124, i32* %16
%125 = load i32, i32* %16
%126 = load i32, i32* %12
%127 = sext i32 %126 to i64
%128 = mul i64 4, %127
%129 = trunc i64 %128 to i32
%130 = call i32 @shmget(i32 %125, i32 %129, i32 438)
store i32 %130, i32* %6
%131 = load i32, i32* %6
%132 = call i64 @shmat(i32 %131, i32* null, i32 0)
%133 = inttoptr i64 %132 to i32*
store i32* %133, i32** %7
%134 = load i8*, i8** %14
%135 = call i32 (...) @getpid()
%136 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %134, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.6, i64 0, i64 0), i32 %135)
%137 = load i32, i32* @STDOUT_FILENO
%138 = load i8*, i8** %14
%139 = load i8*, i8** %14
%140 = call i32 @strlen(i8* %139)
%141 = call i32 @write(i32 %137, i8* %138, i32 %140)
%142 = load i32*, i32** %7
%143 = load i32, i32* %12
%144 = call i32 @quickSort(i32* %142, i32 0, i32 %143)
%145 = load i32*, i32** %7
%146 = call i32 @shmdt(i32* %145)
%147 = call i32 @exit(i32 0)
unreachable
148: ; preds = %98
br label %149
149: ; preds = %148, %75
br label %200
150: ; preds = %2
%151 = load i8**, i8*** %5
%152 = getelementptr inbounds i8*, i8** %151, i64 1
%153 = load i8*, i8** %152
%154 = call i32 @atoi(i8* %153)
store i32 %154, i32* %17
%155 = load i8**, i8*** %5
%156 = getelementptr inbounds i8*, i8** %155, i64 2
%157 = load i8*, i8** %156
%158 = call i32 @atoi(i8* %157)
store i32 %158, i32* %18
%159 = load i8**, i8*** %5
%160 = getelementptr inbounds i8*, i8** %159, i64 3
%161 = load i8*, i8** %160
%162 = call i32 @atoi(i8* %161)
store i32 %162, i32* %19
%163 = call i32 @ftok(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 1340)
store i32 %163, i32* %21
%164 = load i32, i32* %21
%165 = load i32, i32* %19
%166 = sext i32 %165 to i64
%167 = mul i64 4, %166
%168 = trunc i64 %167 to i32
%169 = call i32 @shmget(i32 %164, i32 %168, i32 438)
store i32 %169, i32* %6
%170 = load i32, i32* %6
%171 = call i64 @shmat(i32 %170, i32* null, i32 0)
%172 = inttoptr i64 %171 to i32*
store i32* %172, i32** %7
%173 = call i64 @malloc(i32 100)
%174 = inttoptr i64 %173 to i8*
store i8* %174, i8** %20
%175 = load i8*, i8** %20
%176 = call i32 (...) @getpid()
%177 = load i32, i32* %17
%178 = load i32, i32* %18
%179 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %175, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.7, i64 0, i64 0), i32 %176, i32 %177, i32 %178)
%180 = load i32, i32* @STDOUT_FILENO
%181 = load i8*, i8** %20
%182 = load i8*, i8** %20
%183 = call i32 @strlen(i8* %182)
%184 = call i32 @write(i32 %180, i8* %181, i32 %183)
%185 = load i32*, i32** %7
%186 = load i32, i32* %17
%187 = load i32, i32* %18
%188 = call i32 @quickSort(i32* %185, i32 %186, i32 %187)
%189 = load i8*, i8** %20
%190 = call i32 (...) @getpid()
%191 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %189, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i32 %190)
%192 = load i32, i32* @STDOUT_FILENO
%193 = load i8*, i8** %20
%194 = load i8*, i8** %20
%195 = call i32 @strlen(i8* %194)
%196 = call i32 @write(i32 %192, i8* %193, i32 %195)
%197 = load i32*, i32** %7
%198 = call i32 @shmdt(i32* %197)
%199 = call i32 @exit(i32 0)
unreachable
200: ; preds = %149
%201 = load i32, i32* %3
ret i32 %201
}

LLVM IR (-O2):
@.str = [46 x i8] c" ### QSORT (%d): started with a[%d ... %d]\0A\00"
@STDOUT_FILENO = global i32 0
@.str.1 = [42 x i8] c" ### QSORT (%d): initial partition: %d\0A\00"
@.str.2 = [8 x i8] c"./qsort\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [6 x i8] c"child\00"
@.str.5 = [7 x i8] c"./main\00"
@.str.6 = [59 x i8] c" ### QSORT (%d): Children done sorting. Merging arrays.\0A\00"
@.str.7 = [51 x i8] c" ### QSORT CHILD(%d): started with a[%d ... %d]\0A\00"
@.str.8 = [29 x i8] c" ### QSORT (%d): exiting.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [6 x i8*]
%4 = alloca i32
%5 = icmp slt i32 %0, 5
br i1 %5, label %6, label %74
6: ; preds = %2
%7 = bitcast [6 x i8*]* %3 to i8*
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = sdiv i32 %13, 2
%15 = tail call i64 @malloc(i32 100)
%16 = inttoptr i64 %15 to i8*
%17 = tail call i32 (...) @getpid()
%18 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %16, i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %10, i32 %13)
%19 = load i32, i32* @STDOUT_FILENO
%20 = tail call i32 @strlen(i8* %16)
%21 = tail call i32 @write(i32 %19, i8* %16, i32 %20)
%22 = tail call i32 (...) @getpid()
%23 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %16, i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %14)
%24 = load i32, i32* @STDOUT_FILENO
%25 = tail call i32 @strlen(i8* %16)
%26 = tail call i32 @write(i32 %24, i8* %16, i32 %25)
%27 = tail call i64 @malloc(i32 32)
%28 = inttoptr i64 %27 to i8*
%29 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 0
store i8* %28, i8** %29
%30 = tail call i64 @malloc(i32 32)
%31 = inttoptr i64 %30 to i8*
%32 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 1
store i8* %31, i8** %32
%33 = tail call i64 @malloc(i32 32)
%34 = inttoptr i64 %33 to i8*
%35 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 2
store i8* %34, i8** %35
%36 = tail call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%37 = tail call i32 (...) @fork()
%38 = icmp eq i32 %37, 0
br i1 %38, label %63, label %39
39: ; preds = %6
%40 = tail call i32 (...) @fork()
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = add nsw i32 %14, 1
br label %63
44: ; preds = %39
%45 = bitcast i32* %4 to i8*
br label %46
46: ; preds = %46, %44
%47 = call i64 @waitpid(i32 -1, i32* %4, i32 0)
%48 = icmp sgt i64 %47, 0
br i1 %48, label %46, label %49
49: ; preds = %46
%50 = call i32 @ftok(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 1340)
%51 = shl i32 %13, 2
%52 = call i32 @shmget(i32 %50, i32 %51, i32 438)
%53 = call i64 @shmat(i32 %52, i32* null, i32 0)
%54 = inttoptr i64 %53 to i32*
%55 = call i32 (...) @getpid()
%56 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %16, i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.6, i64 0, i64 0), i32 %55)
%57 = load i32, i32* @STDOUT_FILENO
%58 = call i32 @strlen(i8* %16)
%59 = call i32 @write(i32 %57, i8* %16, i32 %58)
%60 = call i32 @quickSort(i32* %54, i32 0, i32 %13)
%61 = call i32 @shmdt(i32* %54)
%62 = call i32 @exit(i32 0)
unreachable
63: ; preds = %6, %42
%64 = phi i32 [ %43, %42 ], [ %10, %6 ]
%65 = phi i32 [ %13, %42 ], [ %14, %6 ]
%66 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %31, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %64)
%67 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %34, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %65)
%68 = getelementptr inbounds i8*, i8** %1, i64 3
%69 = load i8*, i8** %68
%70 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 3
store i8* %69, i8** %70
%71 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 4
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %71
%72 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 5
store i8* null, i8** %72
%73 = call i32 @execvp(i8* %28, i8** %29)
ret i32 0
74: ; preds = %2
%75 = getelementptr inbounds i8*, i8** %1, i64 1
%76 = load i8*, i8** %75
%77 = tail call i32 @atoi(i8* %76)
%78 = getelementptr inbounds i8*, i8** %1, i64 2
%79 = load i8*, i8** %78
%80 = tail call i32 @atoi(i8* %79)
%81 = getelementptr inbounds i8*, i8** %1, i64 3
%82 = load i8*, i8** %81
%83 = tail call i32 @atoi(i8* %82)
%84 = tail call i32 @ftok(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 1340)
%85 = shl i32 %83, 2
%86 = tail call i32 @shmget(i32 %84, i32 %85, i32 438)
%87 = tail call i64 @shmat(i32 %86, i32* null, i32 0)
%88 = inttoptr i64 %87 to i32*
%89 = tail call i64 @malloc(i32 100)
%90 = inttoptr i64 %89 to i8*
%91 = tail call i32 (...) @getpid()
%92 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %90, i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.7, i64 0, i64 0), i32 %91, i32 %77, i32 %80)
%93 = load i32, i32* @STDOUT_FILENO
%94 = tail call i32 @strlen(i8* %90)
%95 = tail call i32 @write(i32 %93, i8* %90, i32 %94)
%96 = tail call i32 @quickSort(i32* %88, i32 %77, i32 %80)
%97 = tail call i32 (...) @getpid()
%98 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %90, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i32 %97)
%99 = load i32, i32* @STDOUT_FILENO
%100 = tail call i32 @strlen(i8* %90)
%101 = tail call i32 @write(i32 %99, i8* %90, i32 %100)
%102 = tail call i32 @shmdt(i32* %88)
%103 = tail call i32 @exit(i32 0)
unreachable
}