#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 dummy;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
int EINTR;
int /*<<< orphan*/ IPC_PRIVATE;
int S_IRUSR;
int S_IWUSR;
int atoi(char *);
int errno;
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
scalar_t__ getpid();
scalar_t__ getppid();
int init_element(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_error(char *, int);
int r_semop(int, struct sembuf *, int);
int r_wait(int /*<<< orphan*/ *);
int remove_sem(int);
int semget(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ set_sembuf(struct sembuf *, int /*<<< orphan*/, int,
                              int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int, long, long, long);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char buffer[1024];
  char *c;
  pid_t childpid;
  int error, delay, i, n;
  volatile int dummy;
  int semid;
  struct sembuf semwait[1];
  struct sembuf semsignal[1];
  if ((argc != 3) || ((n = atoi(argv[1])) <= 0) ||
      ((delay = atoi(argv[2])) < 0)) {
    fprintf(stderr, "Usage: %s processes delay\n", argv[0]);
    return -1;
  }
  if ((semid = semget(IPC_PRIVATE, 1, (S_IRUSR | S_IWUSR))) == -1) {
    perror("semget failed");
    return -1;
  }
  set_sembuf(semwait, 0, -1, 0);
  set_sembuf(semsignal, 0, 1, 0);
  if (init_element(semid, 0, 1) == -1) {
    perror("initialize failed");
    if (remove_sem(semid) == -1)
      perror("remove sem failed");
    return -1;
  }
  for (i = 1; i < n; i++) {
    if ((childpid = fork()) > 0)
      break;
  }
  snprintf(buffer, 1024, "i: %d process ID: %ld parent ID: %ld child ID: %ld\n",
           i, (long)getpid(), (long)getppid(), (long)childpid);
  c = buffer;
  if (((error = r_semop(semid, semwait, 1)) == -1) && (i > 1)) {
    print_error("child failed to lock semid", error);
    return -1;
  } else if (!error) {
    while (*c != '\0') {
      fputc(*c, stderr);
      c++;
      for (i = 0; i < delay; i++)
        dummy++;
    }
    if ((error = r_semop(semid, semsignal, 1)) == -1)
      print_error("failed to unlock semid", error);
  }
  if ((r_wait(NULL) == -1) && (errno != EINTR))
    print_error("failed to wait", errno);
  if ((i == 1) && ((error = remove_sem(semid)) == -1)) {
    print_error("failed to clean up", error);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    124b <main+0x5b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x430(%rbp)
cmp    $0x0,%eax
jle    124b <main+0x5b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x428(%rbp)
cmp    $0x0,%eax
jge    1273 <main+0x83>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd9e(%rip),%rsi
call   10b0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15b1 <main+0x3c1>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
mov    0x2d35(%rip),%rax
mov    (%rax),%edx
mov    0x2d54(%rip),%rax
or     (%rax),%edx
mov    $0x1,%esi
call   1050 <semget@plt>
mov    %eax,-0x438(%rbp)
cmp    $0xffffffff,%eax
jne    12bf <main+0xcf>
lea    0xd6d(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15b1 <main+0x3c1>
lea    -0x440(%rbp),%rdi
xor    %ecx,%ecx
mov    $0xffffffff,%edx
mov    %ecx,%esi
call   1030 <set_sembuf@plt>
lea    -0x448(%rbp),%rdi
xor    %ecx,%ecx
mov    $0x1,%edx
mov    %ecx,%esi
call   1030 <set_sembuf@plt>
mov    -0x438(%rbp),%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1080 <init_element@plt>
cmp    $0xffffffff,%eax
jne    133c <main+0x14c>
lea    0xd1e(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x438(%rbp),%edi
call   1110 <remove_sem@plt>
cmp    $0xffffffff,%eax
jne    1330 <main+0x140>
lea    0xd10(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15b1 <main+0x3c1>
movl   $0x1,-0x42c(%rbp)
mov    -0x42c(%rbp),%eax
cmp    -0x430(%rbp),%eax
jge    138e <main+0x19e>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %rax,-0x420(%rbp)
cmp    $0x0,%rax
jle    1375 <main+0x185>
jmp    138e <main+0x19e>
jmp    137a <main+0x18a>
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
jmp    1346 <main+0x156>
lea    -0x410(%rbp),%rax
mov    %rax,-0x460(%rbp)
mov    -0x42c(%rbp),%eax
mov    %eax,-0x454(%rbp)
mov    $0x0,%al
call   1070 <getpid@plt>
mov    %rax,-0x450(%rbp)
mov    $0x0,%al
call   10e0 <getppid@plt>
mov    -0x460(%rbp),%rdi
mov    -0x454(%rbp),%ecx
mov    -0x450(%rbp),%r8
mov    %rax,%r9
mov    -0x420(%rbp),%rax
mov    $0x400,%esi
lea    0xc66(%rip),%rdx
mov    %rax,(%rsp)
call   1090 <snprintf@plt>
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
mov    -0x438(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x1,%edx
call   10f0 <r_semop@plt>
mov    %eax,-0x424(%rbp)
cmp    $0xffffffff,%eax
jne    144f <main+0x25f>
cmpl   $0x1,-0x42c(%rbp)
jle    144f <main+0x25f>
mov    -0x424(%rbp),%esi
lea    0xc43(%rip),%rdi
call   1060 <print_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15b1 <main+0x3c1>
cmpl   $0x0,-0x424(%rbp)
jne    1521 <main+0x331>
jmp    1461 <main+0x271>
mov    -0x418(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     14e4 <main+0x2f4>
mov    -0x418(%rbp),%rax
mov    (%rax),%al
mov    0x2b4c(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   10a0 <fputc@plt>
mov    -0x418(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x418(%rbp)
movl   $0x0,-0x42c(%rbp)
mov    -0x42c(%rbp),%eax
cmp    -0x428(%rbp),%eax
jge    14df <main+0x2ef>
mov    -0x434(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x434(%rbp)
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
jmp    14aa <main+0x2ba>
jmp    1461 <main+0x271>
mov    -0x438(%rbp),%edi
lea    -0x448(%rbp),%rsi
mov    $0x1,%edx
call   10f0 <r_semop@plt>
mov    %eax,-0x424(%rbp)
cmp    $0xffffffff,%eax
jne    151c <main+0x32c>
mov    -0x424(%rbp),%esi
lea    0xb85(%rip),%rdi
call   1060 <print_error@plt>
jmp    1521 <main+0x331>
jmp    1526 <main+0x336>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <r_wait@plt>
cmp    $0xffffffff,%eax
jne    1565 <main+0x375>
mov    0x2a89(%rip),%rax
mov    (%rax),%eax
mov    0x2a78(%rip),%rcx
cmp    (%rcx),%eax
je     1565 <main+0x375>
mov    0x2a71(%rip),%rax
mov    (%rax),%esi
lea    0xb53(%rip),%rdi
call   1060 <print_error@plt>
cmpl   $0x1,-0x42c(%rbp)
jne    15aa <main+0x3ba>
mov    -0x438(%rbp),%edi
call   1110 <remove_sem@plt>
mov    %eax,-0x424(%rbp)
cmp    $0xffffffff,%eax
jne    15aa <main+0x3ba>
mov    -0x424(%rbp),%esi
lea    0xb29(%rip),%rdi
call   1060 <print_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15b1 <main+0x3c1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1345 <main+0x155>
mov    0x8(%rbx),%rdi
call   10d0 <atoi@plt>
test   %eax,%eax
jle    1345 <main+0x155>
mov    %eax,%r13d
mov    0x10(%rbx),%rdi
call   10d0 <atoi@plt>
test   %eax,%eax
js     1345 <main+0x155>
mov    %eax,%r15d
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
mov    0x2d73(%rip),%rax
mov    0x2d94(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    $0x1,%esi
call   1050 <semget@plt>
cmp    $0xffffffff,%eax
je     1497 <main+0x2a7>
mov    %eax,%r14d
lea    0x18(%rsp),%rdi
mov    $0xffffffff,%r12d
xor    %esi,%esi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1030 <set_sembuf@plt>
lea    0x10(%rsp),%rdi
mov    $0x1,%ebp
xor    %esi,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <set_sembuf@plt>
mov    %r14d,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1080 <init_element@plt>
cmp    $0xffffffff,%eax
je     14a8 <main+0x2b8>
cmp    $0x2,%r13d
jb     12da <main+0xea>
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1100 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
jg     12da <main+0xea>
add    $0x1,%ebp
cmp    %ebp,%r13d
jne    12c0 <main+0xd0>
mov    %r13d,%ebp
xor    %eax,%eax
call   1070 <getpid@plt>
mov    %rax,%r12
xor    %eax,%eax
call   10e0 <getppid@plt>
mov    %rbx,(%rsp)
lea    0xd57(%rip),%rdx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %ebp,%ecx
mov    %r12,%r8
mov    %rax,%r9
call   1090 <snprintf@plt>
lea    0x18(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   10f0 <r_semop@plt>
cmp    $0xffffffff,%eax
jne    1378 <main+0x188>
cmp    $0x2,%ebp
jb     1378 <main+0x188>
lea    0xd4e(%rip),%rdi
mov    $0xffffffff,%r12d
mov    $0xffffffff,%esi
call   1060 <print_error@plt>
jmp    1363 <main+0x173>
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xca8(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %eax,%eax
jne    1442 <main+0x252>
mov    0x20(%rsp),%al
test   %al,%al
je     141a <main+0x22a>
mov    %r14d,0x1c(%rsp)
lea    -0x1(%r15),%r12d
mov    %r15d,%ebp
and    $0x3,%ebp
mov    %r15d,%r13d
and    $0xfffffffc,%r13d
mov    0x2c27(%rip),%r14
jmp    13b6 <main+0x1c6>
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%al
test   %al,%al
je     140c <main+0x21c>
mov    (%r14),%esi
movsbl %al,%edi
call   10a0 <fputc@plt>
add    $0x1,%rbx
test   %r15d,%r15d
jle    13b0 <main+0x1c0>
cmp    $0x3,%r12d
jb     13f9 <main+0x209>
mov    %r13d,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
addl   $0x1,0xc(%rsp)
addl   $0x1,0xc(%rsp)
addl   $0x1,0xc(%rsp)
addl   $0x1,0xc(%rsp)
add    $0xfffffffc,%eax
jne    13e0 <main+0x1f0>
test   %ebp,%ebp
je     13b0 <main+0x1c0>
mov    %ebp,%eax
nop
addl   $0x1,0xc(%rsp)
add    $0xffffffff,%eax
jne    1400 <main+0x210>
jmp    13b0 <main+0x1c0>
xor    %ebp,%ebp
test   %r15d,%r15d
cmovg  %r15d,%ebp
mov    0x1c(%rsp),%r14d
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   10f0 <r_semop@plt>
cmp    $0xffffffff,%eax
jne    1442 <main+0x252>
lea    0xc64(%rip),%rdi
mov    $0xffffffff,%esi
call   1060 <print_error@plt>
xor    %r12d,%r12d
xor    %edi,%edi
call   1040 <r_wait@plt>
cmp    $0xffffffff,%eax
jne    1471 <main+0x281>
mov    0x2b70(%rip),%rax
mov    (%rax),%esi
mov    0x2b5f(%rip),%rax
cmp    (%rax),%esi
je     1471 <main+0x281>
lea    0xc47(%rip),%rdi
call   1060 <print_error@plt>
cmp    $0x1,%ebp
jne    1363 <main+0x173>
mov    %r14d,%edi
call   1110 <remove_sem@plt>
cmp    $0xffffffff,%eax
jne    1363 <main+0x173>
lea    0xc30(%rip),%rdi
jmp    1333 <main+0x143>
lea    0xb7d(%rip),%rdi
call   10c0 <perror@plt>
jmp    135d <main+0x16d>
lea    0xb7a(%rip),%rdi
call   10c0 <perror@plt>
mov    %r14d,%edi
call   1110 <remove_sem@plt>
cmp    $0xffffffff,%eax
jne    1363 <main+0x173>
lea    0xb6f(%rip),%rdi
call   10c0 <perror@plt>
jmp    1363 <main+0x173>

LLVM IR (-O0):
%struct.sembuf = type { i32 }
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s processes delay\0A\00"
@IPC_PRIVATE = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [14 x i8] c"semget failed\00"
@.str.2 = [18 x i8] c"initialize failed\00"
@.str.3 = [18 x i8] c"remove sem failed\00"
@.str.4 = [52 x i8] c"i: %d process ID: %ld parent ID: %ld child ID: %ld\0A\00"
@.str.5 = [27 x i8] c"child failed to lock semid\00"
@.str.6 = [23 x i8] c"failed to unlock semid\00"
@errno = global i32 0
@EINTR = global i32 0
@.str.7 = [15 x i8] c"failed to wait\00"
@.str.8 = [19 x i8] c"failed to clean up\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [1 x %struct.sembuf]
%16 = alloca [1 x %struct.sembuf]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 3
br i1 %18, label %31, label %19
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %12
%24 = icmp sle i32 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %19
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %10
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %25, %19, %2
%32 = load i32, i32* @stderr
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %35)
store i32 -1, i32* %3
br label %151
37: ; preds = %25
%38 = load i32, i32* @IPC_PRIVATE
%39 = load i32, i32* @S_IRUSR
%40 = load i32, i32* @S_IWUSR
%41 = or i32 %39, %40
%42 = call i32 @semget(i32 %38, i32 1, i32 %41)
store i32 %42, i32* %14
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %37
%45 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %151
46: ; preds = %37
%47 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %15, i64 0, i64 0
%48 = call i32 @set_sembuf(%struct.sembuf* %47, i32 0, i32 -1, i32 0)
%49 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %16, i64 0, i64 0
%50 = call i32 @set_sembuf(%struct.sembuf* %49, i32 0, i32 1, i32 0)
%51 = load i32, i32* %14
%52 = call i32 @init_element(i32 %51, i32 0, i32 1)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %62
54: ; preds = %46
%55 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%56 = load i32, i32* %14
%57 = call i32 @remove_sem(i32 %56)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %61
59: ; preds = %54
%60 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %61
61: ; preds = %59, %54
store i32 -1, i32* %3
br label %151
62: ; preds = %46
store i32 1, i32* %11
br label %63
63: ; preds = %72, %62
%64 = load i32, i32* %11
%65 = load i32, i32* %12
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %75
67: ; preds = %63
%68 = call i64 (...) @fork()
store i64 %68, i64* %8
%69 = icmp sgt i64 %68, 0
br i1 %69, label %70, label %71
70: ; preds = %67
br label %75
71: ; preds = %67
br label %72
72: ; preds = %71
%73 = load i32, i32* %11
%74 = add nsw i32 %73, 1
store i32 %74, i32* %11
br label %63
75: ; preds = %70, %63
%76 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%77 = load i32, i32* %11
%78 = call i64 (...) @getpid()
%79 = call i64 (...) @getppid()
%80 = load i64, i64* %8
%81 = call i32 @snprintf(i8* %76, i32 1024, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %77, i64 %78, i64 %79, i64 %80)
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
store i8* %82, i8** %7
%83 = load i32, i32* %14
%84 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %15, i64 0, i64 0
%85 = call i32 @r_semop(i32 %83, %struct.sembuf* %84, i32 1)
store i32 %85, i32* %9
%86 = icmp eq i32 %85, -1
br i1 %86, label %87, label %93
87: ; preds = %75
%88 = load i32, i32* %11
%89 = icmp sgt i32 %88, 1
br i1 %89, label %90, label %93
90: ; preds = %87
%91 = load i32, i32* %9
%92 = call i32 @print_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %91)
store i32 -1, i32* %3
br label %151
93: ; preds = %87, %75
%94 = load i32, i32* %9
%95 = icmp ne i32 %94, 0
br i1 %95, label %129, label %96
96: ; preds = %93
br label %97
97: ; preds = %119, %96
%98 = load i8*, i8** %7
%99 = load i8, i8* %98
%100 = sext i8 %99 to i32
%101 = icmp ne i32 %100, 0
br i1 %101, label %102, label %120
102: ; preds = %97
%103 = load i8*, i8** %7
%104 = load i8, i8* %103
%105 = load i32, i32* @stderr
%106 = call i32 @fputc(i8 signext %104, i32 %105)
%107 = load i8*, i8** %7
%108 = getelementptr inbounds i8, i8* %107, i32 1
store i8* %108, i8** %7
store i32 0, i32* %11
br label %109
109: ; preds = %116, %102
%110 = load i32, i32* %11
%111 = load i32, i32* %10
%112 = icmp slt i32 %110, %111
br i1 %112, label %113, label %119
113: ; preds = %109
%114 = load volatile i32, i32* %13
%115 = add nsw i32 %114, 1
store volatile i32 %115, i32* %13
br label %116
116: ; preds = %113
%117 = load i32, i32* %11
%118 = add nsw i32 %117, 1
store i32 %118, i32* %11
br label %109
119: ; preds = %109
br label %97
120: ; preds = %97
%121 = load i32, i32* %14
%122 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %16, i64 0, i64 0
%123 = call i32 @r_semop(i32 %121, %struct.sembuf* %122, i32 1)
store i32 %123, i32* %9
%124 = icmp eq i32 %123, -1
br i1 %124, label %125, label %128
125: ; preds = %120
%126 = load i32, i32* %9
%127 = call i32 @print_error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %126)
br label %128
128: ; preds = %125, %120
br label %129
129: ; preds = %128, %93
br label %130
130: ; preds = %129
%131 = call i32 @r_wait(i32* null)
%132 = icmp eq i32 %131, -1
br i1 %132, label %133, label %140
133: ; preds = %130
%134 = load i32, i32* @errno
%135 = load i32, i32* @EINTR
%136 = icmp ne i32 %134, %135
br i1 %136, label %137, label %140
137: ; preds = %133
%138 = load i32, i32* @errno
%139 = call i32 @print_error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %138)
br label %140
140: ; preds = %137, %133, %130
%141 = load i32, i32* %11
%142 = icmp eq i32 %141, 1
br i1 %142, label %143, label %150
143: ; preds = %140
%144 = load i32, i32* %14
%145 = call i32 @remove_sem(i32 %144)
store i32 %145, i32* %9
%146 = icmp eq i32 %145, -1
br i1 %146, label %147, label %150
147: ; preds = %143
%148 = load i32, i32* %9
%149 = call i32 @print_error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i32 %148)
store i32 -1, i32* %3
br label %151
150: ; preds = %143, %140
store i32 0, i32* %3
br label %151
151: ; preds = %150, %147, %90, %61, %44, %31
%152 = load i32, i32* %3
ret i32 %152
}

LLVM IR (-O2):
%struct.sembuf = type { i32 }
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s processes delay\0A\00"
@IPC_PRIVATE = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [14 x i8] c"semget failed\00"
@.str.2 = [18 x i8] c"initialize failed\00"
@.str.3 = [18 x i8] c"remove sem failed\00"
@.str.4 = [52 x i8] c"i: %d process ID: %ld parent ID: %ld child ID: %ld\0A\00"
@.str.5 = [27 x i8] c"child failed to lock semid\00"
@.str.6 = [23 x i8] c"failed to unlock semid\00"
@errno = global i32 0
@EINTR = global i32 0
@.str.7 = [15 x i8] c"failed to wait\00"
@.str.8 = [19 x i8] c"failed to clean up\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca [1 x %struct.sembuf]
%6 = alloca [1 x %struct.sembuf]
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = bitcast [1 x %struct.sembuf]* %5 to i8*
%10 = bitcast [1 x %struct.sembuf]* %6 to i8*
%11 = icmp eq i32 %0, 3
br i1 %11, label %12, label %22
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = icmp slt i32 %15, 1
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %17, %12, %2
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %1
%25 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %135
26: ; preds = %17
%27 = load i32, i32* @IPC_PRIVATE
%28 = load i32, i32* @S_IRUSR
%29 = load i32, i32* @S_IWUSR
%30 = or i32 %29, %28
%31 = tail call i32 @semget(i32 %27, i32 1, i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %135
35: ; preds = %26
%36 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %5, i64 0, i64 0
%37 = call i32 @set_sembuf(%struct.sembuf* %36, i32 0, i32 -1, i32 0)
%38 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %6, i64 0, i64 0
%39 = call i32 @set_sembuf(%struct.sembuf* %38, i32 0, i32 1, i32 0)
%40 = call i32 @init_element(i32 %31, i32 0, i32 1)
%41 = icmp eq i32 %40, -1
br i1 %41, label %44, label %42
42: ; preds = %35
%43 = icmp ugt i32 %15, 1
br i1 %43, label %50, label %57
44: ; preds = %35
%45 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @remove_sem(i32 %31)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %135
48: ; preds = %44
%49 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %135
50: ; preds = %42, %54
%51 = phi i32 [ %55, %54 ], [ 1, %42 ]
%52 = call i64 (...) @fork()
%53 = icmp sgt i64 %52, 0
br i1 %53, label %57, label %54
54: ; preds = %50
%55 = add nuw nsw i32 %51, 1
%56 = icmp eq i32 %55, %15
br i1 %56, label %57, label %50
57: ; preds = %54, %50, %42
%58 = phi i32 [ 1, %42 ], [ %51, %50 ], [ %15, %54 ]
%59 = phi i64 [ undef, %42 ], [ %52, %50 ], [ %52, %54 ]
%60 = call i64 (...) @getpid()
%61 = call i64 (...) @getppid()
%62 = call i32 @snprintf(i8* %7, i32 1024, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %58, i64 %60, i64 %61, i64 %59)
%63 = call i32 @r_semop(i32 %31, %struct.sembuf* %36, i32 1)
%64 = icmp eq i32 %63, -1
%65 = icmp ugt i32 %58, 1
%66 = select i1 %64, i1 %65, i1 false
br i1 %66, label %67, label %69
67: ; preds = %57
%68 = call i32 @print_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 -1)
br label %135
69: ; preds = %57
%70 = icmp eq i32 %63, 0
br i1 %70, label %71, label %118
71: ; preds = %69
%72 = load i8, i8* %7
%73 = icmp eq i8 %72, 0
br i1 %73, label %112, label %74
74: ; preds = %71
%75 = icmp sgt i32 %20, 0
%76 = add i32 %20, -1
%77 = and i32 %20, 3
%78 = icmp ult i32 %76, 3
%79 = and i32 %20, -4
%80 = icmp eq i32 %77, 0
br label %91
81: ; preds = %98, %97
br i1 %80, label %88, label %82
82: ; preds = %81, %82
%83 = phi i32 [ %86, %82 ], [ 0, %81 ]
%84 = load volatile i32, i32* %4
%85 = add nsw i32 %84, 1
store volatile i32 %85, i32* %4
%86 = add i32 %83, 1
%87 = icmp eq i32 %86, %77
br i1 %87, label %88, label %82
88: ; preds = %81, %82, %91
%89 = load i8, i8* %96
%90 = icmp eq i8 %89, 0
br i1 %90, label %110, label %91
91: ; preds = %74, %88
%92 = phi i8 [ %72, %74 ], [ %89, %88 ]
%93 = phi i8* [ %7, %74 ], [ %96, %88 ]
%94 = load i32, i32* @stderr
%95 = call i32 @fputc(i8 signext %92, i32 %94)
%96 = getelementptr inbounds i8, i8* %93, i64 1
br i1 %75, label %97, label %88
97: ; preds = %91
br i1 %78, label %81, label %98
98: ; preds = %97, %98
%99 = phi i32 [ %108, %98 ], [ 0, %97 ]
%100 = load volatile i32, i32* %4
%101 = add nsw i32 %100, 1
store volatile i32 %101, i32* %4
%102 = load volatile i32, i32* %4
%103 = add nsw i32 %102, 1
store volatile i32 %103, i32* %4
%104 = load volatile i32, i32* %4
%105 = add nsw i32 %104, 1
store volatile i32 %105, i32* %4
%106 = load volatile i32, i32* %4
%107 = add nsw i32 %106, 1
store volatile i32 %107, i32* %4
%108 = add i32 %99, 4
%109 = icmp eq i32 %108, %79
br i1 %109, label %81, label %98
110: ; preds = %88
%111 = call i32 @llvm.smax.i32(i32 %20, i32 0)
br label %112
112: ; preds = %110, %71
%113 = phi i32 [ %58, %71 ], [ %111, %110 ]
%114 = call i32 @r_semop(i32 %31, %struct.sembuf* %38, i32 1)
%115 = icmp eq i32 %114, -1
br i1 %115, label %116, label %118
116: ; preds = %112
%117 = call i32 @print_error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 -1)
br label %118
118: ; preds = %69, %116, %112
%119 = phi i32 [ %58, %69 ], [ %113, %116 ], [ %113, %112 ]
%120 = call i32 @r_wait(i32* null)
%121 = icmp eq i32 %120, -1
br i1 %121, label %122, label %128
122: ; preds = %118
%123 = load i32, i32* @errno
%124 = load i32, i32* @EINTR
%125 = icmp eq i32 %123, %124
br i1 %125, label %128, label %126
126: ; preds = %122
%127 = call i32 @print_error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %123)
br label %128
128: ; preds = %126, %122, %118
%129 = icmp eq i32 %119, 1
br i1 %129, label %130, label %135
130: ; preds = %128
%131 = call i32 @remove_sem(i32 %31)
%132 = icmp eq i32 %131, -1
br i1 %132, label %133, label %135
133: ; preds = %130
%134 = call i32 @print_error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i32 -1)
br label %135
135: ; preds = %128, %130, %44, %48, %133, %67, %33, %22
%136 = phi i32 [ -1, %22 ], [ -1, %33 ], [ -1, %67 ], [ -1, %133 ], [ -1, %48 ], [ -1, %44 ], [ 0, %130 ], [ 0, %128 ]
ret i32 %136
}