#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*/ sem_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ *SEM_FAILED;
int /*<<< orphan*/ STDOUT_FILENO;
int S_IRUSR;
int S_IWUSR;
int atoi(char *);
int close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int ftruncate(int, size_t);
int /*<<< orphan*/ memcpy(char *, int *, size_t);
char *mmap(int /*<<< orphan*/ *, size_t, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ *sem_open(char *, int, int, int /*<<< orphan*/);
int sem_post(int /*<<< orphan*/ *);
int sem_wait(int /*<<< orphan*/ *);
int shm_open(char *, int, int /*<<< orphan*/);
int shm_unlink(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, size_t);
int main(int argc, char *argv[]) {
  if (argv[1] == NULL || argv[2] == NULL) {
    printf("no command arguments given, exiting\n");
    exit(EXIT_FAILURE);
  }
  char *shared_memory = argv[1];
  int num_elements = atoi(argv[2]);
  size_t len = num_elements * sizeof(int);
  int fd, i;
  int array[num_elements];
  sem_t *sem;
  fd = shm_open(shared_memory, O_CREAT | O_RDWR, 0);
  if (fd == -1) {
    perror("shared memory open");
    exit(EXIT_FAILURE);
  }
  printf("shared memory open!");
  if (ftruncate(fd, len) == -1) {
    perror("shared memory resize");
    exit(EXIT_FAILURE);
  }
  printf("shared memory resized!");
  sem = sem_open("zurn_sem", O_CREAT, S_IRUSR | S_IWUSR, 0);
  if (sem == SEM_FAILED) {
    perror("semaphore open failure");
    exit(EXIT_FAILURE);
  }
  for (i = 0; i < num_elements; i++) {
    array[i] = rand();
  }
  shared_memory = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  if (shared_memory == MAP_FAILED) {
    perror("memory mapping failed");
    exit(EXIT_FAILURE);
  }
  if (close(fd) == -1) {
    perror("close fd error");
  }
  memcpy(shared_memory, array, len);
  if (sem_post(sem) == -1) {
    perror("sem post error");
    exit(EXIT_FAILURE);
  }
  if (sem_wait(sem) == -1) {
    perror("sem wait error");
    exit(EXIT_FAILURE);
  }
  write(STDOUT_FILENO, shared_memory, len);
  if (shm_unlink("zurn_sem") == -1) {
    perror("sem unlink error");
    exit(EXIT_FAILURE);
  }
  printf("\n");
  exit(EXIT_SUCCESS);
}


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)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     1224 <main+0x34>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
jne    123e <main+0x4e>
lea    0xdd5(%rip),%rdi
call   1060 <printf@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d60(%rip),%rax
mov    (%rax),%esi
mov    0x2d27(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   10f0 <shm_open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    12d1 <main+0xe1>
lea    0xd67(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    0xd60(%rip),%rdi
call   1060 <printf@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1070 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    130c <main+0x11c>
lea    0xd53(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    0xd4e(%rip),%rdi
call   1060 <printf@plt>
mov    0x2cd9(%rip),%rax
mov    (%rax),%esi
mov    0x2c70(%rip),%rax
mov    (%rax),%edx
mov    0x2c87(%rip),%rax
or     (%rax),%edx
lea    0xd3e(%rip),%rdi
xor    %ecx,%ecx
call   10a0 <sem_open@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    0x2c70(%rip),%rcx
cmp    (%rcx),%rax
jne    1373 <main+0x183>
lea    0xd21(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c3c(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    13a8 <main+0x1b8>
mov    $0x0,%al
call   1110 <rand@plt>
mov    %eax,%edx
mov    -0x50(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    137a <main+0x18a>
mov    -0x28(%rbp),%rsi
mov    0x2c3d(%rip),%rax
mov    (%rax),%edx
mov    0x2be4(%rip),%rax
or     (%rax),%edx
mov    0x2c13(%rip),%rax
mov    (%rax),%ecx
mov    -0x2c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2ba2(%rip),%rcx
cmp    (%rcx),%rax
jne    1409 <main+0x219>
lea    0xca2(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2ba6(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
cmp    $0xffffffff,%eax
jne    1426 <main+0x236>
lea    0xc8d(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x50(%rbp),%rsi
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
call   10b0 <memcpy@plt>
mov    -0x48(%rbp),%rdi
call   1090 <sem_post@plt>
cmp    $0xffffffff,%eax
jne    1463 <main+0x273>
lea    0xc6d(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2b4c(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x48(%rbp),%rdi
call   1030 <sem_wait@plt>
cmp    $0xffffffff,%eax
jne    148f <main+0x29f>
lea    0xc50(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2b20(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    0x2b4a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <write@plt>
lea    0xbcc(%rip),%rdi
call   1100 <shm_unlink@plt>
cmp    $0xffffffff,%eax
jne    14d4 <main+0x2e4>
lea    0xc1a(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2adb(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    0xb48(%rip),%rdi
call   1060 <printf@plt>
mov    0x2aa9(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x8(%rsi),%r14
test   %r14,%r14
je     1230 <main+0x20>
mov    0x10(%rsi),%rdi
test   %rdi,%rdi
jne    1241 <main+0x31>
lea    0xe90(%rip),%rdi
call   1050 <puts@plt>
jmp    1403 <main+0x1f3>
call   10f0 <atoi@plt>
mov    %eax,%r12d
mov    %eax,%ebx
mov    %rsp,%r13
lea    0xf(,%rbx,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    0x2d91(%rip),%rcx
mov    0x2d5a(%rip),%rax
mov    (%rax),%esi
or     (%rcx),%esi
mov    %r14,%rdi
xor    %edx,%edx
call   1110 <shm_open@plt>
cmp    $0xffffffff,%eax
jne    128d <main+0x7d>
lea    0xd78(%rip),%rdi
jmp    13fe <main+0x1ee>
mov    %eax,%r15d
movslq %r12d,%r14
shl    $0x2,%r14
lea    0xd75(%rip),%rdi
call   1080 <printf@plt>
mov    %r15d,%edi
mov    %r14,%rsi
call   1090 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    12bf <main+0xaf>
lea    0xd6d(%rip),%rdi
jmp    13fe <main+0x1ee>
lea    0xd76(%rip),%rdi
call   1080 <printf@plt>
mov    0x2d26(%rip),%rax
mov    (%rax),%esi
mov    0x2cbd(%rip),%rax
mov    0x2cd6(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xd66(%rip),%rdi
xor    %ecx,%ecx
call   10c0 <sem_open@plt>
mov    0x2cc5(%rip),%rcx
cmp    (%rcx),%rax
jne    130c <main+0xfc>
lea    0xd55(%rip),%rdi
jmp    13fe <main+0x1ee>
mov    %rax,-0x30(%rbp)
test   %ebx,%ebx
jle    1335 <main+0x125>
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1130 <rand@plt>
mov    %eax,0x0(%r13,%r12,4)
add    $0x1,%r12
cmp    %r12,%rbx
jne    1320 <main+0x110>
mov    0x2cb4(%rip),%rax
mov    0x2c5d(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2c8a(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14,%rsi
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,%r12
mov    0x2c1e(%rip),%rax
cmp    (%rax),%r12
jne    137b <main+0x16b>
lea    0xcfd(%rip),%rdi
jmp    13fe <main+0x1ee>
mov    %r15d,%edi
call   10a0 <close@plt>
cmp    $0xffffffff,%eax
jne    1394 <main+0x184>
lea    0xcfa(%rip),%rdi
call   10e0 <perror@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   10d0 <memcpy@plt>
mov    -0x30(%rbp),%rbx
mov    %rbx,%rdi
call   10b0 <sem_post@plt>
cmp    $0xffffffff,%eax
jne    13bc <main+0x1ac>
lea    0xcde(%rip),%rdi
jmp    13fe <main+0x1ee>
mov    %rbx,%rdi
call   1040 <sem_wait@plt>
cmp    $0xffffffff,%eax
jne    13d2 <main+0x1c2>
lea    0xcd7(%rip),%rdi
jmp    13fe <main+0x1ee>
mov    0x2c07(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
mov    %r14,%rdx
call   1060 <write@plt>
lea    0xc66(%rip),%rdi
call   1120 <shm_unlink@plt>
cmp    $0xffffffff,%eax
jne    1411 <main+0x201>
lea    0xcb8(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2b9e(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2b6e(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"no command arguments given, exiting\0A\00"
@EXIT_FAILURE = global i32 0
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.1 = [19 x i8] c"shared memory open\00"
@.str.2 = [20 x i8] c"shared memory open!\00"
@.str.3 = [21 x i8] c"shared memory resize\00"
@.str.4 = [23 x i8] c"shared memory resized!\00"
@.str.5 = [9 x i8] c"zurn_sem\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@SEM_FAILED = global i32* null
@.str.6 = [23 x i8] c"semaphore open failure\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.7 = [22 x i8] c"memory mapping failed\00"
@.str.8 = [15 x i8] c"close fd error\00"
@.str.9 = [15 x i8] c"sem post error\00"
@.str.10 = [15 x i8] c"sem wait error\00"
@STDOUT_FILENO = global i32 0
@.str.11 = [17 x i8] c"sem unlink error\00"
@.str.12 = [2 x i8] c"\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = icmp eq i8* %16, null
br i1 %17, label %23, label %18
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %18, %2
%24 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %18
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
store i8* %30, i8** %6
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = mul i64 %36, 4
store i64 %37, i64* %8
%38 = load i32, i32* %7
%39 = zext i32 %38 to i64
%40 = call i8* @llvm.stacksave()
store i8* %40, i8** %11
%41 = alloca i32, i64 %39
store i64 %39, i64* %12
%42 = load i8*, i8** %6
%43 = load i32, i32* @O_CREAT
%44 = load i32, i32* @O_RDWR
%45 = or i32 %43, %44
%46 = call i32 @shm_open(i8* %42, i32 %45, i32 0)
store i32 %46, i32* %9
%47 = load i32, i32* %9
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %53
49: ; preds = %27
%50 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %27
%54 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%55 = load i32, i32* %9
%56 = load i64, i64* %8
%57 = call i32 @ftruncate(i32 %55, i64 %56)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %63
59: ; preds = %53
%60 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%61 = load i32, i32* @EXIT_FAILURE
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %53
%64 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%65 = load i32, i32* @O_CREAT
%66 = load i32, i32* @S_IRUSR
%67 = load i32, i32* @S_IWUSR
%68 = or i32 %66, %67
%69 = call i32* @sem_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %65, i32 %68, i32 0)
store i32* %69, i32** %13
%70 = load i32*, i32** %13
%71 = load i32*, i32** @SEM_FAILED
%72 = icmp eq i32* %70, %71
br i1 %72, label %73, label %77
73: ; preds = %63
%74 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%75 = load i32, i32* @EXIT_FAILURE
%76 = call i32 @exit(i32 %75)
unreachable
77: ; preds = %63
store i32 0, i32* %10
br label %78
78: ; preds = %87, %77
%79 = load i32, i32* %10
%80 = load i32, i32* %7
%81 = icmp slt i32 %79, %80
br i1 %81, label %82, label %90
82: ; preds = %78
%83 = call i32 (...) @rand()
%84 = load i32, i32* %10
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i32, i32* %41, i64 %85
store i32 %83, i32* %86
br label %87
87: ; preds = %82
%88 = load i32, i32* %10
%89 = add nsw i32 %88, 1
store i32 %89, i32* %10
br label %78
90: ; preds = %78
%91 = load i64, i64* %8
%92 = load i32, i32* @PROT_READ
%93 = load i32, i32* @PROT_WRITE
%94 = or i32 %92, %93
%95 = load i32, i32* @MAP_SHARED
%96 = load i32, i32* %9
%97 = call i8* @mmap(i32* null, i64 %91, i32 %94, i32 %95, i32 %96, i32 0)
store i8* %97, i8** %6
%98 = load i8*, i8** %6
%99 = load i8*, i8** @MAP_FAILED
%100 = icmp eq i8* %98, %99
br i1 %100, label %101, label %105
101: ; preds = %90
%102 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%103 = load i32, i32* @EXIT_FAILURE
%104 = call i32 @exit(i32 %103)
unreachable
105: ; preds = %90
%106 = load i32, i32* %9
%107 = call i32 @close(i32 %106)
%108 = icmp eq i32 %107, -1
br i1 %108, label %109, label %111
109: ; preds = %105
%110 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
br label %111
111: ; preds = %109, %105
%112 = load i8*, i8** %6
%113 = load i64, i64* %8
%114 = call i32 @memcpy(i8* %112, i32* %41, i64 %113)
%115 = load i32*, i32** %13
%116 = call i32 @sem_post(i32* %115)
%117 = icmp eq i32 %116, -1
br i1 %117, label %118, label %122
118: ; preds = %111
%119 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%120 = load i32, i32* @EXIT_FAILURE
%121 = call i32 @exit(i32 %120)
unreachable
122: ; preds = %111
%123 = load i32*, i32** %13
%124 = call i32 @sem_wait(i32* %123)
%125 = icmp eq i32 %124, -1
br i1 %125, label %126, label %130
126: ; preds = %122
%127 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
%128 = load i32, i32* @EXIT_FAILURE
%129 = call i32 @exit(i32 %128)
unreachable
130: ; preds = %122
%131 = load i32, i32* @STDOUT_FILENO
%132 = load i8*, i8** %6
%133 = load i64, i64* %8
%134 = call i32 @write(i32 %131, i8* %132, i64 %133)
%135 = call i32 @shm_unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%136 = icmp eq i32 %135, -1
br i1 %136, label %137, label %141
137: ; preds = %130
%138 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
%139 = load i32, i32* @EXIT_FAILURE
%140 = call i32 @exit(i32 %139)
unreachable
141: ; preds = %130
%142 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%143 = load i32, i32* @EXIT_SUCCESS
%144 = call i32 @exit(i32 %143)
unreachable
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.1 = [19 x i8] c"shared memory open\00"
@.str.2 = [20 x i8] c"shared memory open!\00"
@.str.3 = [21 x i8] c"shared memory resize\00"
@.str.4 = [23 x i8] c"shared memory resized!\00"
@.str.5 = [9 x i8] c"zurn_sem\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@SEM_FAILED = global i32* null
@.str.6 = [23 x i8] c"semaphore open failure\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.7 = [22 x i8] c"memory mapping failed\00"
@.str.8 = [15 x i8] c"close fd error\00"
@.str.9 = [15 x i8] c"sem post error\00"
@.str.10 = [15 x i8] c"sem wait error\00"
@STDOUT_FILENO = global i32 0
@.str.11 = [17 x i8] c"sem unlink error\00"
@EXIT_SUCCESS = global i32 0
@str = [36 x i8] c"no command arguments given, exiting\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %6, %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %6
%15 = tail call i32 @atoi(i8* %8)
%16 = sext i32 %15 to i64
%17 = shl nsw i64 %16, 2
%18 = zext i32 %15 to i64
%19 = alloca i32, i64 %18
%20 = load i32, i32* @O_CREAT
%21 = load i32, i32* @O_RDWR
%22 = or i32 %21, %20
%23 = tail call i32 @shm_open(i8* %4, i32 %22, i32 0)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %14
%26 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %14
%30 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%31 = tail call i32 @ftruncate(i32 %23, i64 %17)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = tail call i32 @exit(i32 %35)
unreachable
37: ; preds = %29
%38 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%39 = load i32, i32* @O_CREAT
%40 = load i32, i32* @S_IRUSR
%41 = load i32, i32* @S_IWUSR
%42 = or i32 %41, %40
%43 = tail call i32* @sem_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %39, i32 %42, i32 0)
%44 = load i32*, i32** @SEM_FAILED
%45 = icmp eq i32* %43, %44
br i1 %45, label %48, label %46
46: ; preds = %37
%47 = icmp sgt i32 %15, 0
br i1 %47, label %52, label %58
48: ; preds = %37
%49 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = tail call i32 @exit(i32 %50)
unreachable
52: ; preds = %46, %52
%53 = phi i64 [ %56, %52 ], [ 0, %46 ]
%54 = tail call i32 (...) @rand()
%55 = getelementptr inbounds i32, i32* %19, i64 %53
store i32 %54, i32* %55
%56 = add nuw nsw i64 %53, 1
%57 = icmp eq i64 %56, %18
br i1 %57, label %58, label %52
58: ; preds = %52, %46
%59 = load i32, i32* @PROT_READ
%60 = load i32, i32* @PROT_WRITE
%61 = or i32 %60, %59
%62 = load i32, i32* @MAP_SHARED
%63 = tail call i8* @mmap(i32* null, i64 %17, i32 %61, i32 %62, i32 %23, i32 0)
%64 = load i8*, i8** @MAP_FAILED
%65 = icmp eq i8* %63, %64
br i1 %65, label %66, label %70
66: ; preds = %58
%67 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%68 = load i32, i32* @EXIT_FAILURE
%69 = tail call i32 @exit(i32 %68)
unreachable
70: ; preds = %58
%71 = tail call i32 @close(i32 %23)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %75
73: ; preds = %70
%74 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
br label %75
75: ; preds = %73, %70
%76 = call i32 @memcpy(i8* %63, i32* %19, i64 %17)
%77 = call i32 @sem_post(i32* %43)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %83
79: ; preds = %75
%80 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%81 = load i32, i32* @EXIT_FAILURE
%82 = call i32 @exit(i32 %81)
unreachable
83: ; preds = %75
%84 = call i32 @sem_wait(i32* %43)
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %90
86: ; preds = %83
%87 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
%88 = load i32, i32* @EXIT_FAILURE
%89 = call i32 @exit(i32 %88)
unreachable
90: ; preds = %83
%91 = load i32, i32* @STDOUT_FILENO
%92 = call i32 @write(i32 %91, i8* %63, i64 %17)
%93 = call i32 @shm_unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %99
95: ; preds = %90
%96 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
%97 = load i32, i32* @EXIT_FAILURE
%98 = call i32 @exit(i32 %97)
unreachable
99: ; preds = %90
%100 = call i32 @putchar(i32 10)
%101 = load i32, i32* @EXIT_SUCCESS
%102 = call i32 @exit(i32 %101)
unreachable
}