#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int IPC_CREAT;
int /*<<< orphan*/ IPC_PRIVATE;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ display(int *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ quicksort(int *, int /*<<< orphan*/, int);
scalar_t__ realloc(int *, int);
int *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int shmdt(int *);
int shmget(int /*<<< orphan*/, size_t, int);
int main(int argc, char *argv[]) {
  int *array = NULL;
  int *shm_array;
  int length = 0;
  FILE *fh;
  int data;
  int shm_id;
  key_t key;
  int i;
  size_t shm_size;
  if (argc != 2) {
    printf("usage: %s <filename>\n", argv[0]);
    return 1;
  }
  printf("attempting to sort file: %s\n", argv[1]);
  fh = fopen(argv[1], "r");
  if (fh == NULL) {
    printf("error opening file\n");
    return 0;
  }
  while (fscanf(fh, "%d", &data) != EOF) {
    ++length;
    array = (int *)realloc(array, length * sizeof(int));
    array[length - 1] = data;
  }
  fclose(fh);
  printf("%d elements read\n", length);
  display(array, length);
  key = IPC_PRIVATE;
  shm_size = length * sizeof(int);
  if ((shm_id = shmget(key, shm_size, IPC_CREAT | 0666)) == -1) {
    perror("shmget");
    exit(1);
  }
  if ((shm_array = shmat(shm_id, NULL, 0)) == (int *)-1) {
    perror("shmat");
    exit(1);
  }
  for (i = 0; i < length; i++) {
    shm_array[i] = array[i];
  }
  display(shm_array, length);
  printf("now sorting...\n");
  quicksort(shm_array, 0, length - 1);
  printf("done sorting\n");
  display(shm_array, length);
  if (shmdt(shm_array) == -1) {
    perror("shmdt");
    exit(1);
  }
  if (shmctl(shm_id, IPC_RMID, NULL) == -1) {
    perror("shmctl");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1220 <main+0x50>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1466 <main+0x296>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdee(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1273 <main+0xa3>
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1466 <main+0x296>
jmp    1278 <main+0xa8>
mov    -0x30(%rbp),%rdi
lea    0xdc6(%rip),%rsi
lea    -0x34(%rbp),%rdx
call   1080 <fscanf@plt>
mov    0x2d4d(%rip),%rcx
cmp    (%rcx),%rax
je     12d4 <main+0x104>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1090 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x34(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1278 <main+0xa8>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%esi
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <display@plt>
mov    0x2ce7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %rax,-0x48(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    0x2ca8(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
call   10e0 <shmget@plt>
mov    %eax,-0x38(%rbp)
cmp    $0xffffffff,%eax
jne    134f <main+0x17f>
lea    0xd1e(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x38(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10d0 <shmat@plt>
mov    %rax,-0x20(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    1387 <main+0x1b7>
lea    0xced(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    13be <main+0x1ee>
mov    -0x18(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    138e <main+0x1be>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <display@plt>
lea    0xc9a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1060 <quicksort@plt>
lea    0xc8b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <display@plt>
mov    -0x20(%rbp),%rdi
call   1030 <shmdt@plt>
cmp    $0xffffffff,%eax
jne    142b <main+0x25b>
lea    0xc6d(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x38(%rbp),%edi
mov    0x2b9b(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   10a0 <shmctl@plt>
cmp    $0xffffffff,%eax
jne    145f <main+0x28f>
lea    0xc3f(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1246 <main+0x66>
mov    0x8(%rbx),%rsi
lea    0xe18(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x8(%rbx),%rdi
lea    0xe20(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1261 <main+0x81>
mov    %rax,%r14
lea    0xe0e(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1090 <fscanf@plt>
mov    0x2da5(%rip),%r13
cmp    0x0(%r13),%rax
jne    1274 <main+0x94>
xor    %r12d,%r12d
jmp    12b9 <main+0xd9>
mov    (%rbx),%rsi
lea    0xdb0(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%ebx
jmp    14f7 <main+0x317>
lea    0xe18(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    14f7 <main+0x317>
mov    $0x4,%ebx
xor    %r15d,%r15d
xor    %r12d,%r12d
nop
mov    %r15,%rbp
add    $0x1,%r15
mov    %r12,%rdi
mov    %ebx,%esi
call   10a0 <realloc@plt>
mov    %rax,%r12
mov    0x4(%rsp),%eax
mov    %eax,(%r12,%rbp,4)
mov    %r14,%rdi
lea    0xd8f(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1090 <fscanf@plt>
add    $0x4,%ebx
cmp    0x0(%r13),%rax
jne    1280 <main+0xa0>
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    0xd70(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r12,%rdi
mov    %r15d,%esi
call   1060 <display@plt>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
mov    %r15d,%r15d
lea    0x0(,%r15,4),%rsi
mov    0x2cd0(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
call   10f0 <shmget@plt>
cmp    $0xffffffff,%eax
je     1508 <main+0x328>
mov    %eax,%r14d
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
je     1511 <main+0x331>
mov    %rax,%rbp
test   %r15,%r15
je     1494 <main+0x2b4>
cmp    $0x8,%r15d
jb     1354 <main+0x174>
lea    (%r12,%r15,4),%rax
cmp    %rax,%rbp
jae    13c1 <main+0x1e1>
lea    0x0(,%r15,4),%rax
add    %rbp,%rax
cmp    %rax,%r12
jae    13c1 <main+0x1e1>
xor    %eax,%eax
mov    %rax,%rcx
not    %rcx
add    %r15,%rcx
mov    %r15,%rdx
and    $0x3,%rdx
je     1382 <main+0x1a2>
nopl   0x0(%rax,%rax,1)
mov    (%r12,%rax,4),%esi
mov    %esi,0x0(%rbp,%rax,4)
add    $0x1,%rax
add    $0xffffffffffffffff,%rdx
jne    1370 <main+0x190>
cmp    $0x3,%rcx
jb     1494 <main+0x2b4>
nopl   0x0(%rax)
mov    (%r12,%rax,4),%ecx
mov    %ecx,0x0(%rbp,%rax,4)
mov    0x4(%r12,%rax,4),%ecx
mov    %ecx,0x4(%rbp,%rax,4)
mov    0x8(%r12,%rax,4),%ecx
mov    %ecx,0x8(%rbp,%rax,4)
mov    0xc(%r12,%rax,4),%ecx
mov    %ecx,0xc(%rbp,%rax,4)
add    $0x4,%rax
cmp    %rax,%r15
jne    1390 <main+0x1b0>
jmp    1494 <main+0x2b4>
mov    %r15d,%eax
and    $0xfffffff8,%eax
lea    -0x8(%rax),%rsi
mov    %rsi,%rdx
shr    $0x3,%rdx
add    $0x1,%rdx
mov    %edx,%ecx
and    $0x3,%ecx
cmp    $0x18,%rsi
jae    13e5 <main+0x205>
xor    %esi,%esi
jmp    1451 <main+0x271>
and    $0xfffffffffffffffc,%rdx
xor    %esi,%esi
nopl   0x0(%rax,%rax,1)
movups (%r12,%rsi,4),%xmm0
movups 0x10(%r12,%rsi,4),%xmm1
movups %xmm0,0x0(%rbp,%rsi,4)
movups %xmm1,0x10(%rbp,%rsi,4)
movups 0x20(%r12,%rsi,4),%xmm0
movups 0x30(%r12,%rsi,4),%xmm1
movups %xmm0,0x20(%rbp,%rsi,4)
movups %xmm1,0x30(%rbp,%rsi,4)
movups 0x40(%r12,%rsi,4),%xmm0
movups 0x50(%r12,%rsi,4),%xmm1
movups %xmm0,0x40(%rbp,%rsi,4)
movups %xmm1,0x50(%rbp,%rsi,4)
movups 0x60(%r12,%rsi,4),%xmm0
movups 0x70(%r12,%rsi,4),%xmm1
movups %xmm0,0x60(%rbp,%rsi,4)
movups %xmm1,0x70(%rbp,%rsi,4)
add    $0x20,%rsi
add    $0xfffffffffffffffc,%rdx
jne    13f0 <main+0x210>
test   %rcx,%rcx
je     148b <main+0x2ab>
lea    0x10(,%rsi,4),%rdx
add    %rbp,%rdx
lea    (%r12,%rsi,4),%rsi
add    $0x10,%rsi
shl    $0x5,%rcx
xor    %edi,%edi
nop
movups -0x10(%rsi,%rdi,1),%xmm0
movups (%rsi,%rdi,1),%xmm1
movups %xmm0,-0x10(%rdx,%rdi,1)
movups %xmm1,(%rdx,%rdi,1)
add    $0x20,%rdi
cmp    %rdi,%rcx
jne    1470 <main+0x290>
cmp    %r15,%rax
jne    1356 <main+0x176>
mov    %rbp,%rdi
mov    %r15d,%esi
call   1060 <display@plt>
lea    0xbbe(%rip),%rdi
call   1030 <puts@plt>
lea    -0x1(%r15),%edx
xor    %ebx,%ebx
mov    %rbp,%rdi
xor    %esi,%esi
call   1070 <quicksort@plt>
lea    0xbb1(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
mov    %r15d,%esi
call   1060 <display@plt>
mov    %rbp,%rdi
call   1040 <shmdt@plt>
cmp    $0xffffffff,%eax
je     151a <main+0x33a>
mov    0x2aea(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
xor    %edx,%edx
call   10b0 <shmctl@plt>
cmp    $0xffffffff,%eax
je     1523 <main+0x343>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb3b(%rip),%rdi
jmp    152a <main+0x34a>
lea    0xb39(%rip),%rdi
jmp    152a <main+0x34a>
lea    0xb36(%rip),%rdi
jmp    152a <main+0x34a>
lea    0xb33(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"usage: %s <filename>\0A\00"
@.str.1 = [29 x i8] c"attempting to sort file: %s\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [20 x i8] c"error opening file\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.5 = [18 x i8] c"%d elements read\0A\00"
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@.str.6 = [7 x i8] c"shmget\00"
@.str.7 = [6 x i8] c"shmat\00"
@.str.8 = [16 x i8] c"now sorting...\0A\00"
@.str.9 = [14 x i8] c"done sorting\0A\00"
@.str.10 = [6 x i8] c"shmdt\00"
@IPC_RMID = global i32 0
@.str.11 = [7 x i8] c"shmctl\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 i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32 0, i32* %8
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 1, i32* %3
br label %131
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %30, i32** %9
%31 = load i32*, i32** %9
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %35
33: ; preds = %22
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %131
35: ; preds = %22
br label %36
36: ; preds = %41, %35
%37 = load i32*, i32** %9
%38 = call i64 @fscanf(i32* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %10)
%39 = load i64, i64* @EOF
%40 = icmp ne i64 %38, %39
br i1 %40, label %41, label %57
41: ; preds = %36
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
%44 = load i32*, i32** %6
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = mul i64 %46, 4
%48 = trunc i64 %47 to i32
%49 = call i64 @realloc(i32* %44, i32 %48)
%50 = inttoptr i64 %49 to i32*
store i32* %50, i32** %6
%51 = load i32, i32* %10
%52 = load i32*, i32** %6
%53 = load i32, i32* %8
%54 = sub nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %52, i64 %55
store i32 %51, i32* %56
br label %36
57: ; preds = %36
%58 = load i32*, i32** %9
%59 = call i32 @fclose(i32* %58)
%60 = load i32, i32* %8
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %60)
%62 = load i32*, i32** %6
%63 = load i32, i32* %8
%64 = call i32 @display(i32* %62, i32 %63)
%65 = load i32, i32* @IPC_PRIVATE
store i32 %65, i32* %12
%66 = load i32, i32* %8
%67 = sext i32 %66 to i64
%68 = mul i64 %67, 4
store i64 %68, i64* %14
%69 = load i32, i32* %12
%70 = load i64, i64* %14
%71 = load i32, i32* @IPC_CREAT
%72 = or i32 %71, 438
%73 = call i32 @shmget(i32 %69, i64 %70, i32 %72)
store i32 %73, i32* %11
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %78
75: ; preds = %57
%76 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %57
%79 = load i32, i32* %11
%80 = call i32* @shmat(i32 %79, i32* null, i32 0)
store i32* %80, i32** %7
%81 = icmp eq i32* %80, inttoptr (i64 -1 to i32*)
br i1 %81, label %82, label %85
82: ; preds = %78
%83 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%84 = call i32 @exit(i32 1)
unreachable
85: ; preds = %78
store i32 0, i32* %13
br label %86
86: ; preds = %100, %85
%87 = load i32, i32* %13
%88 = load i32, i32* %8
%89 = icmp slt i32 %87, %88
br i1 %89, label %90, label %103
90: ; preds = %86
%91 = load i32*, i32** %6
%92 = load i32, i32* %13
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i32, i32* %91, i64 %93
%95 = load i32, i32* %94
%96 = load i32*, i32** %7
%97 = load i32, i32* %13
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i32, i32* %96, i64 %98
store i32 %95, i32* %99
br label %100
100: ; preds = %90
%101 = load i32, i32* %13
%102 = add nsw i32 %101, 1
store i32 %102, i32* %13
br label %86
103: ; preds = %86
%104 = load i32*, i32** %7
%105 = load i32, i32* %8
%106 = call i32 @display(i32* %104, i32 %105)
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%108 = load i32*, i32** %7
%109 = load i32, i32* %8
%110 = sub nsw i32 %109, 1
%111 = call i32 @quicksort(i32* %108, i32 0, i32 %110)
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%113 = load i32*, i32** %7
%114 = load i32, i32* %8
%115 = call i32 @display(i32* %113, i32 %114)
%116 = load i32*, i32** %7
%117 = call i32 @shmdt(i32* %116)
%118 = icmp eq i32 %117, -1
br i1 %118, label %119, label %122
119: ; preds = %103
%120 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%121 = call i32 @exit(i32 1)
unreachable
122: ; preds = %103
%123 = load i32, i32* %11
%124 = load i32, i32* @IPC_RMID
%125 = call i32 @shmctl(i32 %123, i32 %124, i32* null)
%126 = icmp eq i32 %125, -1
br i1 %126, label %127, label %130
127: ; preds = %122
%128 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
%129 = call i32 @exit(i32 1)
unreachable
130: ; preds = %122
store i32 0, i32* %3
br label %131
131: ; preds = %130, %33, %17
%132 = load i32, i32* %3
ret i32 %132
}

LLVM IR (-O2):
@.str = [22 x i8] c"usage: %s <filename>\0A\00"
@.str.1 = [29 x i8] c"attempting to sort file: %s\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.5 = [18 x i8] c"%d elements read\0A\00"
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@.str.6 = [7 x i8] c"shmget\00"
@.str.7 = [6 x i8] c"shmat\00"
@.str.10 = [6 x i8] c"shmdt\00"
@IPC_RMID = global i32 0
@.str.11 = [7 x i8] c"shmctl\00"
@str = [15 x i8] c"now sorting...\00"
@str.12 = [13 x i8] c"done sorting\00"
@str.13 = [19 x i8] c"error opening file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %205
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %10
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %20, label %16
16: ; preds = %9
%17 = call i64 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%18 = load i64, i64* @EOF
%19 = icmp eq i64 %17, %18
br i1 %19, label %38, label %22
20: ; preds = %9
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.13, i64 0, i64 0))
br label %205
22: ; preds = %16, %22
%23 = phi i64 [ %25, %22 ], [ 0, %16 ]
%24 = phi i32* [ %29, %22 ], [ null, %16 ]
%25 = add nuw i64 %23, 1
%26 = trunc i64 %25 to i32
%27 = shl i32 %26, 2
%28 = call i64 @realloc(i32* %24, i32 %27)
%29 = inttoptr i64 %28 to i32*
%30 = load i32, i32* %3
%31 = getelementptr inbounds i32, i32* %29, i64 %23
store i32 %30, i32* %31
%32 = call i64 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%33 = load i64, i64* @EOF
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %22
35: ; preds = %22
%36 = trunc i64 %25 to i32
%37 = inttoptr i64 %28 to i32*
br label %38
38: ; preds = %35, %16
%39 = phi i32 [ 0, %16 ], [ %36, %35 ]
%40 = phi i32* [ null, %16 ], [ %37, %35 ]
%41 = call i32 @fclose(i32* %14)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %39)
%43 = call i32 @display(i32* %40, i32 %39)
%44 = load i32, i32* @IPC_PRIVATE
%45 = zext i32 %39 to i64
%46 = shl nuw nsw i64 %45, 2
%47 = load i32, i32* @IPC_CREAT
%48 = or i32 %47, 438
%49 = call i32 @shmget(i32 %44, i64 %46, i32 %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %54
51: ; preds = %38
%52 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %38
%55 = call i32* @shmat(i32 %49, i32* null, i32 0)
%56 = icmp eq i32* %55, inttoptr (i64 -1 to i32*)
br i1 %56, label %164, label %57
57: ; preds = %54
%58 = icmp eq i32 %39, 0
br i1 %58, label %186, label %59
59: ; preds = %57
%60 = icmp ult i32 %39, 8
br i1 %60, label %146, label %61
61: ; preds = %59
%62 = getelementptr i32, i32* %55, i64 %45
%63 = getelementptr i32, i32* %40, i64 %45
%64 = icmp ult i32* %55, %63
%65 = icmp ult i32* %40, %62
%66 = and i1 %64, %65
br i1 %66, label %146, label %67
67: ; preds = %61
%68 = and i64 %45, 4294967288
%69 = add nsw i64 %68, -8
%70 = lshr exact i64 %69, 3
%71 = add nuw nsw i64 %70, 1
%72 = and i64 %71, 3
%73 = icmp ult i64 %69, 24
br i1 %73, label %125, label %74
74: ; preds = %67
%75 = and i64 %71, 4611686018427387900
br label %76
76: ; preds = %76, %74
%77 = phi i64 [ 0, %74 ], [ %122, %76 ]
%78 = phi i64 [ 0, %74 ], [ %123, %76 ]
%79 = getelementptr inbounds i32, i32* %40, i64 %77
%80 = bitcast i32* %79 to <4 x i32>*
%81 = load <4 x i32>, <4 x i32>* %80
%82 = getelementptr inbounds i32, i32* %79, i64 4
%83 = bitcast i32* %82 to <4 x i32>*
%84 = load <4 x i32>, <4 x i32>* %83
%85 = getelementptr inbounds i32, i32* %55, i64 %77
%86 = bitcast i32* %85 to <4 x i32>*
store <4 x i32> %81, <4 x i32>* %86
%87 = getelementptr inbounds i32, i32* %85, i64 4
%88 = bitcast i32* %87 to <4 x i32>*
store <4 x i32> %84, <4 x i32>* %88
%89 = or i64 %77, 8
%90 = getelementptr inbounds i32, i32* %40, i64 %89
%91 = bitcast i32* %90 to <4 x i32>*
%92 = load <4 x i32>, <4 x i32>* %91
%93 = getelementptr inbounds i32, i32* %90, i64 4
%94 = bitcast i32* %93 to <4 x i32>*
%95 = load <4 x i32>, <4 x i32>* %94
%96 = getelementptr inbounds i32, i32* %55, i64 %89
%97 = bitcast i32* %96 to <4 x i32>*
store <4 x i32> %92, <4 x i32>* %97
%98 = getelementptr inbounds i32, i32* %96, i64 4
%99 = bitcast i32* %98 to <4 x i32>*
store <4 x i32> %95, <4 x i32>* %99
%100 = or i64 %77, 16
%101 = getelementptr inbounds i32, i32* %40, i64 %100
%102 = bitcast i32* %101 to <4 x i32>*
%103 = load <4 x i32>, <4 x i32>* %102
%104 = getelementptr inbounds i32, i32* %101, i64 4
%105 = bitcast i32* %104 to <4 x i32>*
%106 = load <4 x i32>, <4 x i32>* %105
%107 = getelementptr inbounds i32, i32* %55, i64 %100
%108 = bitcast i32* %107 to <4 x i32>*
store <4 x i32> %103, <4 x i32>* %108
%109 = getelementptr inbounds i32, i32* %107, i64 4
%110 = bitcast i32* %109 to <4 x i32>*
store <4 x i32> %106, <4 x i32>* %110
%111 = or i64 %77, 24
%112 = getelementptr inbounds i32, i32* %40, i64 %111
%113 = bitcast i32* %112 to <4 x i32>*
%114 = load <4 x i32>, <4 x i32>* %113
%115 = getelementptr inbounds i32, i32* %112, i64 4
%116 = bitcast i32* %115 to <4 x i32>*
%117 = load <4 x i32>, <4 x i32>* %116
%118 = getelementptr inbounds i32, i32* %55, i64 %111
%119 = bitcast i32* %118 to <4 x i32>*
store <4 x i32> %114, <4 x i32>* %119
%120 = getelementptr inbounds i32, i32* %118, i64 4
%121 = bitcast i32* %120 to <4 x i32>*
store <4 x i32> %117, <4 x i32>* %121
%122 = add nuw i64 %77, 32
%123 = add i64 %78, 4
%124 = icmp eq i64 %123, %75
br i1 %124, label %125, label %76
125: ; preds = %76, %67
%126 = phi i64 [ 0, %67 ], [ %122, %76 ]
%127 = icmp eq i64 %72, 0
br i1 %127, label %144, label %128
128: ; preds = %125, %128
%129 = phi i64 [ %141, %128 ], [ %126, %125 ]
%130 = phi i64 [ %142, %128 ], [ 0, %125 ]
%131 = getelementptr inbounds i32, i32* %40, i64 %129
%132 = bitcast i32* %131 to <4 x i32>*
%133 = load <4 x i32>, <4 x i32>* %132
%134 = getelementptr inbounds i32, i32* %131, i64 4
%135 = bitcast i32* %134 to <4 x i32>*
%136 = load <4 x i32>, <4 x i32>* %135
%137 = getelementptr inbounds i32, i32* %55, i64 %129
%138 = bitcast i32* %137 to <4 x i32>*
store <4 x i32> %133, <4 x i32>* %138
%139 = getelementptr inbounds i32, i32* %137, i64 4
%140 = bitcast i32* %139 to <4 x i32>*
store <4 x i32> %136, <4 x i32>* %140
%141 = add nuw i64 %129, 8
%142 = add i64 %130, 1
%143 = icmp eq i64 %142, %72
br i1 %143, label %144, label %128
144: ; preds = %128, %125
%145 = icmp eq i64 %68, %45
br i1 %145, label %186, label %146
146: ; preds = %61, %59, %144
%147 = phi i64 [ 0, %61 ], [ 0, %59 ], [ %68, %144 ]
%148 = xor i64 %147, -1
%149 = add nsw i64 %148, %45
%150 = and i64 %45, 3
%151 = icmp eq i64 %150, 0
br i1 %151, label %161, label %152
152: ; preds = %146, %152
%153 = phi i64 [ %158, %152 ], [ %147, %146 ]
%154 = phi i64 [ %159, %152 ], [ 0, %146 ]
%155 = getelementptr inbounds i32, i32* %40, i64 %153
%156 = load i32, i32* %155
%157 = getelementptr inbounds i32, i32* %55, i64 %153
store i32 %156, i32* %157
%158 = add nuw nsw i64 %153, 1
%159 = add i64 %154, 1
%160 = icmp eq i64 %159, %150
br i1 %160, label %161, label %152
161: ; preds = %152, %146
%162 = phi i64 [ %147, %146 ], [ %158, %152 ]
%163 = icmp ult i64 %149, 3
br i1 %163, label %186, label %167
164: ; preds = %54
%165 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%166 = call i32 @exit(i32 1)
unreachable
167: ; preds = %161, %167
%168 = phi i64 [ %184, %167 ], [ %162, %161 ]
%169 = getelementptr inbounds i32, i32* %40, i64 %168
%170 = load i32, i32* %169
%171 = getelementptr inbounds i32, i32* %55, i64 %168
store i32 %170, i32* %171
%172 = add nuw nsw i64 %168, 1
%173 = getelementptr inbounds i32, i32* %40, i64 %172
%174 = load i32, i32* %173
%175 = getelementptr inbounds i32, i32* %55, i64 %172
store i32 %174, i32* %175
%176 = add nuw nsw i64 %168, 2
%177 = getelementptr inbounds i32, i32* %40, i64 %176
%178 = load i32, i32* %177
%179 = getelementptr inbounds i32, i32* %55, i64 %176
store i32 %178, i32* %179
%180 = add nuw nsw i64 %168, 3
%181 = getelementptr inbounds i32, i32* %40, i64 %180
%182 = load i32, i32* %181
%183 = getelementptr inbounds i32, i32* %55, i64 %180
store i32 %182, i32* %183
%184 = add nuw nsw i64 %168, 4
%185 = icmp eq i64 %184, %45
br i1 %185, label %186, label %167
186: ; preds = %161, %167, %144, %57
%187 = call i32 @display(i32* %55, i32 %39)
%188 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%189 = add nsw i32 %39, -1
%190 = call i32 @quicksort(i32* %55, i32 0, i32 %189)
%191 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.12, i64 0, i64 0))
%192 = call i32 @display(i32* %55, i32 %39)
%193 = call i32 @shmdt(i32* %55)
%194 = icmp eq i32 %193, -1
br i1 %194, label %195, label %198
195: ; preds = %186
%196 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%197 = call i32 @exit(i32 1)
unreachable
198: ; preds = %186
%199 = load i32, i32* @IPC_RMID
%200 = call i32 @shmctl(i32 %49, i32 %199, i32* null)
%201 = icmp eq i32 %200, -1
br i1 %201, label %202, label %205
202: ; preds = %198
%203 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
%204 = call i32 @exit(i32 1)
unreachable
205: ; preds = %198, %20, %6
%206 = phi i32 [ 1, %6 ], [ 0, %20 ], [ 0, %198 ]
ret i32 %206
}