#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 /*<<< orphan*/ IPC_PRIVATE;
int /*<<< orphan*/ SETVAL;
int fork();
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, int *, int);
int /*<<< orphan*/ scanf(char *, int *);
int semctl(int, int, int /*<<< orphan*/, int /*<<< orphan*/);
int semget(int /*<<< orphan*/, int, int);
int semop(int, struct sembuf *, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, int *, int);
int main() {
  int fd[2];
  pipe(fd);
  int semaphore;
  if ((semaphore = semget(IPC_PRIVATE, 2, 0660)) == -1) {
    perror("ERROR CREATING THE SEMAPHORE");
  }
  if (semctl(semaphore, 0, SETVAL, 0) == -1) {
    perror("ERROR SETTING SEMAPHORE 1 VALUE TO 1");
  }
  if (semctl(semaphore, 1, SETVAL, 0) == -1) {
    perror("ERROR SETTING SEMAPHORE 2 VALUE TO 1");
  }
  struct sembuf sem1_op;
  sem1_op.sem_num = 0;
  sem1_op.sem_op = 1;
  sem1_op.sem_flg = 0;
  struct sembuf sem1_prob;
  sem1_prob.sem_num = 0;
  sem1_prob.sem_op = -1;
  sem1_prob.sem_flg = 0;
  struct sembuf sem2_op;
  sem2_op.sem_num = 1;
  sem2_op.sem_op = 1;
  sem2_op.sem_flg = 0;
  struct sembuf sem2_prob;
  sem2_prob.sem_num = 1;
  sem2_prob.sem_op = -1;
  sem2_prob.sem_flg = 0;
  switch (fork()) {
  case 0: {
    int sum1 = 0;
    int number1_from_pipe = 1;
    int finished = 0;
    while (!finished) {
      if (semop(semaphore, &sem1_prob, 1) == -1) {
        perror("ERROR DECREMENTING THE SEMAPHORE");
      }
      read(fd[0], &number1_from_pipe, sizeof(int));
      sum1 = sum1 + number1_from_pipe;
      if (number1_from_pipe == 0) {
        write(fd[1], &sum1, sizeof(int));
        finished = 1;
        if (semop(semaphore, &sem1_op, 1) == -1) {
          perror("ERROR INCREMENTING THE SEMAPHORE");
        }
      }
    }
    break;
  }
  case -1: {
    printf("ERROR WITH FORK");
    return -1;
    break;
  }
  default: {
    switch (fork()) {
    case 0: {
      int sum2 = 0;
      int number2_from_pipe = 1;
      int finished = 0;
      while (!finished) {
        if (semop(semaphore, &sem2_prob, 1) == -1) {
          perror("ERROR DECREMENTING THE SEMAPHORE");
        }
        read(fd[0], &number2_from_pipe, sizeof(int));
        sum2 = sum2 + number2_from_pipe;
        if (number2_from_pipe == 0) {
          write(fd[1], &sum2, sizeof(int));
          finished = 1;
          if (semop(semaphore, &sem2_op, 1) == -1) {
            perror("ERROR INCREMENTING THE SEMAPHORE");
          }
        }
      }
      break;
    }
    case -1: {
      printf("ERROR WITH FORK");
      return -1;
      break;
    }
    default: {
      int temp = 1;
      int negative_entered = 0;
      int positive_entered = 0;
      do {
        printf("\nInput an integer (0 triggers the computation)\n");
        scanf("%d", &temp);
        getchar();
        if (temp > 0) {
          positive_entered = 1;
          write(fd[1], &temp, sizeof(int));
          if (semop(semaphore, &sem1_op, 1) == -1) {
            perror("ERROR INCREMENTING THE SEMAPHORE");
          }
        }
        if (temp < 0) {
          negative_entered = 1;
          write(fd[1], &temp, sizeof(int));
          if (semop(semaphore, &sem2_op, 1) == -1) {
            perror("ERROR INCREMENTING THE SEMAPHORE");
          }
        }
        if (temp == 0) {
          write(fd[1], &temp, sizeof(int));
          if (semop(semaphore, &sem1_op, 1) == -1) {
            perror("ERROR INCREMENTING THE SEMAPHORE");
          }
          write(fd[1], &temp, sizeof(int));
          if (semop(semaphore, &sem2_op, 1) == -1) {
            perror("ERROR INCREMENTING THE SEMAPHORE");
          }
        }
      } while (temp != 0);
      if (!positive_entered) {
        if (semop(semaphore, &sem1_op, 1) == -1) {
          perror("ERROR INCREMENTING THE SEMAPHORE");
        }
      }
      if (!negative_entered) {
        if (semop(semaphore, &sem2_op, 1) == -1) {
          perror("ERROR INCREMENTING THE SEMAPHORE");
        }
      }
      int res1;
      int res2;
      if (semop(semaphore, &sem1_prob, 1) == -1) {
        perror("ERROR INCREMENTING THE SEMAPHORE");
      }
      read(fd[0], &res1, sizeof(int));
      if (semop(semaphore, &sem2_prob, 1) == -1) {
        perror("ERROR INCREMENTING THE SEMAPHORE");
      }
      read(fd[0], &res2, sizeof(int));
      printf("\nSUM 1 = %d\n", res1);
      printf("SUM 2 = %d\n", res2);
      wait(NULL);
      wait(NULL);
    }
    }
  }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <pipe@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    $0x2,%esi
mov    $0x1b0,%edx
call   1030 <semget@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    120b <main+0x4b>
lea    0xdfa(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x10(%rbp),%edi
mov    0x2dc3(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
mov    %ecx,%esi
call   10b0 <semctl@plt>
cmp    $0xffffffff,%eax
jne    1235 <main+0x75>
lea    0xded(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x10(%rbp),%edi
mov    0x2d99(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
xor    %ecx,%ecx
call   10b0 <semctl@plt>
cmp    $0xffffffff,%eax
jne    1262 <main+0xa2>
lea    0xde5(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x1,-0x40(%rbp)
movl   $0x1,-0x3c(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x1,-0x50(%rbp)
movl   $0xffffffff,-0x4c(%rbp)
movq   $0x0,-0x48(%rbp)
xor    %eax,%eax
call   10e0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x80(%rbp)
sub    $0xffffffff,%eax
je     13a6 <main+0x1e6>
jmp    12d4 <main+0x114>
mov    -0x80(%rbp),%eax
test   %eax,%eax
jne    13c0 <main+0x200>
jmp    12e4 <main+0x124>
movl   $0x0,-0x54(%rbp)
movl   $0x1,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    130f <main+0x14f>
jmp    13a1 <main+0x1e1>
mov    -0x10(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x1,%edx
call   10c0 <semop@plt>
cmp    $0xffffffff,%eax
jne    1335 <main+0x175>
lea    0xd37(%rip),%rdi
call   10a0 <perror@plt>
mov    -0xc(%rbp),%edi
lea    -0x58(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    -0x54(%rbp),%eax
add    -0x58(%rbp),%eax
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x58(%rbp)
jne    139c <main+0x1dc>
mov    -0x8(%rbp),%edi
lea    -0x54(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
movl   $0x1,-0x5c(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   10c0 <semop@plt>
cmp    $0xffffffff,%eax
jne    1397 <main+0x1d7>
lea    0xcf6(%rip),%rdi
call   10a0 <perror@plt>
jmp    139c <main+0x1dc>
jmp    12f9 <main+0x139>
jmp    173d <main+0x57d>
lea    0xcfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    173d <main+0x57d>
xor    %eax,%eax
call   10e0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x84(%rbp)
sub    $0xffffffff,%eax
je     14b2 <main+0x2f2>
jmp    13dd <main+0x21d>
mov    -0x84(%rbp),%eax
test   %eax,%eax
jne    14cc <main+0x30c>
jmp    13f0 <main+0x230>
movl   $0x0,-0x60(%rbp)
movl   $0x1,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    141b <main+0x25b>
jmp    14ad <main+0x2ed>
mov    -0x10(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x1,%edx
call   10c0 <semop@plt>
cmp    $0xffffffff,%eax
jne    1441 <main+0x281>
lea    0xc2b(%rip),%rdi
call   10a0 <perror@plt>
mov    -0xc(%rbp),%edi
lea    -0x64(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    -0x60(%rbp),%eax
add    -0x64(%rbp),%eax
mov    %eax,-0x60(%rbp)
cmpl   $0x0,-0x64(%rbp)
jne    14a8 <main+0x2e8>
mov    -0x8(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
movl   $0x1,-0x68(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x1,%edx
call   10c0 <semop@plt>
cmp    $0xffffffff,%eax
jne    14a3 <main+0x2e3>
lea    0xbea(%rip),%rdi
call   10a0 <perror@plt>
jmp    14a8 <main+0x2e8>
jmp    1405 <main+0x245>
jmp    1738 <main+0x578>
lea    0xbf0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    173d <main+0x57d>
movl   $0x1,-0x6c(%rbp)
movl   $0x0,-0x70(%rbp)
movl   $0x0,-0x74(%rbp)
lea    0xbd1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xbf3(%rip),%rdi
lea    -0x6c(%rbp),%rsi
call   1090 <scanf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
cmpl   $0x0,-0x6c(%rbp)
jle    1553 <main+0x393>
movl   $0x1,-0x74(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x6c(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    -0x10(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   10c0 <semop@plt>
cmp    $0xffffffff,%eax
jne    154e <main+0x38e>
lea    0xb3f(%rip),%rdi
call   10a0 <perror@plt>
jmp    1553 <main+0x393>
cmpl   $0x0,-0x6c(%rbp)
jge    15a0 <main+0x3e0>
movl   $0x1,-0x70(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x6c(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    -0x10(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x1,%edx
call   10c0 <semop@plt>
cmp    $0xffffffff,%eax
jne    159b <main+0x3db>
lea    0xaf2(%rip),%rdi
call   10a0 <perror@plt>
jmp    15a0 <main+0x3e0>
cmpl   $0x0,-0x6c(%rbp)
jne    161d <main+0x45d>
mov    -0x8(%rbp),%edi
lea    -0x6c(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    -0x10(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   10c0 <semop@plt>
cmp    $0xffffffff,%eax
jne    15e1 <main+0x421>
lea    0xaac(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x8(%rbp),%edi
lea    -0x6c(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    -0x10(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x1,%edx
call   10c0 <semop@plt>
cmp    $0xffffffff,%eax
jne    1618 <main+0x458>
lea    0xa75(%rip),%rdi
call   10a0 <perror@plt>
jmp    161d <main+0x45d>
jmp    1622 <main+0x462>
cmpl   $0x0,-0x6c(%rbp)
jne    14e1 <main+0x321>
cmpl   $0x0,-0x74(%rbp)
jne    1661 <main+0x4a1>
mov    -0x10(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   10c0 <semop@plt>
cmp    $0xffffffff,%eax
jne    165c <main+0x49c>
lea    0xa31(%rip),%rdi
call   10a0 <perror@plt>
jmp    1661 <main+0x4a1>
cmpl   $0x0,-0x70(%rbp)
jne    1696 <main+0x4d6>
mov    -0x10(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x1,%edx
call   10c0 <semop@plt>
cmp    $0xffffffff,%eax
jne    1691 <main+0x4d1>
lea    0x9fc(%rip),%rdi
call   10a0 <perror@plt>
jmp    1696 <main+0x4d6>
mov    -0x10(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x1,%edx
call   10c0 <semop@plt>
cmp    $0xffffffff,%eax
jne    16bc <main+0x4fc>
lea    0x9d1(%rip),%rdi
call   10a0 <perror@plt>
mov    -0xc(%rbp),%edi
lea    -0x78(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    -0x10(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x1,%edx
call   10c0 <semop@plt>
cmp    $0xffffffff,%eax
jne    16f3 <main+0x533>
lea    0x99a(%rip),%rdi
call   10a0 <perror@plt>
mov    -0xc(%rbp),%edi
lea    -0x7c(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    -0x78(%rbp),%esi
lea    0x9de(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x7c(%rbp),%esi
lea    0x9da(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <wait@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <wait@plt>
jmp    173d <main+0x57d>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    $0x2,%esi
mov    $0x1b0,%edx
call   1030 <semget@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
je     1638 <main+0x468>
mov    0x2dc5(%rip),%rbx
mov    (%rbx),%edx
mov    %r14d,%edi
xor    %esi,%esi
xor    %ecx,%ecx
call   10c0 <semctl@plt>
cmp    $0xffffffff,%eax
je     1649 <main+0x479>
mov    (%rbx),%edx
mov    %r14d,%edi
mov    $0x1,%esi
xor    %ecx,%ecx
call   10c0 <semctl@plt>
cmp    $0xffffffff,%eax
je     165a <main+0x48a>
movabs $0x100000000,%rax
mov    %rax,0x28(%rsp)
movq   $0x0,0x30(%rsp)
movabs $0xffffffff00000000,%rax
ff ff ff
mov    %rax,0x48(%rsp)
movq   $0x0,0x50(%rsp)
movabs $0x100000001,%rax
mov    %rax,0x18(%rsp)
movq   $0x0,0x20(%rsp)
movabs $0xffffffff00000001,%rax
ff ff ff
mov    %rax,0x38(%rsp)
movq   $0x0,0x40(%rsp)
xor    %eax,%eax
call   10f0 <fork@plt>
cmp    $0xffffffff,%eax
je     138e <main+0x1be>
test   %eax,%eax
jne    131e <main+0x14e>
movl   $0x1,0x4(%rsp)
xor    %ebp,%ebp
lea    0x48(%rsp),%r12
lea    0xd99(%rip),%r15
lea    0x4(%rsp),%rbx
jmp    12ff <main+0x12f>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1080 <read@plt>
mov    0x4(%rsp),%eax
add    %eax,%ebp
test   %eax,%eax
je     13a6 <main+0x1d6>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   10d0 <semop@plt>
cmp    $0xffffffff,%eax
jne    12e0 <main+0x110>
mov    %r15,%rdi
call   10b0 <perror@plt>
jmp    12e0 <main+0x110>
xor    %eax,%eax
call   10f0 <fork@plt>
cmp    $0xffffffff,%eax
je     138e <main+0x1be>
test   %eax,%eax
jne    13c4 <main+0x1f4>
movl   $0x1,0x4(%rsp)
xor    %ebp,%ebp
lea    0x38(%rsp),%r12
lea    0xd1f(%rip),%r15
lea    0x4(%rsp),%rbx
jmp    136f <main+0x19f>
nop
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1080 <read@plt>
mov    0x4(%rsp),%eax
add    %eax,%ebp
test   %eax,%eax
je     1520 <main+0x350>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   10d0 <semop@plt>
cmp    $0xffffffff,%eax
jne    1350 <main+0x180>
mov    %r15,%rdi
call   10b0 <perror@plt>
jmp    1350 <main+0x180>
lea    0xd14(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%ebx
jmp    1551 <main+0x381>
mov    %ebp,(%rsp)
mov    0xc(%rsp),%edi
mov    %rsp,%rsi
mov    $0x4,%edx
call   1050 <write@plt>
lea    0x28(%rsp),%rsi
jmp    1539 <main+0x369>
movl   $0x1,(%rsp)
lea    0xd03(%rip),%rbx
lea    0xce0(%rip),%r15
mov    %rsp,%r12
lea    0x28(%rsp),%r13
movl   $0x0,0x10(%rsp)
xor    %ebp,%ebp
jmp    13fb <main+0x22b>
nopl   (%rax)
mov    (%rsp),%eax
test   %eax,%eax
je     1562 <main+0x392>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   10a0 <scanf@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
mov    (%rsp),%eax
test   %eax,%eax
jle    144e <main+0x27e>
mov    0xc(%rsp),%edi
mov    %r12,%rsi
mov    $0x4,%edx
call   1050 <write@plt>
mov    %r14d,%edi
mov    %r13,%rsi
mov    $0x1,%edx
call   10d0 <semop@plt>
cmp    $0xffffffff,%eax
je     14f0 <main+0x320>
mov    $0x1,%ebp
mov    (%rsp),%eax
test   %eax,%eax
jns    1482 <main+0x2b2>
mov    0xc(%rsp),%edi
mov    %r12,%rsi
mov    $0x4,%edx
call   1050 <write@plt>
movl   $0x1,0x10(%rsp)
mov    %r14d,%edi
lea    0x18(%rsp),%rsi
mov    $0x1,%edx
call   10d0 <semop@plt>
cmp    $0xffffffff,%eax
je     1501 <main+0x331>
mov    (%rsp),%eax
test   %eax,%eax
jne    13f3 <main+0x223>
mov    0xc(%rsp),%edi
mov    %r12,%rsi
mov    $0x4,%edx
call   1050 <write@plt>
mov    %r14d,%edi
mov    %r13,%rsi
mov    $0x1,%edx
call   10d0 <semop@plt>
cmp    $0xffffffff,%eax
je     1512 <main+0x342>
mov    0xc(%rsp),%edi
mov    %r12,%rsi
mov    $0x4,%edx
call   1050 <write@plt>
mov    %r14d,%edi
lea    0x18(%rsp),%rsi
mov    $0x1,%edx
call   10d0 <semop@plt>
cmp    $0xffffffff,%eax
jne    13f0 <main+0x220>
lea    0xba2(%rip),%rdi
call   10b0 <perror@plt>
jmp    13f0 <main+0x220>
lea    0xb91(%rip),%rdi
call   10b0 <perror@plt>
jmp    1446 <main+0x276>
lea    0xb80(%rip),%rdi
call   10b0 <perror@plt>
jmp    1482 <main+0x2b2>
lea    0xb6f(%rip),%rdi
call   10b0 <perror@plt>
jmp    14b3 <main+0x2e3>
mov    %ebp,(%rsp)
mov    0xc(%rsp),%edi
mov    %rsp,%rsi
mov    $0x4,%edx
call   1050 <write@plt>
lea    0x18(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   10d0 <semop@plt>
cmp    $0xffffffff,%eax
je     166b <main+0x49b>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %ebp,%ebp
jne    1581 <main+0x3b1>
lea    0x28(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   10d0 <semop@plt>
cmp    $0xffffffff,%eax
je     169e <main+0x4ce>
cmpl   $0x0,0x10(%rsp)
jne    15a3 <main+0x3d3>
lea    0x18(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   10d0 <semop@plt>
cmp    $0xffffffff,%eax
je     16ba <main+0x4ea>
lea    0x48(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   10d0 <semop@plt>
cmp    $0xffffffff,%eax
je     167c <main+0x4ac>
mov    0x8(%rsp),%edi
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1080 <read@plt>
lea    0x38(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   10d0 <semop@plt>
cmp    $0xffffffff,%eax
je     168d <main+0x4bd>
mov    0x8(%rsp),%edi
lea    0x14(%rsp),%rsi
mov    $0x4,%edx
call   1080 <read@plt>
mov    0x4(%rsp),%esi
lea    0xab2(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x14(%rsp),%esi
lea    0xaab(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10e0 <wait@plt>
xor    %edi,%edi
call   10e0 <wait@plt>
jmp    1551 <main+0x381>
lea    0x9c1(%rip),%rdi
call   10b0 <perror@plt>
jmp    120c <main+0x3c>
lea    0x9cd(%rip),%rdi
call   10b0 <perror@plt>
jmp    122a <main+0x5a>
lea    0x9e1(%rip),%rdi
call   10b0 <perror@plt>
jmp    1244 <main+0x74>
lea    0xa16(%rip),%rdi
call   10b0 <perror@plt>
jmp    154f <main+0x37f>
lea    0xa05(%rip),%rdi
call   10b0 <perror@plt>
jmp    15be <main+0x3ee>
lea    0x9f4(%rip),%rdi
call   10b0 <perror@plt>
jmp    15ec <main+0x41c>
lea    0x9e3(%rip),%rdi
call   10b0 <perror@plt>
cmpl   $0x0,0x10(%rsp)
jne    15a3 <main+0x3d3>
jmp    1588 <main+0x3b8>
lea    0x9c7(%rip),%rdi
call   10b0 <perror@plt>
jmp    15a3 <main+0x3d3>

LLVM IR (-O0):
%struct.sembuf = type { i32, i32, i64 }
@IPC_PRIVATE = global i32 0
@.str = [29 x i8] c"ERROR CREATING THE SEMAPHORE\00"
@SETVAL = global i32 0
@.str.1 = [37 x i8] c"ERROR SETTING SEMAPHORE 1 VALUE TO 1\00"
@.str.2 = [37 x i8] c"ERROR SETTING SEMAPHORE 2 VALUE TO 1\00"
@.str.3 = [33 x i8] c"ERROR DECREMENTING THE SEMAPHORE\00"
@.str.4 = [33 x i8] c"ERROR INCREMENTING THE SEMAPHORE\00"
@.str.5 = [16 x i8] c"ERROR WITH FORK\00"
@.str.6 = [48 x i8] c"\0AInput an integer (0 triggers the computation)\0A\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [13 x i8] c"\0ASUM 1 = %d\0A\00"
@.str.9 = [12 x i8] c"SUM 2 = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca %struct.sembuf
%5 = alloca %struct.sembuf
%6 = alloca %struct.sembuf
%7 = alloca %struct.sembuf
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32 0, i32* %1
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%20 = call i32 @pipe(i32* %19)
%21 = load i32, i32* @IPC_PRIVATE
%22 = call i32 @semget(i32 %21, i32 2, i32 432)
store i32 %22, i32* %3
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %0
%25 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %0
%27 = load i32, i32* %3
%28 = load i32, i32* @SETVAL
%29 = call i32 @semctl(i32 %27, i32 0, i32 %28, i32 0)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %26
%34 = load i32, i32* %3
%35 = load i32, i32* @SETVAL
%36 = call i32 @semctl(i32 %34, i32 1, i32 %35, i32 0)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %33
%41 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %4, i32 0, i32 0
store i32 0, i32* %41
%42 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %4, i32 0, i32 1
store i32 1, i32* %42
%43 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %4, i32 0, i32 2
store i64 0, i64* %43
%44 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %5, i32 0, i32 0
store i32 0, i32* %44
%45 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %5, i32 0, i32 1
store i32 -1, i32* %45
%46 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %5, i32 0, i32 2
store i64 0, i64* %46
%47 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %6, i32 0, i32 0
store i32 1, i32* %47
%48 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %6, i32 0, i32 1
store i32 1, i32* %48
%49 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %6, i32 0, i32 2
store i64 0, i64* %49
%50 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %7, i32 0, i32 0
store i32 1, i32* %50
%51 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %7, i32 0, i32 1
store i32 -1, i32* %51
%52 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %7, i32 0, i32 2
store i64 0, i64* %52
%53 = call i32 (...) @fork()
switch i32 %53, label %88 [
i32 0, label %54
i32 -1, label %86
]
54: ; preds = %40
store i32 0, i32* %8
store i32 1, i32* %9
store i32 0, i32* %10
br label %55
55: ; preds = %84, %54
%56 = load i32, i32* %10
%57 = icmp ne i32 %56, 0
%58 = xor i1 %57, true
br i1 %58, label %59, label %85
59: ; preds = %55
%60 = load i32, i32* %3
%61 = call i32 @semop(i32 %60, %struct.sembuf* %5, i32 1)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %65
63: ; preds = %59
%64 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %65
65: ; preds = %63, %59
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%67 = load i32, i32* %66
%68 = call i32 @read(i32 %67, i32* %9, i32 4)
%69 = load i32, i32* %8
%70 = load i32, i32* %9
%71 = add nsw i32 %69, %70
store i32 %71, i32* %8
%72 = load i32, i32* %9
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %84
74: ; preds = %65
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%76 = load i32, i32* %75
%77 = call i32 @write(i32 %76, i32* %8, i32 4)
store i32 1, i32* %10
%78 = load i32, i32* %3
%79 = call i32 @semop(i32 %78, %struct.sembuf* %4, i32 1)
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %83
81: ; preds = %74
%82 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %83
83: ; preds = %81, %74
br label %84
84: ; preds = %83, %65
br label %55
85: ; preds = %55
br label %226
86: ; preds = %40
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %226
88: ; preds = %40
%89 = call i32 (...) @fork()
switch i32 %89, label %124 [
i32 0, label %90
i32 -1, label %122
]
90: ; preds = %88
store i32 0, i32* %11
store i32 1, i32* %12
store i32 0, i32* %13
br label %91
91: ; preds = %120, %90
%92 = load i32, i32* %13
%93 = icmp ne i32 %92, 0
%94 = xor i1 %93, true
br i1 %94, label %95, label %121
95: ; preds = %91
%96 = load i32, i32* %3
%97 = call i32 @semop(i32 %96, %struct.sembuf* %7, i32 1)
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %101
99: ; preds = %95
%100 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %101
101: ; preds = %99, %95
%102 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%103 = load i32, i32* %102
%104 = call i32 @read(i32 %103, i32* %12, i32 4)
%105 = load i32, i32* %11
%106 = load i32, i32* %12
%107 = add nsw i32 %105, %106
store i32 %107, i32* %11
%108 = load i32, i32* %12
%109 = icmp eq i32 %108, 0
br i1 %109, label %110, label %120
110: ; preds = %101
%111 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%112 = load i32, i32* %111
%113 = call i32 @write(i32 %112, i32* %11, i32 4)
store i32 1, i32* %13
%114 = load i32, i32* %3
%115 = call i32 @semop(i32 %114, %struct.sembuf* %6, i32 1)
%116 = icmp eq i32 %115, -1
br i1 %116, label %117, label %119
117: ; preds = %110
%118 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %119
119: ; preds = %117, %110
br label %120
120: ; preds = %119, %101
br label %91
121: ; preds = %91
br label %225
122: ; preds = %88
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %226
124: ; preds = %88
store i32 1, i32* %14
store i32 0, i32* %15
store i32 0, i32* %16
br label %125
125: ; preds = %177, %124
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0))
%127 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %14)
%128 = call i32 (...) @getchar()
%129 = load i32, i32* %14
%130 = icmp sgt i32 %129, 0
br i1 %130, label %131, label %141
131: ; preds = %125
store i32 1, i32* %16
%132 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%133 = load i32, i32* %132
%134 = call i32 @write(i32 %133, i32* %14, i32 4)
%135 = load i32, i32* %3
%136 = call i32 @semop(i32 %135, %struct.sembuf* %4, i32 1)
%137 = icmp eq i32 %136, -1
br i1 %137, label %138, label %140
138: ; preds = %131
%139 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %140
140: ; preds = %138, %131
br label %141
141: ; preds = %140, %125
%142 = load i32, i32* %14
%143 = icmp slt i32 %142, 0
br i1 %143, label %144, label %154
144: ; preds = %141
store i32 1, i32* %15
%145 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%146 = load i32, i32* %145
%147 = call i32 @write(i32 %146, i32* %14, i32 4)
%148 = load i32, i32* %3
%149 = call i32 @semop(i32 %148, %struct.sembuf* %6, i32 1)
%150 = icmp eq i32 %149, -1
br i1 %150, label %151, label %153
151: ; preds = %144
%152 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %153
153: ; preds = %151, %144
br label %154
154: ; preds = %153, %141
%155 = load i32, i32* %14
%156 = icmp eq i32 %155, 0
br i1 %156, label %157, label %176
157: ; preds = %154
%158 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%159 = load i32, i32* %158
%160 = call i32 @write(i32 %159, i32* %14, i32 4)
%161 = load i32, i32* %3
%162 = call i32 @semop(i32 %161, %struct.sembuf* %4, i32 1)
%163 = icmp eq i32 %162, -1
br i1 %163, label %164, label %166
164: ; preds = %157
%165 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %166
166: ; preds = %164, %157
%167 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%168 = load i32, i32* %167
%169 = call i32 @write(i32 %168, i32* %14, i32 4)
%170 = load i32, i32* %3
%171 = call i32 @semop(i32 %170, %struct.sembuf* %6, i32 1)
%172 = icmp eq i32 %171, -1
br i1 %172, label %173, label %175
173: ; preds = %166
%174 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %175
175: ; preds = %173, %166
br label %176
176: ; preds = %175, %154
br label %177
177: ; preds = %176
%178 = load i32, i32* %14
%179 = icmp ne i32 %178, 0
br i1 %179, label %125, label %180
180: ; preds = %177
%181 = load i32, i32* %16
%182 = icmp ne i32 %181, 0
br i1 %182, label %190, label %183
183: ; preds = %180
%184 = load i32, i32* %3
%185 = call i32 @semop(i32 %184, %struct.sembuf* %4, i32 1)
%186 = icmp eq i32 %185, -1
br i1 %186, label %187, label %189
187: ; preds = %183
%188 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %189
189: ; preds = %187, %183
br label %190
190: ; preds = %189, %180
%191 = load i32, i32* %15
%192 = icmp ne i32 %191, 0
br i1 %192, label %200, label %193
193: ; preds = %190
%194 = load i32, i32* %3
%195 = call i32 @semop(i32 %194, %struct.sembuf* %6, i32 1)
%196 = icmp eq i32 %195, -1
br i1 %196, label %197, label %199
197: ; preds = %193
%198 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %199
199: ; preds = %197, %193
br label %200
200: ; preds = %199, %190
%201 = load i32, i32* %3
%202 = call i32 @semop(i32 %201, %struct.sembuf* %5, i32 1)
%203 = icmp eq i32 %202, -1
br i1 %203, label %204, label %206
204: ; preds = %200
%205 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %206
206: ; preds = %204, %200
%207 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%208 = load i32, i32* %207
%209 = call i32 @read(i32 %208, i32* %17, i32 4)
%210 = load i32, i32* %3
%211 = call i32 @semop(i32 %210, %struct.sembuf* %7, i32 1)
%212 = icmp eq i32 %211, -1
br i1 %212, label %213, label %215
213: ; preds = %206
%214 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %215
215: ; preds = %213, %206
%216 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%217 = load i32, i32* %216
%218 = call i32 @read(i32 %217, i32* %18, i32 4)
%219 = load i32, i32* %17
%220 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %219)
%221 = load i32, i32* %18
%222 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 %221)
%223 = call i32 @wait(i32* null)
%224 = call i32 @wait(i32* null)
br label %225
225: ; preds = %215, %121
br label %226
226: ; preds = %86, %122, %225, %85
%227 = load i32, i32* %1
ret i32 %227
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i64 }
@IPC_PRIVATE = global i32 0
@.str = [29 x i8] c"ERROR CREATING THE SEMAPHORE\00"
@SETVAL = global i32 0
@.str.1 = [37 x i8] c"ERROR SETTING SEMAPHORE 1 VALUE TO 1\00"
@.str.2 = [37 x i8] c"ERROR SETTING SEMAPHORE 2 VALUE TO 1\00"
@.str.3 = [33 x i8] c"ERROR DECREMENTING THE SEMAPHORE\00"
@.str.4 = [33 x i8] c"ERROR INCREMENTING THE SEMAPHORE\00"
@.str.5 = [16 x i8] c"ERROR WITH FORK\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [13 x i8] c"\0ASUM 1 = %d\0A\00"
@.str.9 = [12 x i8] c"SUM 2 = %d\0A\00"
@str = [47 x i8] c"\0AInput an integer (0 triggers the computation)\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca %struct.sembuf
%3 = alloca %struct.sembuf
%4 = alloca %struct.sembuf
%5 = alloca %struct.sembuf
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = bitcast [2 x i32]* %1 to i8*
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%15 = call i32 @pipe(i32* %14)
%16 = load i32, i32* @IPC_PRIVATE
%17 = call i32 @semget(i32 %16, i32 2, i32 432)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %0
%20 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %0
%22 = load i32, i32* @SETVAL
%23 = call i32 @semctl(i32 %17, i32 0, i32 %22, i32 0)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = load i32, i32* @SETVAL
%29 = call i32 @semctl(i32 %17, i32 1, i32 %28, i32 0)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = bitcast %struct.sembuf* %2 to i8*
%35 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %2, i64 0, i32 0
store i32 0, i32* %35
%36 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %2, i64 0, i32 1
store i32 1, i32* %36
%37 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %2, i64 0, i32 2
store i64 0, i64* %37
%38 = bitcast %struct.sembuf* %3 to i8*
%39 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i64 0, i32 0
store i32 0, i32* %39
%40 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i64 0, i32 1
store i32 -1, i32* %40
%41 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i64 0, i32 2
store i64 0, i64* %41
%42 = bitcast %struct.sembuf* %4 to i8*
%43 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %4, i64 0, i32 0
store i32 1, i32* %43
%44 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %4, i64 0, i32 1
store i32 1, i32* %44
%45 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %4, i64 0, i32 2
store i64 0, i64* %45
%46 = bitcast %struct.sembuf* %5 to i8*
%47 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %5, i64 0, i32 0
store i32 1, i32* %47
%48 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %5, i64 0, i32 1
store i32 -1, i32* %48
%49 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %5, i64 0, i32 2
store i64 0, i64* %49
%50 = call i32 (...) @fork()
switch i32 %50, label %77 [
i32 0, label %51
i32 -1, label %75
]
51: ; preds = %33
%52 = bitcast i32* %6 to i8*
%53 = bitcast i32* %7 to i8*
store i32 1, i32* %7
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
br label %55
55: ; preds = %61, %51
%56 = phi i32 [ 0, %51 ], [ %65, %61 ]
%57 = call i32 @semop(i32 %17, %struct.sembuf* %3, i32 1)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %61
61: ; preds = %59, %55
%62 = load i32, i32* %14
%63 = call i32 @read(i32 %62, i32* %7, i32 4)
%64 = load i32, i32* %7
%65 = add nsw i32 %64, %56
%66 = icmp eq i32 %64, 0
br i1 %66, label %67, label %55
67: ; preds = %61
store i32 %65, i32* %6
%68 = load i32, i32* %54
%69 = call i32 @write(i32 %68, i32* %6, i32 4)
%70 = call i32 @semop(i32 %17, %struct.sembuf* %2, i32 1)
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %74
72: ; preds = %67
%73 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %74
74: ; preds = %67, %72
br label %196
75: ; preds = %33
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %196
77: ; preds = %33
%78 = call i32 (...) @fork()
switch i32 %78, label %105 [
i32 0, label %79
i32 -1, label %103
]
79: ; preds = %77
%80 = bitcast i32* %8 to i8*
%81 = bitcast i32* %9 to i8*
store i32 1, i32* %9
%82 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
br label %83
83: ; preds = %89, %79
%84 = phi i32 [ 0, %79 ], [ %93, %89 ]
%85 = call i32 @semop(i32 %17, %struct.sembuf* %5, i32 1)
%86 = icmp eq i32 %85, -1
br i1 %86, label %87, label %89
87: ; preds = %83
%88 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %89
89: ; preds = %87, %83
%90 = load i32, i32* %14
%91 = call i32 @read(i32 %90, i32* %9, i32 4)
%92 = load i32, i32* %9
%93 = add nsw i32 %92, %84
%94 = icmp eq i32 %92, 0
br i1 %94, label %95, label %83
95: ; preds = %89
store i32 %93, i32* %8
%96 = load i32, i32* %82
%97 = call i32 @write(i32 %96, i32* %8, i32 4)
%98 = call i32 @semop(i32 %17, %struct.sembuf* %4, i32 1)
%99 = icmp eq i32 %98, -1
br i1 %99, label %100, label %102
100: ; preds = %95
%101 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %102
102: ; preds = %95, %100
br label %196
103: ; preds = %77
%104 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %196
105: ; preds = %77
%106 = bitcast i32* %10 to i8*
store i32 1, i32* %10
%107 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
br label %108
108: ; preds = %156, %105
%109 = phi i32 [ 0, %105 ], [ %137, %156 ]
%110 = phi i32 [ 0, %105 ], [ %127, %156 ]
%111 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
%112 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %10)
%113 = call i32 (...) @getchar()
%114 = load i32, i32* %10
%115 = icmp sgt i32 %114, 0
br i1 %115, label %116, label %125
116: ; preds = %108
%117 = load i32, i32* %107
%118 = call i32 @write(i32 %117, i32* %10, i32 4)
%119 = call i32 @semop(i32 %17, %struct.sembuf* %2, i32 1)
%120 = icmp eq i32 %119, -1
br i1 %120, label %121, label %123
121: ; preds = %116
%122 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %123
123: ; preds = %121, %116
%124 = load i32, i32* %10
br label %125
125: ; preds = %123, %108
%126 = phi i32 [ %124, %123 ], [ %114, %108 ]
%127 = phi i32 [ 1, %123 ], [ %110, %108 ]
%128 = icmp slt i32 %126, 0
br i1 %128, label %129, label %136
129: ; preds = %125
%130 = load i32, i32* %107
%131 = call i32 @write(i32 %130, i32* %10, i32 4)
%132 = call i32 @semop(i32 %17, %struct.sembuf* %4, i32 1)
%133 = icmp eq i32 %132, -1
br i1 %133, label %134, label %136
134: ; preds = %129
%135 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %136
136: ; preds = %129, %134, %125
%137 = phi i32 [ 1, %134 ], [ 1, %129 ], [ %109, %125 ]
%138 = load i32, i32* %10
%139 = icmp eq i32 %138, 0
br i1 %139, label %140, label %156
140: ; preds = %136
%141 = load i32, i32* %107
%142 = call i32 @write(i32 %141, i32* %10, i32 4)
%143 = call i32 @semop(i32 %17, %struct.sembuf* %2, i32 1)
%144 = icmp eq i32 %143, -1
br i1 %144, label %145, label %147
145: ; preds = %140
%146 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %147
147: ; preds = %145, %140
%148 = load i32, i32* %107
%149 = call i32 @write(i32 %148, i32* %10, i32 4)
%150 = call i32 @semop(i32 %17, %struct.sembuf* %4, i32 1)
%151 = icmp eq i32 %150, -1
br i1 %151, label %152, label %154
152: ; preds = %147
%153 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %154
154: ; preds = %147, %152
%155 = load i32, i32* %10
br label %156
156: ; preds = %154, %136
%157 = phi i32 [ %155, %154 ], [ %138, %136 ]
%158 = icmp eq i32 %157, 0
br i1 %158, label %159, label %108
159: ; preds = %156
%160 = icmp eq i32 %127, 0
br i1 %160, label %161, label %166
161: ; preds = %159
%162 = call i32 @semop(i32 %17, %struct.sembuf* %2, i32 1)
%163 = icmp eq i32 %162, -1
br i1 %163, label %164, label %166
164: ; preds = %161
%165 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %166
166: ; preds = %161, %164, %159
%167 = icmp eq i32 %137, 0
br i1 %167, label %168, label %173
168: ; preds = %166
%169 = call i32 @semop(i32 %17, %struct.sembuf* %4, i32 1)
%170 = icmp eq i32 %169, -1
br i1 %170, label %171, label %173
171: ; preds = %168
%172 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %173
173: ; preds = %168, %171, %166
%174 = bitcast i32* %11 to i8*
%175 = bitcast i32* %12 to i8*
%176 = call i32 @semop(i32 %17, %struct.sembuf* %3, i32 1)
%177 = icmp eq i32 %176, -1
br i1 %177, label %178, label %180
178: ; preds = %173
%179 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %180
180: ; preds = %178, %173
%181 = load i32, i32* %14
%182 = call i32 @read(i32 %181, i32* %11, i32 4)
%183 = call i32 @semop(i32 %17, %struct.sembuf* %5, i32 1)
%184 = icmp eq i32 %183, -1
br i1 %184, label %185, label %187
185: ; preds = %180
%186 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %187
187: ; preds = %185, %180
%188 = load i32, i32* %14
%189 = call i32 @read(i32 %188, i32* %12, i32 4)
%190 = load i32, i32* %11
%191 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %190)
%192 = load i32, i32* %12
%193 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 %192)
%194 = call i32 @wait(i32* null)
%195 = call i32 @wait(i32* null)
br label %196
196: ; preds = %74, %187, %102, %103, %75
%197 = phi i32 [ -1, %103 ], [ -1, %75 ], [ 0, %102 ], [ 0, %187 ], [ 0, %74 ]
ret i32 %197
}