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

/* Variables and functions */
scalar_t__ ECHILD;
int IPC_CREAT;
int /*<<< orphan*/ IPC_RMID;
int O_CREAT;
int O_EXCL;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int ftok(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, unsigned int *);
int /*<<< orphan*/ sem_destroy(int /*<<< orphan*/ *);
int /*<<< orphan*/ *sem_open(char *, int, int, unsigned int);
int /*<<< orphan*/ sem_post(int /*<<< orphan*/ *);
int /*<<< orphan*/ sem_unlink(char *);
int /*<<< orphan*/ sem_wait(int /*<<< orphan*/ *);
scalar_t__ shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ shmdt(int *);
int shmget(int, int, int);
int /*<<< orphan*/ sleep(int);
scalar_t__ waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int i;
  key_t shmkey;
  int shmid;
  sem_t *sem;
  pid_t pid;
  int *p;
  unsigned int n;
  unsigned int value;
  shmkey = ftok("/dev/null", 5);
  printf("shmkey for p = %d\n", shmkey);
  shmid = shmget(shmkey, sizeof(int), 0644 | IPC_CREAT);
  if (shmid < 0) {
    perror("shmget\n");
    exit(1);
  }
  p = (int *)shmat(shmid, NULL, 0);
  *p = 0;
  printf("p=%d is allocated in shared memory.\n\n", *p);
  printf("How many children do you want to fork?\n");
  printf("Fork count: ");
  scanf("%u", &n);
  printf("What do you want the semaphore value to be?\n");
  printf("Semaphore value: ");
  scanf("%u", &value);
  sem = sem_open("pSem", O_CREAT | O_EXCL, 0644, value);
  sem_unlink("pSem");
  printf("semaphores initialized.\n\n");
  for (i = 0; i < n; i++) {
    pid = fork();
    if (pid < 0)
      printf("Fork error.\n");
    else if (pid == 0)
      break;
  }
  if (pid != 0) {
    while (pid = waitpid(-1, NULL, 0)) {
      if (errno == ECHILD)
        break;
    }
    printf("\nParent: All children have exited.\n");
    shmdt(p);
    shmctl(shmid, IPC_RMID, 0);
    sem_destroy(sem);
    exit(0);
  } else {
    sem_wait(sem);
    printf("  Child(%d) is in critical section.\n", i);
    sleep(1);
    *p += i % 3;
    printf("  Child(%d) new value of *p=%d.\n", i, *p);
    sem_post(sem);
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xdd3(%rip),%rdi
mov    $0x5,%esi
call   10f0 <ftok@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%edi
mov    0x2d63(%rip),%rax
mov    (%rax),%edx
or     $0x1a4,%edx
mov    $0x4,%esi
call   10d0 <shmget@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    128a <main+0x7a>
lea    0xda2(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x1c(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10c0 <shmat@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rax
mov    (%rax),%esi
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xda3(%rip),%rdi
lea    -0x3c(%rbp),%rsi
call   1080 <scanf@plt>
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd77(%rip),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <scanf@plt>
mov    0x2cdf(%rip),%rax
mov    (%rax),%esi
mov    0x2cb6(%rip),%rax
or     (%rax),%esi
mov    -0x40(%rbp),%ecx
lea    0xd94(%rip),%rdi
mov    $0x1a4,%edx
call   1070 <sem_open@plt>
mov    %rax,-0x28(%rbp)
lea    0xd7f(%rip),%rdi
call   1110 <sem_unlink@plt>
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jae    13ba <main+0x1aa>
mov    $0x0,%al
call   1130 <fork@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    1392 <main+0x182>
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13a7 <main+0x197>
cmpq   $0x0,-0x30(%rbp)
jne    13a2 <main+0x192>
jmp    13ba <main+0x1aa>
jmp    13a7 <main+0x197>
jmp    13ac <main+0x19c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    135d <main+0x14d>
cmpq   $0x0,-0x30(%rbp)
je     1446 <main+0x236>
jmp    13ca <main+0x1ba>
mov    $0xffffffff,%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     140c <main+0x1fc>
mov    0x2be1(%rip),%rax
mov    (%rax),%rax
mov    0x2bc7(%rip),%rcx
cmp    (%rcx),%rax
jne    1407 <main+0x1f7>
jmp    140c <main+0x1fc>
jmp    13ca <main+0x1ba>
lea    0xcdb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1040 <shmdt@plt>
mov    -0x1c(%rbp),%edi
mov    0x2b9b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <shmctl@plt>
mov    -0x28(%rbp),%rdi
call   1120 <sem_destroy@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1030 <sem_wait@plt>
mov    -0x14(%rbp),%esi
lea    0xcb9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <sleep@plt>
mov    -0x14(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    -0x38(%rbp),%rax
add    (%rax),%edx
mov    %edx,(%rax)
mov    -0x14(%rbp),%esi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
lea    0xcaa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1060 <sem_post@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xdcd(%rip),%rdi
mov    $0x5,%esi
call   1100 <ftok@plt>
mov    %eax,%ebx
lea    0xdc4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d62(%rip),%rax
mov    $0x1a4,%edx
or     (%rax),%edx
mov    %ebx,%edi
mov    $0x4,%esi
call   10e0 <shmget@plt>
test   %eax,%eax
jns    1283 <main+0x63>
lea    0xda9(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    %eax,%r12d
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <shmat@plt>
mov    %rax,%r15
movl   $0x0,(%rax)
lea    0xd84(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe07(%rip),%rdi
call   1040 <puts@plt>
lea    0xd8e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd8d(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <scanf@plt>
lea    0xe00(%rip),%rdi
call   1040 <puts@plt>
lea    0xd70(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <scanf@plt>
mov    0x2cf2(%rip),%rax
mov    0x2ccb(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0xc(%rsp),%ecx
lea    0xd51(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1a4,%edx
call   1080 <sem_open@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1120 <sem_unlink@plt>
lea    0xdd0(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0x8(%rsp)
jne    13b2 <main+0x192>
mov    0x2c82(%rip),%rbx
mov    0x2c6b(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xffffffff,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10a0 <waitpid@plt>
test   %rax,%rax
je     137c <main+0x15c>
mov    (%rbx),%rax
cmp    0x0(%rbp),%rax
jne    1360 <main+0x140>
lea    0xda1(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1050 <shmdt@plt>
mov    0x2c31(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
xor    %edx,%edx
call   10b0 <shmctl@plt>
mov    %r14,%rdi
call   1130 <sem_destroy@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
lea    0xd8e(%rip),%rbp
xor    %ebx,%ebx
jmp    13d5 <main+0x1b5>
nopl   (%rax)
mov    %rbp,%rdi
call   1040 <puts@plt>
add    $0x1,%ebx
cmp    0x8(%rsp),%ebx
jae    1347 <main+0x127>
xor    %eax,%eax
call   1140 <fork@plt>
test   %rax,%rax
js     13c0 <main+0x1a0>
jne    13c8 <main+0x1a8>
mov    %r14,%rdi
call   1030 <sem_wait@plt>
lea    0xc80(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   1110 <sleep@plt>
mov    %ebx,%eax
mov    $0xaaaaaaab,%ecx
imul   %rax,%rcx
shr    $0x21,%rcx
lea    (%rcx,%rcx,2),%eax
mov    %ebx,%edx
sub    %eax,%edx
add    (%r15),%edx
mov    %edx,(%r15)
lea    0xc6f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1070 <sem_post@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/null\00"
@.str.1 = [19 x i8] c"shmkey for p = %d\0A\00"
@IPC_CREAT = global i32 0
@.str.2 = [8 x i8] c"shmget\0A\00"
@.str.3 = [38 x i8] c"p=%d is allocated in shared memory.\0A\0A\00"
@.str.4 = [40 x i8] c"How many children do you want to fork?\0A\00"
@.str.5 = [13 x i8] c"Fork count: \00"
@.str.6 = [3 x i8] c"%u\00"
@.str.7 = [45 x i8] c"What do you want the semaphore value to be?\0A\00"
@.str.8 = [18 x i8] c"Semaphore value: \00"
@.str.9 = [5 x i8] c"pSem\00"
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str.10 = [26 x i8] c"semaphores initialized.\0A\0A\00"
@.str.11 = [13 x i8] c"Fork error.\0A\00"
@errno = global i64 0
@ECHILD = global i64 0
@.str.12 = [36 x i8] c"\0AParent: All children have exited.\0A\00"
@IPC_RMID = global i32 0
@.str.13 = [37 x i8] c" Child(%d) is in critical section.\0A\00"
@.str.14 = [33 x i8] c" Child(%d) new value of *p=%d.\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 i64
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 @ftok(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 5)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %7
%18 = load i32, i32* @IPC_CREAT
%19 = or i32 420, %18
%20 = call i32 @shmget(i32 %17, i32 4, i32 %19)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %2
%24 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = load i32, i32* %8
%28 = call i64 @shmat(i32 %27, i32* null, i32 0)
%29 = inttoptr i64 %28 to i32*
store i32* %29, i32** %11
%30 = load i32*, i32** %11
store i32 0, i32* %30
%31 = load i32*, i32** %11
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %12)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0))
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
%39 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %13)
%40 = load i32, i32* @O_CREAT
%41 = load i32, i32* @O_EXCL
%42 = or i32 %40, %41
%43 = load i32, i32* %13
%44 = call i32* @sem_open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %42, i32 420, i32 %43)
store i32* %44, i32** %9
%45 = call i32 @sem_unlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %6
br label %47
47: ; preds = %63, %26
%48 = load i32, i32* %6
%49 = load i32, i32* %12
%50 = icmp ult i32 %48, %49
br i1 %50, label %51, label %66
51: ; preds = %47
%52 = call i64 (...) @fork()
store i64 %52, i64* %10
%53 = load i64, i64* %10
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %51
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0))
br label %62
57: ; preds = %51
%58 = load i64, i64* %10
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %57
br label %66
61: ; preds = %57
br label %62
62: ; preds = %61, %55
br label %63
63: ; preds = %62
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
br label %47
66: ; preds = %60, %47
%67 = load i64, i64* %10
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %89
69: ; preds = %66
br label %70
70: ; preds = %78, %69
%71 = call i64 @waitpid(i32 -1, i32* null, i32 0)
store i64 %71, i64* %10
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %79
73: ; preds = %70
%74 = load i64, i64* @errno
%75 = load i64, i64* @ECHILD
%76 = icmp eq i64 %74, %75
br i1 %76, label %77, label %78
77: ; preds = %73
br label %79
78: ; preds = %73
br label %70
79: ; preds = %77, %70
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0))
%81 = load i32*, i32** %11
%82 = call i32 @shmdt(i32* %81)
%83 = load i32, i32* %8
%84 = load i32, i32* @IPC_RMID
%85 = call i32 @shmctl(i32 %83, i32 %84, i32 0)
%86 = load i32*, i32** %9
%87 = call i32 @sem_destroy(i32* %86)
%88 = call i32 @exit(i32 0)
unreachable
89: ; preds = %66
%90 = load i32*, i32** %9
%91 = call i32 @sem_wait(i32* %90)
%92 = load i32, i32* %6
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0), i32 %92)
%94 = call i32 @sleep(i32 1)
%95 = load i32, i32* %6
%96 = srem i32 %95, 3
%97 = load i32*, i32** %11
%98 = load i32, i32* %97
%99 = add nsw i32 %98, %96
store i32 %99, i32* %97
%100 = load i32, i32* %6
%101 = load i32*, i32** %11
%102 = load i32, i32* %101
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.14, i64 0, i64 0), i32 %100, i32 %102)
%104 = load i32*, i32** %9
%105 = call i32 @sem_post(i32* %104)
%106 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/null\00"
@.str.1 = [19 x i8] c"shmkey for p = %d\0A\00"
@IPC_CREAT = global i32 0
@.str.2 = [8 x i8] c"shmget\0A\00"
@.str.3 = [38 x i8] c"p=%d is allocated in shared memory.\0A\0A\00"
@.str.5 = [13 x i8] c"Fork count: \00"
@.str.6 = [3 x i8] c"%u\00"
@.str.8 = [18 x i8] c"Semaphore value: \00"
@.str.9 = [5 x i8] c"pSem\00"
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@errno = global i64 0
@ECHILD = global i64 0
@IPC_RMID = global i32 0
@.str.13 = [37 x i8] c" Child(%d) is in critical section.\0A\00"
@.str.14 = [33 x i8] c" Child(%d) new value of *p=%d.\0A\00"
@str = [39 x i8] c"How many children do you want to fork?\00"
@str.15 = [44 x i8] c"What do you want the semaphore value to be?\00"
@str.16 = [25 x i8] c"semaphores initialized.\0A\00"
@str.17 = [35 x i8] c"\0AParent: All children have exited.\00"
@str.18 = [12 x i8] c"Fork error.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 @ftok(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 5)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @IPC_CREAT
%10 = or i32 %9, 420
%11 = tail call i32 @shmget(i32 %7, i32 4, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = tail call i64 @shmat(i32 %11, i32* null, i32 0)
%18 = inttoptr i64 %17 to i32*
store i32 0, i32* %18
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 0)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %3)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.15, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %4)
%26 = load i32, i32* @O_CREAT
%27 = load i32, i32* @O_EXCL
%28 = or i32 %27, %26
%29 = load i32, i32* %4
%30 = call i32* @sem_open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %28, i32 420, i32 %29)
%31 = call i32 @sem_unlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.16, i64 0, i64 0))
%33 = load i32, i32* %3
%34 = icmp eq i32 %33, 0
br i1 %34, label %47, label %35
35: ; preds = %16, %43
%36 = phi i32 [ %44, %43 ], [ 0, %16 ]
%37 = call i64 (...) @fork()
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.18, i64 0, i64 0))
br label %43
41: ; preds = %35
%42 = icmp eq i64 %37, 0
br i1 %42, label %62, label %43
43: ; preds = %39, %41
%44 = add nuw nsw i32 %36, 1
%45 = load i32, i32* %3
%46 = icmp ult i32 %44, %45
br i1 %46, label %35, label %47
47: ; preds = %43, %16
br label %48
48: ; preds = %47, %51
%49 = call i64 @waitpid(i32 -1, i32* null, i32 0)
%50 = icmp eq i64 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %48
%52 = load i64, i64* @errno
%53 = load i64, i64* @ECHILD
%54 = icmp eq i64 %52, %53
br i1 %54, label %55, label %48
55: ; preds = %51, %48
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.17, i64 0, i64 0))
%57 = call i32 @shmdt(i32* %18)
%58 = load i32, i32* @IPC_RMID
%59 = call i32 @shmctl(i32 %11, i32 %58, i32 0)
%60 = call i32 @sem_destroy(i32* %30)
%61 = call i32 @exit(i32 0)
unreachable
62: ; preds = %41
%63 = call i32 @sem_wait(i32* %30)
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0), i32 %36)
%65 = call i32 @sleep(i32 1)
%66 = urem i32 %36, 3
%67 = load i32, i32* %18
%68 = add nsw i32 %67, %66
store i32 %68, i32* %18
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.14, i64 0, i64 0), i32 %36, i32 %68)
%70 = call i32 @sem_post(i32* %30)
%71 = call i32 @exit(i32 0)
unreachable
}