#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 */
struct sembuf {
  int sem_num;
  int sem_op;
  scalar_t__ sem_flg;
};

/* Variables and functions */
int IPC_CREAT;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ SETVAL;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int semctl(int, int, int /*<<< orphan*/, ...);
int semget(int, int, int);
int semop(int, struct sembuf *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
scalar_t__ wait(int /*<<< orphan*/);
int main() {
  int sem;
  struct sembuf op;
  op.sem_flg = 0;
  if ((sem = semget(20, 2, 0666 | IPC_CREAT)) == -1) {
    perror("[semget]");
  }
  if (semctl(sem, 0, SETVAL, 2) == -1) {
    perror("[semctl -- SEM_0]");
  }
  if (semctl(sem, 1, SETVAL, 2) == -1) {
    perror("[semctl -- SEM_1]");
  }
  if (fork() == 0) {
    printf("process 1\n");
    fflush(stdout);
    sleep(2);
    op.sem_num = 0;
    op.sem_op = -1;
    if (semop(sem, &op, 1) == -1) {
      perror("[process1 -- down]");
    }
    exit(0);
  }
  if (fork() == 0) {
    printf("process 2\n");
    fflush(stdout);
    sleep(2);
    op.sem_num = 0;
    op.sem_op = -1;
    if (semop(sem, &op, 1) == -1) {
      perror("[process2 -- down]");
    }
    exit(0);
  }
  if (fork() == 0) {
    op.sem_num = 0;
    op.sem_op = 0;
    if (semop(sem, &op, 1) == -1) {
      perror("[process3 -- zero]");
    }
    printf("process 3\n");
    fflush(stdout);
    sleep(1);
    op.sem_num = 1;
    op.sem_op = -1;
    if (semop(sem, &op, 1) == -1) {
      perror("[process3 -- down]");
    }
    exit(0);
  }
  if (fork() == 0) {
    op.sem_num = 0;
    op.sem_op = 0;
    if (semop(sem, &op, 1) == -1) {
      perror("[process4 -- zero]");
    }
    printf("process 4\n");
    fflush(stdout);
    sleep(1);
    op.sem_num = 1;
    op.sem_op = -1;
    if (semop(sem, &op, 1) == -1) {
      perror("[process4 -- down]");
    }
    exit(0);
  }
  if (fork() == 0) {
    op.sem_num = 1;
    op.sem_op = 0;
    if (semop(sem, &op, 1) == -1) {
      perror("[process5 -- zero]");
    }
    printf("process 5\n");
    fflush(stdout);
    exit(0);
  }
  while (wait(0) >= 0)
    ;
  semctl(sem, 0, IPC_RMID);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x14,%edi
mov    $0x2,%esi
call   1030 <semget@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11ed <main+0x4d>
lea    0xe18(%rip),%rdi
call   1060 <perror@plt>
mov    -0x8(%rbp),%edi
mov    0x2dd1(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
mov    $0x2,%ecx
mov    $0x0,%al
call   1070 <semctl@plt>
cmp    $0xffffffff,%eax
jne    121c <main+0x7c>
lea    0xdf2(%rip),%rdi
call   1060 <perror@plt>
mov    -0x8(%rbp),%edi
mov    0x2da2(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
mov    $0x2,%ecx
mov    $0x0,%al
call   1070 <semctl@plt>
cmp    $0xffffffff,%eax
jne    124e <main+0xae>
lea    0xdd2(%rip),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
cmp    $0x0,%rax
jne    12be <main+0x11e>
lea    0xdc7(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x2,%edi
call   10a0 <sleep@plt>
movl   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1080 <semop@plt>
cmp    $0xffffffff,%eax
jne    12b7 <main+0x117>
lea    0xd86(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
cmp    $0x0,%rax
jne    132e <main+0x18e>
lea    0xd75(%rip),%rdi
call   1040 <printf@plt>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x2,%edi
call   10a0 <sleep@plt>
movl   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1080 <semop@plt>
cmp    $0xffffffff,%eax
jne    1327 <main+0x187>
lea    0xd34(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
cmp    $0x0,%rax
jne    13d2 <main+0x232>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1080 <semop@plt>
cmp    $0xffffffff,%eax
jne    1373 <main+0x1d3>
lea    0xcfb(%rip),%rdi
call   1060 <perror@plt>
lea    0xd02(%rip),%rdi
call   1040 <printf@plt>
mov    0x2c52(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
movl   $0x1,-0x18(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1080 <semop@plt>
cmp    $0xffffffff,%eax
jne    13cb <main+0x22b>
lea    0xcc1(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
cmp    $0x0,%rax
jne    1476 <main+0x2d6>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1080 <semop@plt>
cmp    $0xffffffff,%eax
jne    1417 <main+0x277>
lea    0xc88(%rip),%rdi
call   1060 <perror@plt>
lea    0xc8f(%rip),%rdi
call   1040 <printf@plt>
mov    0x2bae(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
movl   $0x1,-0x18(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1080 <semop@plt>
cmp    $0xffffffff,%eax
jne    146f <main+0x2cf>
lea    0xc4e(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
cmp    $0x0,%rax
jne    14dc <main+0x33c>
movl   $0x1,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1080 <semop@plt>
cmp    $0xffffffff,%eax
jne    14bb <main+0x31b>
lea    0xc15(%rip),%rdi
call   1060 <perror@plt>
lea    0xc1c(%rip),%rdi
call   1040 <printf@plt>
mov    0x2b0a(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    14e1 <main+0x341>
xor    %edi,%edi
call   10b0 <wait@plt>
cmp    $0x0,%rax
jl     14f7 <main+0x357>
jmp    14e1 <main+0x341>
mov    -0x8(%rbp),%edi
mov    0x2adf(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
mov    $0x0,%al
call   1070 <semctl@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
mov    0x2e1a(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0x14,%edi
mov    $0x2,%esi
call   1030 <semget@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11df <main+0x3f>
lea    0xe26(%rip),%rdi
call   1060 <perror@plt>
mov    0x2de2(%rip),%rbx
mov    (%rbx),%edx
mov    %ebp,%edi
xor    %esi,%esi
mov    $0x2,%ecx
xor    %eax,%eax
call   1070 <semctl@plt>
cmp    $0xffffffff,%eax
jne    1209 <main+0x69>
lea    0xe05(%rip),%rdi
call   1060 <perror@plt>
mov    (%rbx),%edx
mov    %ebp,%edi
mov    $0x1,%esi
mov    $0x2,%ecx
xor    %eax,%eax
call   1070 <semctl@plt>
cmp    $0xffffffff,%eax
jne    122f <main+0x8f>
lea    0xdf1(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
jne    1294 <main+0xf4>
lea    0xe98(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x2,%edi
call   10a0 <sleep@plt>
movabs $0xffffffff00000000,%rax
ff ff ff
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1080 <semop@plt>
cmp    $0xffffffff,%eax
jne    141d <main+0x27d>
lea    0xd9e(%rip),%rdi
jmp    1418 <main+0x278>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
jne    12f9 <main+0x159>
lea    0xe29(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x2,%edi
call   10a0 <sleep@plt>
movabs $0xffffffff00000000,%rax
ff ff ff
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1080 <semop@plt>
cmp    $0xffffffff,%eax
jne    141d <main+0x27d>
lea    0xd4c(%rip),%rdi
jmp    1418 <main+0x278>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
jne    138d <main+0x1ed>
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1080 <semop@plt>
cmp    $0xffffffff,%eax
jne    1334 <main+0x194>
lea    0xd24(%rip),%rdi
call   1060 <perror@plt>
lea    0xd8b(%rip),%rdi
call   1040 <puts@plt>
mov    0x2c91(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
movabs $0xffffffff00000001,%rax
ff ff ff
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1080 <semop@plt>
cmp    $0xffffffff,%eax
jne    141d <main+0x27d>
lea    0xcde(%rip),%rdi
jmp    1418 <main+0x278>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
jne    1424 <main+0x284>
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1080 <semop@plt>
cmp    $0xffffffff,%eax
jne    13c8 <main+0x228>
lea    0xcb6(%rip),%rdi
call   1060 <perror@plt>
lea    0xced(%rip),%rdi
call   1040 <puts@plt>
mov    0x2bfd(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
movabs $0xffffffff00000001,%rax
ff ff ff
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1080 <semop@plt>
cmp    $0xffffffff,%eax
jne    141d <main+0x27d>
lea    0xc74(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1090 <exit@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
jne    1480 <main+0x2e0>
movq   $0x1,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1080 <semop@plt>
cmp    $0xffffffff,%eax
jne    145b <main+0x2bb>
lea    0xc49(%rip),%rdi
call   1060 <perror@plt>
lea    0xc50(%rip),%rdi
call   1040 <puts@plt>
mov    0x2b6a(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
xor    %edi,%edi
call   1090 <exit@plt>
nopl   0x0(%rax)
xor    %edi,%edi
call   10b0 <wait@plt>
test   %rax,%rax
jns    1480 <main+0x2e0>
mov    0x2b4d(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1070 <semctl@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sembuf = type { i32, i32, i64 }
@IPC_CREAT = global i32 0
@.str = [9 x i8] c"[semget]\00"
@SETVAL = global i32 0
@.str.1 = [18 x i8] c"[semctl -- SEM_0]\00"
@.str.2 = [18 x i8] c"[semctl -- SEM_1]\00"
@.str.3 = [11 x i8] c"process 1\0A\00"
@stdout = global i32 0
@.str.4 = [19 x i8] c"[process1 -- down]\00"
@.str.5 = [11 x i8] c"process 2\0A\00"
@.str.6 = [19 x i8] c"[process2 -- down]\00"
@.str.7 = [19 x i8] c"[process3 -- zero]\00"
@.str.8 = [11 x i8] c"process 3\0A\00"
@.str.9 = [19 x i8] c"[process3 -- down]\00"
@.str.10 = [19 x i8] c"[process4 -- zero]\00"
@.str.11 = [11 x i8] c"process 4\0A\00"
@.str.12 = [19 x i8] c"[process4 -- down]\00"
@.str.13 = [19 x i8] c"[process5 -- zero]\00"
@.str.14 = [11 x i8] c"process 5\0A\00"
@IPC_RMID = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sembuf
store i32 0, i32* %1
%4 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 2
store i64 0, i64* %4
%5 = load i32, i32* @IPC_CREAT
%6 = or i32 438, %5
%7 = call i32 @semget(i32 20, i32 2, i32 %6)
store i32 %7, i32* %2
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
%12 = load i32, i32* %2
%13 = load i32, i32* @SETVAL
%14 = call i32 (i32, i32, i32, ...) @semctl(i32 %12, i32 0, i32 %13, i32 2)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
%19 = load i32, i32* %2
%20 = load i32, i32* @SETVAL
%21 = call i32 (i32, i32, i32, ...) @semctl(i32 %19, i32 1, i32 %20, i32 2)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %18
%26 = call i64 (...) @fork()
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %42
28: ; preds = %25
%29 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%30 = load i32, i32* @stdout
%31 = call i32 @fflush(i32 %30)
%32 = call i32 @sleep(i32 2)
%33 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 0
store i32 0, i32* %33
%34 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 1
store i32 -1, i32* %34
%35 = load i32, i32* %2
%36 = call i32 @semop(i32 %35, %struct.sembuf* %3, i32 1)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %28
%39 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %38, %28
%41 = call i32 @exit(i32 0)
unreachable
42: ; preds = %25
%43 = call i64 (...) @fork()
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %59
45: ; preds = %42
%46 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%47 = load i32, i32* @stdout
%48 = call i32 @fflush(i32 %47)
%49 = call i32 @sleep(i32 2)
%50 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 0
store i32 0, i32* %50
%51 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 1
store i32 -1, i32* %51
%52 = load i32, i32* %2
%53 = call i32 @semop(i32 %52, %struct.sembuf* %3, i32 1)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %57
55: ; preds = %45
%56 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
br label %57
57: ; preds = %55, %45
%58 = call i32 @exit(i32 0)
unreachable
59: ; preds = %42
%60 = call i64 (...) @fork()
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %84
62: ; preds = %59
%63 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 0
store i32 0, i32* %63
%64 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 1
store i32 0, i32* %64
%65 = load i32, i32* %2
%66 = call i32 @semop(i32 %65, %struct.sembuf* %3, i32 1)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %70
68: ; preds = %62
%69 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %70
70: ; preds = %68, %62
%71 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
%72 = load i32, i32* @stdout
%73 = call i32 @fflush(i32 %72)
%74 = call i32 @sleep(i32 1)
%75 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 0
store i32 1, i32* %75
%76 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 1
store i32 -1, i32* %76
%77 = load i32, i32* %2
%78 = call i32 @semop(i32 %77, %struct.sembuf* %3, i32 1)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %82
80: ; preds = %70
%81 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
br label %82
82: ; preds = %80, %70
%83 = call i32 @exit(i32 0)
unreachable
84: ; preds = %59
%85 = call i64 (...) @fork()
%86 = icmp eq i64 %85, 0
br i1 %86, label %87, label %109
87: ; preds = %84
%88 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 0
store i32 0, i32* %88
%89 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 1
store i32 0, i32* %89
%90 = load i32, i32* %2
%91 = call i32 @semop(i32 %90, %struct.sembuf* %3, i32 1)
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %95
93: ; preds = %87
%94 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
br label %95
95: ; preds = %93, %87
%96 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0))
%97 = load i32, i32* @stdout
%98 = call i32 @fflush(i32 %97)
%99 = call i32 @sleep(i32 1)
%100 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 0
store i32 1, i32* %100
%101 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 1
store i32 -1, i32* %101
%102 = load i32, i32* %2
%103 = call i32 @semop(i32 %102, %struct.sembuf* %3, i32 1)
%104 = icmp eq i32 %103, -1
br i1 %104, label %105, label %107
105: ; preds = %95
%106 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
br label %107
107: ; preds = %105, %95
%108 = call i32 @exit(i32 0)
unreachable
109: ; preds = %84
%110 = call i64 (...) @fork()
%111 = icmp eq i64 %110, 0
br i1 %111, label %112, label %125
112: ; preds = %109
%113 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 0
store i32 1, i32* %113
%114 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 1
store i32 0, i32* %114
%115 = load i32, i32* %2
%116 = call i32 @semop(i32 %115, %struct.sembuf* %3, i32 1)
%117 = icmp eq i32 %116, -1
br i1 %117, label %118, label %120
118: ; preds = %112
%119 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0))
br label %120
120: ; preds = %118, %112
%121 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.14, i64 0, i64 0))
%122 = load i32, i32* @stdout
%123 = call i32 @fflush(i32 %122)
%124 = call i32 @exit(i32 0)
unreachable
125: ; preds = %109
br label %126
126: ; preds = %129, %125
%127 = call i64 @wait(i32 0)
%128 = icmp sge i64 %127, 0
br i1 %128, label %129, label %130
129: ; preds = %126
br label %126
130: ; preds = %126
%131 = load i32, i32* %2
%132 = load i32, i32* @IPC_RMID
%133 = call i32 (i32, i32, i32, ...) @semctl(i32 %131, i32 0, i32 %132)
%134 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i64 }
@IPC_CREAT = global i32 0
@.str = [9 x i8] c"[semget]\00"
@SETVAL = global i32 0
@.str.1 = [18 x i8] c"[semctl -- SEM_0]\00"
@.str.2 = [18 x i8] c"[semctl -- SEM_1]\00"
@stdout = global i32 0
@.str.4 = [19 x i8] c"[process1 -- down]\00"
@.str.6 = [19 x i8] c"[process2 -- down]\00"
@.str.7 = [19 x i8] c"[process3 -- zero]\00"
@.str.9 = [19 x i8] c"[process3 -- down]\00"
@.str.10 = [19 x i8] c"[process4 -- zero]\00"
@.str.12 = [19 x i8] c"[process4 -- down]\00"
@.str.13 = [19 x i8] c"[process5 -- zero]\00"
@IPC_RMID = global i32 0
@str = [10 x i8] c"process 5\00"
@str.15 = [10 x i8] c"process 4\00"
@str.16 = [10 x i8] c"process 3\00"
@str.17 = [10 x i8] c"process 2\00"
@str.18 = [10 x i8] c"process 1\00"
define i32 @main() {
%1 = alloca %struct.sembuf
%2 = bitcast %struct.sembuf* %1 to i8*
%3 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %1, i64 0, i32 2
store i64 0, i64* %3
%4 = load i32, i32* @IPC_CREAT
%5 = or i32 %4, 438
%6 = tail call i32 @semget(i32 20, i32 2, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = load i32, i32* @SETVAL
%12 = tail call i32 (i32, i32, i32, ...) @semctl(i32 %6, i32 0, i32 %11, i32 2)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
%17 = load i32, i32* @SETVAL
%18 = tail call i32 (i32, i32, i32, ...) @semctl(i32 %6, i32 1, i32 %17, i32 2)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
%23 = tail call i64 (...) @fork()
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %38
25: ; preds = %22
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.18, i64 0, i64 0))
%27 = load i32, i32* @stdout
%28 = tail call i32 @fflush(i32 %27)
%29 = tail call i32 @sleep(i32 2)
%30 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %1, i64 0, i32 0
store i32 0, i32* %30
%31 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %1, i64 0, i32 1
store i32 -1, i32* %31
%32 = call i32 @semop(i32 %6, %struct.sembuf* %1, i32 1)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %25
%35 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %34, %25
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %22
%39 = tail call i64 (...) @fork()
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %54
41: ; preds = %38
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.17, i64 0, i64 0))
%43 = load i32, i32* @stdout
%44 = tail call i32 @fflush(i32 %43)
%45 = tail call i32 @sleep(i32 2)
%46 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %1, i64 0, i32 0
store i32 0, i32* %46
%47 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %1, i64 0, i32 1
store i32 -1, i32* %47
%48 = call i32 @semop(i32 %6, %struct.sembuf* %1, i32 1)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %41
%51 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
br label %52
52: ; preds = %50, %41
%53 = call i32 @exit(i32 0)
unreachable
54: ; preds = %38
%55 = tail call i64 (...) @fork()
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %75
57: ; preds = %54
%58 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %1, i64 0, i32 0
store i32 0, i32* %58
%59 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %1, i64 0, i32 1
store i32 0, i32* %59
%60 = call i32 @semop(i32 %6, %struct.sembuf* %1, i32 1)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %64
62: ; preds = %57
%63 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %64
64: ; preds = %62, %57
%65 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.16, i64 0, i64 0))
%66 = load i32, i32* @stdout
%67 = call i32 @fflush(i32 %66)
%68 = call i32 @sleep(i32 1)
store i32 1, i32* %58
store i32 -1, i32* %59
%69 = call i32 @semop(i32 %6, %struct.sembuf* %1, i32 1)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %73
71: ; preds = %64
%72 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
br label %73
73: ; preds = %71, %64
%74 = call i32 @exit(i32 0)
unreachable
75: ; preds = %54
%76 = tail call i64 (...) @fork()
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %96
78: ; preds = %75
%79 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %1, i64 0, i32 0
store i32 0, i32* %79
%80 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %1, i64 0, i32 1
store i32 0, i32* %80
%81 = call i32 @semop(i32 %6, %struct.sembuf* %1, i32 1)
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %85
83: ; preds = %78
%84 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
br label %85
85: ; preds = %83, %78
%86 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.15, i64 0, i64 0))
%87 = load i32, i32* @stdout
%88 = call i32 @fflush(i32 %87)
%89 = call i32 @sleep(i32 1)
store i32 1, i32* %79
store i32 -1, i32* %80
%90 = call i32 @semop(i32 %6, %struct.sembuf* %1, i32 1)
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %94
92: ; preds = %85
%93 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
br label %94
94: ; preds = %92, %85
%95 = call i32 @exit(i32 0)
unreachable
96: ; preds = %75
%97 = tail call i64 (...) @fork()
%98 = icmp eq i64 %97, 0
br i1 %98, label %99, label %111
99: ; preds = %96
%100 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %1, i64 0, i32 0
store i32 1, i32* %100
%101 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %1, i64 0, i32 1
store i32 0, i32* %101
%102 = call i32 @semop(i32 %6, %struct.sembuf* %1, i32 1)
%103 = icmp eq i32 %102, -1
br i1 %103, label %104, label %106
104: ; preds = %99
%105 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0))
br label %106
106: ; preds = %104, %99
%107 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%108 = load i32, i32* @stdout
%109 = call i32 @fflush(i32 %108)
%110 = call i32 @exit(i32 0)
unreachable
111: ; preds = %96, %111
%112 = tail call i64 @wait(i32 0)
%113 = icmp sgt i64 %112, -1
br i1 %113, label %111, label %114
114: ; preds = %111
%115 = load i32, i32* @IPC_RMID
%116 = tail call i32 (i32, i32, i32, ...) @semctl(i32 %6, i32 0, i32 %115)
%117 = tail call i32 @exit(i32 0)
unreachable
}