#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*/ mergesort(int *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
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 length = 0;
  FILE *fh;
  int data;
  int *shm_array;
  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);
  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);
  mergesort(shm_array, length);
  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,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1220 <main+0x50>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1447 <main+0x277>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdee(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1273 <main+0xa3>
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1447 <main+0x277>
jmp    1278 <main+0xa8>
mov    -0x28(%rbp),%rdi
lea    0xdc6(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1070 <fscanf@plt>
mov    0x2d4d(%rip),%rcx
cmp    (%rcx),%rax
je     12d4 <main+0x104>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1080 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1278 <main+0xa8>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1c(%rbp),%esi
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2cf3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    0x2cb4(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
call   10e0 <shmget@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
jne    1343 <main+0x173>
lea    0xd2a(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x3c(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10d0 <shmat@plt>
mov    %rax,-0x38(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    137b <main+0x1ab>
lea    0xcf9(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    13b2 <main+0x1e2>
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x38(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1382 <main+0x1b2>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <display@plt>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1090 <mergesort@plt>
lea    0xc9a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <display@plt>
mov    -0x38(%rbp),%rdi
call   1030 <shmdt@plt>
cmp    $0xffffffff,%eax
jne    140c <main+0x23c>
lea    0xc7c(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x3c(%rbp),%edi
mov    0x2bba(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   10a0 <shmctl@plt>
cmp    $0xffffffff,%eax
jne    1440 <main+0x270>
lea    0xc4e(%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   1070 <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   1080 <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   1070 <printf@plt>
mov    $0x1,%ebx
jmp    14d8 <main+0x2f8>
lea    0xe09(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    14d8 <main+0x2f8>
mov    $0x4,%ebx
xor    %r15d,%r15d
xor    %r12d,%r12d
nop
mov    %r15,%rbp
add    $0x1,%r15
mov    %r12,%rdi
mov    %ebx,%esi
call   1090 <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   1080 <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   1070 <printf@plt>
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
mov    %r15d,%r15d
lea    0x0(,%r15,4),%rsi
mov    0x2cdb(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
call   10f0 <shmget@plt>
cmp    $0xffffffff,%eax
je     14e9 <main+0x309>
mov    %eax,%r14d
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
je     14f2 <main+0x312>
mov    %rax,%rbp
test   %r15,%r15
je     1484 <main+0x2a4>
cmp    $0x8,%r15d
jb     1345 <main+0x165>
lea    (%r12,%r15,4),%rax
cmp    %rax,%rbp
jae    13b1 <main+0x1d1>
lea    0x0(,%r15,4),%rax
add    %rbp,%rax
cmp    %rax,%r12
jae    13b1 <main+0x1d1>
xor    %eax,%eax
mov    %rax,%rcx
not    %rcx
add    %r15,%rcx
mov    %r15,%rdx
and    $0x3,%rdx
je     1372 <main+0x192>
nopl   0x0(%rax)
mov    (%r12,%rax,4),%esi
mov    %esi,0x0(%rbp,%rax,4)
add    $0x1,%rax
add    $0xffffffffffffffff,%rdx
jne    1360 <main+0x180>
cmp    $0x3,%rcx
jb     1484 <main+0x2a4>
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    1380 <main+0x1a0>
jmp    1484 <main+0x2a4>
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    13d5 <main+0x1f5>
xor    %esi,%esi
jmp    1441 <main+0x261>
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    13e0 <main+0x200>
test   %rcx,%rcx
je     147b <main+0x29b>
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    1460 <main+0x280>
cmp    %r15,%rax
jne    1347 <main+0x167>
mov    %rbp,%rdi
mov    %r15d,%esi
call   1060 <display@plt>
mov    %rbp,%rdi
mov    %r15d,%esi
call   10a0 <mergesort@plt>
lea    0xbc3(%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     14fb <main+0x31b>
mov    0x2b0b(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
mov    %r14d,%edi
xor    %edx,%edx
call   10b0 <shmctl@plt>
cmp    $0xffffffff,%eax
je     1504 <main+0x324>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb5a(%rip),%rdi
jmp    150b <main+0x32b>
lea    0xb58(%rip),%rdi
jmp    150b <main+0x32b>
lea    0xb55(%rip),%rdi
jmp    150b <main+0x32b>
lea    0xb52(%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 = [14 x i8] c"done sorting\0A\00"
@.str.9 = [6 x i8] c"shmdt\00"
@IPC_RMID = global i32 0
@.str.10 = [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* %7
%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 %126
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** %8
%31 = load i32*, i32** %8
%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 %126
35: ; preds = %22
br label %36
36: ; preds = %41, %35
%37 = load i32*, i32** %8
%38 = call i64 @fscanf(i32* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %9)
%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* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
%44 = load i32*, i32** %6
%45 = load i32, i32* %7
%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* %9
%52 = load i32*, i32** %6
%53 = load i32, i32* %7
%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** %8
%59 = call i32 @fclose(i32* %58)
%60 = load i32, i32* %7
%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* @IPC_PRIVATE
store i32 %62, i32* %12
%63 = load i32, i32* %7
%64 = sext i32 %63 to i64
%65 = mul i64 %64, 4
store i64 %65, i64* %14
%66 = load i32, i32* %12
%67 = load i64, i64* %14
%68 = load i32, i32* @IPC_CREAT
%69 = or i32 %68, 438
%70 = call i32 @shmget(i32 %66, i64 %67, i32 %69)
store i32 %70, i32* %11
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %75
72: ; preds = %57
%73 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %57
%76 = load i32, i32* %11
%77 = call i32* @shmat(i32 %76, i32* null, i32 0)
store i32* %77, i32** %10
%78 = icmp eq i32* %77, inttoptr (i64 -1 to i32*)
br i1 %78, label %79, label %82
79: ; preds = %75
%80 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %75
store i32 0, i32* %13
br label %83
83: ; preds = %97, %82
%84 = load i32, i32* %13
%85 = load i32, i32* %7
%86 = icmp slt i32 %84, %85
br i1 %86, label %87, label %100
87: ; preds = %83
%88 = load i32*, i32** %6
%89 = load i32, i32* %13
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i32, i32* %88, i64 %90
%92 = load i32, i32* %91
%93 = load i32*, i32** %10
%94 = load i32, i32* %13
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i32, i32* %93, i64 %95
store i32 %92, i32* %96
br label %97
97: ; preds = %87
%98 = load i32, i32* %13
%99 = add nsw i32 %98, 1
store i32 %99, i32* %13
br label %83
100: ; preds = %83
%101 = load i32*, i32** %10
%102 = load i32, i32* %7
%103 = call i32 @display(i32* %101, i32 %102)
%104 = load i32*, i32** %10
%105 = load i32, i32* %7
%106 = call i32 @mergesort(i32* %104, i32 %105)
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%108 = load i32*, i32** %10
%109 = load i32, i32* %7
%110 = call i32 @display(i32* %108, i32 %109)
%111 = load i32*, i32** %10
%112 = call i32 @shmdt(i32* %111)
%113 = icmp eq i32 %112, -1
br i1 %113, label %114, label %117
114: ; preds = %100
%115 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%116 = call i32 @exit(i32 1)
unreachable
117: ; preds = %100
%118 = load i32, i32* %11
%119 = load i32, i32* @IPC_RMID
%120 = call i32 @shmctl(i32 %118, i32 %119, i32* null)
%121 = icmp eq i32 %120, -1
br i1 %121, label %122, label %125
122: ; preds = %117
%123 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
%124 = call i32 @exit(i32 1)
unreachable
125: ; preds = %117
store i32 0, i32* %3
br label %126
126: ; preds = %125, %33, %17
%127 = load i32, i32* %3
ret i32 %127
}

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