#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 /*<<< orphan*/ member_2;
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int IPC_CREAT;
int /*<<< orphan*/ IPC_RMID;
int atoi(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int semctl(int, int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/ *);
int semget(int, int, int);
int semop(int, struct sembuf *, int);
void *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ shmdt(void *);
int shmget(int, int, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
int system(char *);
int main(int argc, char *argv[]) {
  int ret = -1;
  if (argc < 2) {
    fprintf(stderr, "testipc createshm\n");
  } else if (strcmp(argv[1], "createshm") == 0) {
    int id = shmget(1, 1024, IPC_CREAT | 0666);
    if (id == -1) {
      fprintf(stderr, "shmget failed (%s)\n", strerror(errno));
    } else {
      void *pt = shmat(id, NULL, 0);
      printf("shmget id %d\n", id);
      if (pt == NULL) {
        fprintf(stderr, "can't shmat to id %d (%s)\n", id, strerror(errno));
      } else {
        char tmp[100];
        int ok;
        strcpy((char *)pt, "original string");
        printf("Letting a sub-program attach to this memory\n");
        sprintf(tmp, "./testipc accessshm %d", id);
        ok = system(tmp);
        printf("\tSub-program returned %d\n", ok);
        printf("\tThe segment now hold :%s:\n", (char *)pt);
        shmdt(pt);
        printf("A sub-program in another context can't attach\n");
        sprintf(tmp, "/usr/sbin/chcontext ./testipc accessshm %d", id);
        ok = system(tmp);
        printf("\tSub-program returned %d\n", ok);
        printf("Executing a sub-shell\n");
        system("/bin/sh");
      }
      printf("Delete the share memory segment\n");
      if (shmctl(id, IPC_RMID, NULL) == -1) {
        fprintf(stderr, "shmctl failed (%s)\n", strerror(errno));
      } else {
        ret = 0;
      }
    }
  } else if (strcmp(argv[1], "accessshm") == 0) {
    int id = atoi(argv[2]);
    void *pt = shmat(id, NULL, 0);
    if (pt == (void *)-1) {
      fprintf(stderr, "can't shmat to id %d (%s)\n", id, strerror(errno));
    } else {
      printf("\tWriting hello in share memory\n");
      strcpy((char *)pt, "hello");
      ret = 0;
    }
  } else if (strcmp(argv[1], "createsem") == 0) {
    int id = semget(1, 1, IPC_CREAT | 0666);
    if (id == -1) {
      fprintf(stderr, "semget failed (%s)\n", strerror(errno));
    } else {
      char tmp[100];
      int ok;
      printf("semget id %d\n", id);
      printf("Letting a sub-program play with this semaphore\n");
      sprintf(tmp, "./testipc accesssem %d", id);
      ok = system(tmp);
      printf("\tSub-program returned %d\n", ok);
      printf("A sub-program in another context can't use the semaphore\n");
      sprintf(tmp, "/usr/sbin/chcontext ./testipc accesssem %d", id);
      ok = system(tmp);
      printf("\tSub-program returned %d\n", ok);
      printf("Executing a sub-shell\n");
      system("/bin/sh");
      printf("Delete the semaphore\n");
      if (semctl(id, 0, IPC_RMID, NULL) == -1) {
        fprintf(stderr, "semctl failed (%s)\n", strerror(errno));
      } else {
        ret = 0;
      }
    }
  } else if (strcmp(argv[1], "accesssem") == 0) {
    int id = atoi(argv[2]);
    struct sembuf ops[] = {{0, 0, 0}};
    if (semop(id, ops, 1) == -1) {
      fprintf(stderr, "can't semop with id %d (%s)\n", id, strerror(errno));
    } else {
      ret = 0;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1246 <main+0x46>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    17f9 <main+0x5f9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdbe(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    148d <main+0x28d>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x1,%edi
mov    $0x400,%esi
call   10e0 <shmget@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    12c8 <main+0xc8>
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x12c(%rbp)
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x12c(%rbp),%edi
mov    %rax,%rdx
lea    0xd61(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1488 <main+0x288>
mov    -0x18(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10d0 <shmat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%esi
lea    0xd4d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpq   $0x0,-0x20(%rbp)
jne    133e <main+0x13e>
mov    0x2ce3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x130(%rbp)
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x134(%rbp),%edi
mov    -0x130(%rbp),%edx
mov    %rax,%rcx
lea    0xd0d(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1417 <main+0x217>
mov    -0x20(%rbp),%rdi
lea    0xd11(%rip),%rsi
call   1040 <strcpy@plt>
lea    0xd15(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xda3(%rip),%rsi
call   1110 <sprintf@plt>
lea    -0x90(%rbp),%rdi
call   1060 <system@plt>
mov    %eax,-0x94(%rbp)
mov    -0x94(%rbp),%esi
lea    0xd06(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xd0e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <shmdt@plt>
lea    0xd13(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xd2a(%rip),%rsi
call   1110 <sprintf@plt>
lea    -0x90(%rbp),%rdi
call   1060 <system@plt>
mov    %eax,-0x94(%rbp)
mov    -0x94(%rbp),%esi
lea    0xca1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd23(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd2c(%rip),%rdi
call   1060 <system@plt>
lea    0xd28(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%edi
mov    0x2ba1(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   10b0 <shmctl@plt>
cmp    $0xffffffff,%eax
jne    147c <main+0x27c>
mov    0x2b96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x138(%rbp)
mov    0x2b7f(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x138(%rbp),%edi
mov    %rax,%rdx
lea    0xcf7(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1483 <main+0x283>
movl   $0x0,-0x14(%rbp)
jmp    1488 <main+0x288>
jmp    17f4 <main+0x5f4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcdf(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1562 <main+0x362>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x98(%rbp)
mov    -0x98(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10d0 <shmat@plt>
mov    %rax,-0xa0(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0xa0(%rbp)
jne    1535 <main+0x335>
mov    0x2aef(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x140(%rbp)
mov    -0x98(%rbp),%eax
mov    %eax,-0x13c(%rbp)
mov    0x2acc(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x140(%rbp),%edi
mov    -0x13c(%rbp),%edx
mov    %rax,%rcx
lea    0xb16(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    155d <main+0x35d>
lea    0xc49(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xa0(%rbp),%rdi
lea    0xc54(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x14(%rbp)
jmp    17ef <main+0x5ef>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xc3a(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    172a <main+0x52a>
mov    0x2a41(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x1,%esi
mov    %esi,%edi
call   1030 <semget@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0xffffffff,-0xa4(%rbp)
jne    15e7 <main+0x3e7>
mov    0x2a2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x144(%rbp)
mov    0x2a14(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x144(%rbp),%edi
mov    %rax,%rdx
lea    0xbda(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1725 <main+0x525>
mov    -0xa4(%rbp),%esi
lea    0xbd5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xbd5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    -0xa4(%rbp),%edx
lea    0xc38(%rip),%rsi
call   1110 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1060 <system@plt>
mov    %eax,-0x114(%rbp)
mov    -0x114(%rbp),%esi
lea    0xa56(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xbb8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    -0xa4(%rbp),%edx
lea    0xbd7(%rip),%rsi
call   1110 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1060 <system@plt>
mov    %eax,-0x114(%rbp)
mov    -0x114(%rbp),%esi
lea    0xa09(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xa8b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xa94(%rip),%rdi
call   1060 <system@plt>
lea    0xbb6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xa4(%rbp),%edi
mov    0x2906(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%ecx
call   10c0 <semctl@plt>
cmp    $0xffffffff,%eax
jne    1719 <main+0x519>
mov    0x28f9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x148(%rbp)
mov    0x28e2(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x148(%rbp),%edi
mov    %rax,%rdx
lea    0xb75(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1720 <main+0x520>
movl   $0x0,-0x14(%rbp)
jmp    1725 <main+0x525>
jmp    17ea <main+0x5ea>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xb5d(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    17e5 <main+0x5e5>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x118(%rbp)
lea    -0x128(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    -0x118(%rbp),%edi
lea    -0x128(%rbp),%rsi
mov    $0x1,%edx
call   1100 <semop@plt>
cmp    $0xffffffff,%eax
jne    17d9 <main+0x5d9>
mov    0x284b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x150(%rbp)
mov    -0x118(%rbp),%eax
mov    %eax,-0x14c(%rbp)
mov    0x2828(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x150(%rbp),%edi
mov    -0x14c(%rbp),%edx
mov    %rax,%rcx
lea    0xad3(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    17e0 <main+0x5e0>
movl   $0x0,-0x14(%rbp)
jmp    17e5 <main+0x5e5>
jmp    17ea <main+0x5ea>
jmp    17ef <main+0x5ef>
jmp    17f4 <main+0x5f4>
jmp    17f9 <main+0x5f9>
mov    -0x14(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
cmp    $0x1,%edi
jg     122b <main+0x2b>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1630 <main+0x430>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xdda(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     12f3 <main+0xf3>
mov    0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     13f3 <main+0x1f3>
mov    0x8(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1439 <main+0x239>
mov    0x8(%rbp),%rdi
lea    0xede(%rip),%rsi
call   1090 <strcmp@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    1635 <main+0x435>
mov    0x10(%rbp),%rdi
call   10f0 <atoi@plt>
mov    %eax,%ebp
movl   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1100 <semop@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
jne    1635 <main+0x435>
mov    0x2d0d(%rip),%rax
mov    (%rax),%ebx
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xe82(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
jmp    15fa <main+0x3fa>
mov    0x2cce(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0x1,%edi
mov    $0x400,%esi
call   10e0 <shmget@plt>
cmp    $0xffffffff,%eax
je     1543 <main+0x343>
mov    %eax,%ebp
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <shmat@plt>
mov    %rax,%rbx
lea    0xd01(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <printf@plt>
test   %rbx,%rbx
je     1566 <main+0x366>
lea    0xd11(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
lea    0xecd(%rip),%rdi
call   1050 <puts@plt>
lea    0xd50(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebp,%edx
call   1110 <sprintf@plt>
mov    %r14,%rdi
call   1070 <system@plt>
lea    0xcea(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xcf1(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1060 <shmdt@plt>
lea    0xea5(%rip),%rdi
call   1050 <puts@plt>
lea    0xce8(%rip),%rsi
mov    %r14,%rdi
mov    %ebp,%edx
call   1110 <sprintf@plt>
mov    %r14,%rdi
call   1070 <system@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xea2(%rip),%rdi
call   1050 <puts@plt>
lea    0xce2(%rip),%rdi
call   1070 <system@plt>
jmp    1592 <main+0x392>
mov    0x10(%rbp),%rdi
call   10f0 <atoi@plt>
mov    %eax,%r14d
xor    %ebx,%ebx
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
je     15d7 <main+0x3d7>
mov    %rax,%rbp
lea    0xde6(%rip),%rdi
call   1050 <puts@plt>
lea    0xcc5(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcpy@plt>
jmp    1635 <main+0x435>
mov    0x2b88(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0x1,%edi
mov    $0x1,%esi
call   1030 <semget@plt>
cmp    $0xffffffff,%eax
je     1606 <main+0x406>
mov    %eax,%ebp
lea    0xcad(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd0f(%rip),%rdi
call   1050 <puts@plt>
lea    0xcb1(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebp,%edx
call   1110 <sprintf@plt>
mov    %r14,%rdi
call   1070 <system@plt>
lea    0xbc8(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd03(%rip),%rdi
call   1050 <puts@plt>
lea    0xc62(%rip),%rsi
mov    %r14,%rdi
mov    %ebp,%edx
call   1110 <sprintf@plt>
mov    %r14,%rdi
call   1070 <system@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd99(%rip),%rdi
call   1050 <puts@plt>
lea    0xbd9(%rip),%rdi
call   1070 <system@plt>
lea    0xcf3(%rip),%rdi
call   1050 <puts@plt>
mov    0x2ac6(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
xor    %ecx,%ecx
call   10c0 <semctl@plt>
cmp    $0xffffffff,%eax
jne    1635 <main+0x435>
mov    0x2ab9(%rip),%rax
mov    (%rax),%ebx
mov    0x2aa8(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xc10(%rip),%rsi
jmp    1624 <main+0x424>
mov    0x2a96(%rip),%rax
mov    (%rax),%ebx
mov    0x2a85(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xabc(%rip),%rsi
jmp    1624 <main+0x424>
mov    0x2a73(%rip),%rax
mov    (%rax),%ebx
mov    0x2a62(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xabb(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
lea    0xcfc(%rip),%rdi
call   1050 <puts@plt>
mov    0x2a2b(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %edx,%edx
call   10b0 <shmctl@plt>
cmp    $0xffffffff,%eax
jne    1635 <main+0x435>
mov    0x2a22(%rip),%rax
mov    (%rax),%ebx
mov    0x2a11(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xafe(%rip),%rsi
jmp    1624 <main+0x424>
mov    0x2a02(%rip),%rax
mov    (%rax),%ebx
mov    0x29f1(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xa4a(%rip),%rsi
mov    %ebx,%edi
mov    %r14d,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1630 <main+0x430>
mov    0x29d3(%rip),%rax
mov    (%rax),%ebx
mov    0x29c2(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xadd(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sembuf = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [19 x i8] c"testipc createshm\0A\00"
@.str.1 = [10 x i8] c"createshm\00"
@IPC_CREAT = global i32 0
@.str.2 = [20 x i8] c"shmget failed (%s)\0A\00"
@errno = global i32 0
@.str.3 = [14 x i8] c"shmget id %d\0A\00"
@.str.4 = [27 x i8] c"can't shmat to id %d (%s)\0A\00"
@.str.5 = [16 x i8] c"original string\00"
@.str.6 = [45 x i8] c"Letting a sub-program attach to this memory\0A\00"
@.str.7 = [23 x i8] c"./testipc accessshm %d\00"
@.str.8 = [26 x i8] c"\09Sub-program returned %d\0A\00"
@.str.9 = [28 x i8] c"\09The segment now hold :%s:\0A\00"
@.str.10 = [47 x i8] c"A sub-program in another context can't attach\0A\00"
@.str.11 = [43 x i8] c"/usr/sbin/chcontext ./testipc accessshm %d\00"
@.str.12 = [23 x i8] c"Executing a sub-shell\0A\00"
@.str.13 = [8 x i8] c"/bin/sh\00"
@.str.14 = [33 x i8] c"Delete the share memory segment\0A\00"
@IPC_RMID = global i32 0
@.str.15 = [20 x i8] c"shmctl failed (%s)\0A\00"
@.str.16 = [10 x i8] c"accessshm\00"
@.str.17 = [32 x i8] c"\09Writing hello in share memory\0A\00"
@.str.18 = [6 x i8] c"hello\00"
@.str.19 = [10 x i8] c"createsem\00"
@.str.20 = [20 x i8] c"semget failed (%s)\0A\00"
@.str.21 = [14 x i8] c"semget id %d\0A\00"
@.str.22 = [48 x i8] c"Letting a sub-program play with this semaphore\0A\00"
@.str.23 = [23 x i8] c"./testipc accesssem %d\00"
@.str.24 = [58 x i8] c"A sub-program in another context can't use the semaphore\0A\00"
@.str.25 = [43 x i8] c"/usr/sbin/chcontext ./testipc accesssem %d\00"
@.str.26 = [22 x i8] c"Delete the semaphore\0A\00"
@.str.27 = [20 x i8] c"semctl failed (%s)\0A\00"
@.str.28 = [10 x i8] c"accesssem\00"
@.str.29 = [29 x i8] c"can't semop with id %d (%s)\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 i8*
%9 = alloca [100 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca [100 x i8]
%15 = alloca i32
%16 = alloca i32
%17 = alloca [1 x %struct.sembuf]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 2
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %197
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %92
29: ; preds = %23
%30 = load i32, i32* @IPC_CREAT
%31 = or i32 %30, 438
%32 = call i32 @shmget(i32 1, i32 1024, i32 %31)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %40
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %38)
br label %91
40: ; preds = %29
%41 = load i32, i32* %7
%42 = call i8* @shmat(i32 %41, i32* null, i32 0)
store i8* %42, i8** %8
%43 = load i32, i32* %7
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %43)
%45 = load i8*, i8** %8
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %53
47: ; preds = %40
%48 = load i32, i32* @stderr
%49 = load i32, i32* %7
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %49, i8* %51)
br label %78
53: ; preds = %40
%54 = load i8*, i8** %8
%55 = call i32 @strcpy(i8* %54, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%58 = load i32, i32* %7
%59 = call i32 @sprintf(i8* %57, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %58)
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%61 = call i32 @system(i8* %60)
store i32 %61, i32* %10
%62 = load i32, i32* %10
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %62)
%64 = load i8*, i8** %8
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i8* %64)
%66 = load i8*, i8** %8
%67 = call i32 @shmdt(i8* %66)
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0))
%69 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%70 = load i32, i32* %7
%71 = call i32 @sprintf(i8* %69, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.11, i64 0, i64 0), i32 %70)
%72 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%73 = call i32 @system(i8* %72)
store i32 %73, i32* %10
%74 = load i32, i32* %10
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %74)
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.12, i64 0, i64 0))
%77 = call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i64 0, i64 0))
br label %78
78: ; preds = %53, %47
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.14, i64 0, i64 0))
%80 = load i32, i32* %7
%81 = load i32, i32* @IPC_RMID
%82 = call i32 @shmctl(i32 %80, i32 %81, i32* null)
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %89
84: ; preds = %78
%85 = load i32, i32* @stderr
%86 = load i32, i32* @errno
%87 = call i8* @strerror(i32 %86)
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.15, i64 0, i64 0), i8* %87)
br label %90
89: ; preds = %78
store i32 0, i32* %6
br label %90
90: ; preds = %89, %84
br label %91
91: ; preds = %90, %35
br label %196
92: ; preds = %23
%93 = load i8**, i8*** %5
%94 = getelementptr inbounds i8*, i8** %93, i64 1
%95 = load i8*, i8** %94
%96 = call i64 @strcmp(i8* %95, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.16, i64 0, i64 0))
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %118
98: ; preds = %92
%99 = load i8**, i8*** %5
%100 = getelementptr inbounds i8*, i8** %99, i64 2
%101 = load i8*, i8** %100
%102 = call i32 @atoi(i8* %101)
store i32 %102, i32* %11
%103 = load i32, i32* %11
%104 = call i8* @shmat(i32 %103, i32* null, i32 0)
store i8* %104, i8** %12
%105 = load i8*, i8** %12
%106 = icmp eq i8* %105, inttoptr (i64 -1 to i8*)
br i1 %106, label %107, label %113
107: ; preds = %98
%108 = load i32, i32* @stderr
%109 = load i32, i32* %11
%110 = load i32, i32* @errno
%111 = call i8* @strerror(i32 %110)
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %109, i8* %111)
br label %117
113: ; preds = %98
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.17, i64 0, i64 0))
%115 = load i8*, i8** %12
%116 = call i32 @strcpy(i8* %115, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.18, i64 0, i64 0))
store i32 0, i32* %6
br label %117
117: ; preds = %113, %107
br label %195
118: ; preds = %92
%119 = load i8**, i8*** %5
%120 = getelementptr inbounds i8*, i8** %119, i64 1
%121 = load i8*, i8** %120
%122 = call i64 @strcmp(i8* %121, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.19, i64 0, i64 0))
%123 = icmp eq i64 %122, 0
br i1 %123, label %124, label %169
124: ; preds = %118
%125 = load i32, i32* @IPC_CREAT
%126 = or i32 %125, 438
%127 = call i32 @semget(i32 1, i32 1, i32 %126)
store i32 %127, i32* %13
%128 = load i32, i32* %13
%129 = icmp eq i32 %128, -1
br i1 %129, label %130, label %135
130: ; preds = %124
%131 = load i32, i32* @stderr
%132 = load i32, i32* @errno
%133 = call i8* @strerror(i32 %132)
%134 = call i32 (i32, i8*, ...) @fprintf(i32 %131, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.20, i64 0, i64 0), i8* %133)
br label %168
135: ; preds = %124
%136 = load i32, i32* %13
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.21, i64 0, i64 0), i32 %136)
%138 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.22, i64 0, i64 0))
%139 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%140 = load i32, i32* %13
%141 = call i32 @sprintf(i8* %139, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.23, i64 0, i64 0), i32 %140)
%142 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%143 = call i32 @system(i8* %142)
store i32 %143, i32* %15
%144 = load i32, i32* %15
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %144)
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.24, i64 0, i64 0))
%147 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%148 = load i32, i32* %13
%149 = call i32 @sprintf(i8* %147, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.25, i64 0, i64 0), i32 %148)
%150 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%151 = call i32 @system(i8* %150)
store i32 %151, i32* %15
%152 = load i32, i32* %15
%153 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %152)
%154 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.12, i64 0, i64 0))
%155 = call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i64 0, i64 0))
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.26, i64 0, i64 0))
%157 = load i32, i32* %13
%158 = load i32, i32* @IPC_RMID
%159 = call i32 @semctl(i32 %157, i32 0, i32 %158, i32* null)
%160 = icmp eq i32 %159, -1
br i1 %160, label %161, label %166
161: ; preds = %135
%162 = load i32, i32* @stderr
%163 = load i32, i32* @errno
%164 = call i8* @strerror(i32 %163)
%165 = call i32 (i32, i8*, ...) @fprintf(i32 %162, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.27, i64 0, i64 0), i8* %164)
br label %167
166: ; preds = %135
store i32 0, i32* %6
br label %167
167: ; preds = %166, %161
br label %168
168: ; preds = %167, %130
br label %194
169: ; preds = %118
%170 = load i8**, i8*** %5
%171 = getelementptr inbounds i8*, i8** %170, i64 1
%172 = load i8*, i8** %171
%173 = call i64 @strcmp(i8* %172, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.28, i64 0, i64 0))
%174 = icmp eq i64 %173, 0
br i1 %174, label %175, label %193
175: ; preds = %169
%176 = load i8**, i8*** %5
%177 = getelementptr inbounds i8*, i8** %176, i64 2
%178 = load i8*, i8** %177
%179 = call i32 @atoi(i8* %178)
store i32 %179, i32* %16
%180 = bitcast [1 x %struct.sembuf]* %17 to i8*
%181 = load i32, i32* %16
%182 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %17, i64 0, i64 0
%183 = call i32 @semop(i32 %181, %struct.sembuf* %182, i32 1)
%184 = icmp eq i32 %183, -1
br i1 %184, label %185, label %191
185: ; preds = %175
%186 = load i32, i32* @stderr
%187 = load i32, i32* %16
%188 = load i32, i32* @errno
%189 = call i8* @strerror(i32 %188)
%190 = call i32 (i32, i8*, ...) @fprintf(i32 %186, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.29, i64 0, i64 0), i32 %187, i8* %189)
br label %192
191: ; preds = %175
store i32 0, i32* %6
br label %192
192: ; preds = %191, %185
br label %193
193: ; preds = %192, %169
br label %194
194: ; preds = %193, %168
br label %195
195: ; preds = %194, %117
br label %196
196: ; preds = %195, %91
br label %197
197: ; preds = %196, %20
%198 = load i32, i32* %6
ret i32 %198
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [19 x i8] c"testipc createshm\0A\00"
@.str.1 = [10 x i8] c"createshm\00"
@IPC_CREAT = global i32 0
@.str.2 = [20 x i8] c"shmget failed (%s)\0A\00"
@errno = global i32 0
@.str.3 = [14 x i8] c"shmget id %d\0A\00"
@.str.4 = [27 x i8] c"can't shmat to id %d (%s)\0A\00"
@.str.5 = [16 x i8] c"original string\00"
@.str.7 = [23 x i8] c"./testipc accessshm %d\00"
@.str.8 = [26 x i8] c"\09Sub-program returned %d\0A\00"
@.str.9 = [28 x i8] c"\09The segment now hold :%s:\0A\00"
@.str.11 = [43 x i8] c"/usr/sbin/chcontext ./testipc accessshm %d\00"
@.str.13 = [8 x i8] c"/bin/sh\00"
@IPC_RMID = global i32 0
@.str.15 = [20 x i8] c"shmctl failed (%s)\0A\00"
@.str.16 = [10 x i8] c"accessshm\00"
@.str.18 = [6 x i8] c"hello\00"
@.str.19 = [10 x i8] c"createsem\00"
@.str.20 = [20 x i8] c"semget failed (%s)\0A\00"
@.str.21 = [14 x i8] c"semget id %d\0A\00"
@.str.23 = [23 x i8] c"./testipc accesssem %d\00"
@.str.25 = [43 x i8] c"/usr/sbin/chcontext ./testipc accesssem %d\00"
@.str.27 = [20 x i8] c"semctl failed (%s)\0A\00"
@.str.28 = [10 x i8] c"accesssem\00"
@.str.29 = [29 x i8] c"can't semop with id %d (%s)\0A\00"
@str = [47 x i8] c"Letting a sub-program play with this semaphore\00"
@str.30 = [57 x i8] c"A sub-program in another context can't use the semaphore\00"
@str.32 = [21 x i8] c"Delete the semaphore\00"
@str.33 = [31 x i8] c"\09Writing hello in share memory\00"
@str.34 = [44 x i8] c"Letting a sub-program attach to this memory\00"
@str.35 = [46 x i8] c"A sub-program in another context can't attach\00"
@str.36 = [22 x i8] c"Executing a sub-shell\00"
@str.37 = [32 x i8] c"Delete the share memory segment\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca [1 x %struct.sembuf]
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %134
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %59
15: ; preds = %10
%16 = load i32, i32* @IPC_CREAT
%17 = or i32 %16, 438
%18 = tail call i32 @shmget(i32 1, i32 1024, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = tail call i8* @strerror(i32 %22)
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %134
25: ; preds = %15
%26 = tail call i8* @shmat(i32 %18, i32* null, i32 0)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%28 = icmp eq i8* %26, null
br i1 %28, label %29, label %34
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = tail call i8* @strerror(i32 %31)
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %18, i8* %32)
br label %49
34: ; preds = %25
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%36 = tail call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.34, i64 0, i64 0))
%38 = call i32 @sprintf(i8* %35, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %18)
%39 = call i32 @system(i8* %35)
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %39)
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i8* %26)
%42 = tail call i32 @shmdt(i8* %26)
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.35, i64 0, i64 0))
%44 = call i32 @sprintf(i8* %35, i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.11, i64 0, i64 0), i32 %18)
%45 = call i32 @system(i8* %35)
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %45)
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.36, i64 0, i64 0))
%48 = tail call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i64 0, i64 0))
br label %49
49: ; preds = %34, %29
%50 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.37, i64 0, i64 0))
%51 = load i32, i32* @IPC_RMID
%52 = tail call i32 @shmctl(i32 %18, i32 %51, i32* null)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %134
54: ; preds = %49
%55 = load i32, i32* @stderr
%56 = load i32, i32* @errno
%57 = tail call i8* @strerror(i32 %56)
%58 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.15, i64 0, i64 0), i8* %57)
br label %134
59: ; preds = %10
%60 = load i8*, i8** %11
%61 = tail call i64 @strcmp(i8* %60, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.16, i64 0, i64 0))
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %77
63: ; preds = %59
%64 = getelementptr inbounds i8*, i8** %1, i64 2
%65 = load i8*, i8** %64
%66 = tail call i32 @atoi(i8* %65)
%67 = tail call i8* @shmat(i32 %66, i32* null, i32 0)
%68 = icmp eq i8* %67, inttoptr (i64 -1 to i8*)
br i1 %68, label %69, label %74
69: ; preds = %63
%70 = load i32, i32* @stderr
%71 = load i32, i32* @errno
%72 = tail call i8* @strerror(i32 %71)
%73 = tail call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %66, i8* %72)
br label %134
74: ; preds = %63
%75 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.33, i64 0, i64 0))
%76 = tail call i32 @strcpy(i8* %67, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.18, i64 0, i64 0))
br label %134
77: ; preds = %59
%78 = load i8*, i8** %11
%79 = tail call i64 @strcmp(i8* %78, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.19, i64 0, i64 0))
%80 = icmp eq i64 %79, 0
br i1 %80, label %81, label %115
81: ; preds = %77
%82 = load i32, i32* @IPC_CREAT
%83 = or i32 %82, 438
%84 = tail call i32 @semget(i32 1, i32 1, i32 %83)
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %91
86: ; preds = %81
%87 = load i32, i32* @stderr
%88 = load i32, i32* @errno
%89 = tail call i8* @strerror(i32 %88)
%90 = tail call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.20, i64 0, i64 0), i8* %89)
br label %134
91: ; preds = %81
%92 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%93 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.21, i64 0, i64 0), i32 %84)
%94 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
%95 = call i32 @sprintf(i8* %92, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.23, i64 0, i64 0), i32 %84)
%96 = call i32 @system(i8* %92)
%97 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %96)
%98 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.30, i64 0, i64 0))
%99 = call i32 @sprintf(i8* %92, i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.25, i64 0, i64 0), i32 %84)
%100 = call i32 @system(i8* %92)
%101 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %100)
%102 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.36, i64 0, i64 0))
%103 = tail call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i64 0, i64 0))
%104 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.32, i64 0, i64 0))
%105 = load i32, i32* @IPC_RMID
%106 = tail call i32 @semctl(i32 %84, i32 0, i32 %105, i32* null)
%107 = icmp eq i32 %106, -1
br i1 %107, label %108, label %113
108: ; preds = %91
%109 = load i32, i32* @stderr
%110 = load i32, i32* @errno
%111 = tail call i8* @strerror(i32 %110)
%112 = tail call i32 (i32, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.27, i64 0, i64 0), i8* %111)
br label %113
113: ; preds = %91, %108
%114 = phi i32 [ -1, %108 ], [ 0, %91 ]
br label %134
115: ; preds = %77
%116 = load i8*, i8** %11
%117 = tail call i64 @strcmp(i8* %116, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.28, i64 0, i64 0))
%118 = icmp eq i64 %117, 0
br i1 %118, label %119, label %134
119: ; preds = %115
%120 = getelementptr inbounds i8*, i8** %1, i64 2
%121 = load i8*, i8** %120
%122 = tail call i32 @atoi(i8* %121)
%123 = bitcast [1 x %struct.sembuf]* %5 to i8*
%124 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %5, i64 0, i64 0
%125 = call i32 @semop(i32 %122, %struct.sembuf* %124, i32 1)
%126 = icmp eq i32 %125, -1
br i1 %126, label %127, label %132
127: ; preds = %119
%128 = load i32, i32* @stderr
%129 = load i32, i32* @errno
%130 = call i8* @strerror(i32 %129)
%131 = call i32 (i32, i8*, ...) @fprintf(i32 %128, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.29, i64 0, i64 0), i32 %122, i8* %130)
br label %132
132: ; preds = %119, %127
%133 = phi i32 [ -1, %127 ], [ 0, %119 ]
br label %134
134: ; preds = %86, %113, %69, %74, %20, %49, %54, %132, %115, %7
%135 = phi i32 [ -1, %7 ], [ %133, %132 ], [ -1, %115 ], [ -1, %20 ], [ -1, %54 ], [ 0, %49 ], [ -1, %69 ], [ 0, %74 ], [ -1, %86 ], [ %114, %113 ]
ret i32 %135
}