#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 shmid_ds {
  int dummy;
};
struct sembuf {
  int sem_num;
  int sem_op;
  void *sem_flg;
};
typedef scalar_t__ key_t;

/* Variables and functions */
int IPC_CREAT;
int IPC_EXCL;
void *IPC_NOWAIT;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ SETALL;
scalar_t__ ftok(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int semctl(int, int, int /*<<< orphan*/, ...);
int semget(scalar_t__, int, int);
int semop(int, struct sembuf *, int);
void *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmctl(int, int /*<<< orphan*/, struct shmid_ds *);
int shmdt(void *);
int shmget(scalar_t__, int, int);
int main(int argc, char *argv[]) {
  int rc, semid, shmid, i;
  key_t semkey, shmkey;
  void *shm_address;
  struct sembuf operations[2];
  struct shmid_ds shmid_struct;
  short sarray[2];
  semkey = ftok("/dev/null", 1);
  if (semkey == (key_t)-1) {
    printf("main: ftok() for sem failed\n");
    return -1;
  }
  shmkey = ftok("/dev/null", 1);
  if (shmkey == (key_t)-1) {
    printf("main: ftok() for shm failed\n");
    return -1;
  }
  semid = semget(semkey, 2, 0666 | IPC_CREAT | IPC_EXCL);
  if (semid == -1) {
    printf("main: semget() failed\n");
    return -1;
  }
  sarray[0] = 0;
  sarray[1] = 0;
  rc = semctl(semid, 1, SETALL, sarray);
  if (rc == -1) {
    printf("main: semctl() initialization failed\n");
    return -1;
  }
  shmid = shmget(shmkey, 50, 0666 | IPC_CREAT | IPC_EXCL);
  if (shmid == -1) {
    printf("main: shmget() failed\n");
    return -1;
  }
  shm_address = shmat(shmid, NULL, 0);
  if (shm_address == NULL) {
    printf("main: shmat() failed\n");
    return -1;
  }
  printf("Ready for client jobs\n");
  for (i = 0; i < 2; i++) {
    operations[0].sem_num = 1;
    operations[0].sem_op = -1;
    operations[0].sem_flg = 0;
    operations[1].sem_num = 0;
    operations[1].sem_op = 1;
    operations[1].sem_flg = IPC_NOWAIT;
    rc = semop(semid, operations, 2);
    if (rc == -1) {
      printf("main: semop() failed\n");
      return -1;
    }
    printf("Server Received : \"%s\"\n", (char *)shm_address);
    operations[0].sem_num = 0;
    operations[0].sem_op = -1;
    operations[0].sem_flg = IPC_NOWAIT;
    rc = semop(semid, operations, 1);
    if (rc == -1) {
      printf("main: semop() failed\n");
      return -1;
    }
  }
  rc = semctl(semid, 1, IPC_RMID);
  if (rc == -1) {
    printf("main: semctl() remove id failed\n");
    return -1;
  }
  rc = shmdt(shm_address);
  if (rc == -1) {
    printf("main: shmdt() failed\n");
    return -1;
  }
  rc = shmctl(shmid, IPC_RMID, &shmid_struct);
  if (rc == -1) {
    printf("main: shmctl() failed\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe53(%rip),%rdi
mov    $0x1,%esi
call   10b0 <ftok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xffffffffffffffff,-0x28(%rbp)
jne    11e0 <main+0x50>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14ee <main+0x35e>
lea    0xe19(%rip),%rdi
mov    $0x1,%esi
call   10b0 <ftok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0xffffffffffffffff,-0x30(%rbp)
jne    121a <main+0x8a>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14ee <main+0x35e>
mov    -0x28(%rbp),%rdi
mov    0x2d9b(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    0x2dbc(%rip),%rax
or     (%rax),%edx
mov    $0x2,%esi
call   1030 <semget@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1267 <main+0xd7>
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14ee <main+0x35e>
movw   $0x0,-0x6c(%rbp)
movw   $0x0,-0x6a(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d4b(%rip),%rax
mov    (%rax),%edx
lea    -0x6c(%rbp),%rcx
mov    $0x1,%esi
mov    $0x0,%al
call   1070 <semctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12b6 <main+0x126>
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14ee <main+0x35e>
mov    -0x30(%rbp),%rdi
mov    0x2cff(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    0x2d20(%rip),%rax
or     (%rax),%edx
mov    $0x32,%esi
call   1090 <shmget@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1303 <main+0x173>
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14ee <main+0x35e>
mov    -0x1c(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1080 <shmat@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    133a <main+0x1aa>
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14ee <main+0x35e>
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x20(%rbp)
jge    143c <main+0x2ac>
movl   $0x1,-0x60(%rbp)
movl   $0xffffffff,-0x5c(%rbp)
movq   $0x0,-0x58(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    0x2c64(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x2,%edx
call   10a0 <semop@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    13c3 <main+0x233>
lea    0xd15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14ee <main+0x35e>
mov    -0x38(%rbp),%rsi
lea    0xd0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x60(%rbp)
movl   $0xffffffff,-0x5c(%rbp)
mov    0x2bfe(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x1,%edx
call   10a0 <semop@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1429 <main+0x299>
lea    0xcaf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14ee <main+0x35e>
jmp    142e <main+0x29e>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    134f <main+0x1bf>
mov    -0x18(%rbp),%edi
mov    0x2b8a(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
mov    $0x0,%al
call   1070 <semctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    147b <main+0x2eb>
lea    0xc8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14ee <main+0x35e>
mov    -0x38(%rbp),%rdi
call   1040 <shmdt@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    14ab <main+0x31b>
lea    0xc7c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14ee <main+0x35e>
mov    -0x1c(%rbp),%edi
mov    0x2b1b(%rip),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%rdx
call   1060 <shmctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    14e7 <main+0x357>
lea    0xc56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14ee <main+0x35e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe4b(%rip),%rdi
mov    $0x1,%esi
call   10c0 <ftok@plt>
cmp    $0xffffffffffffffff,%rax
je     13e0 <main+0x240>
mov    %rax,%rbx
lea    0xe2d(%rip),%rdi
mov    $0x1,%esi
call   10c0 <ftok@plt>
cmp    $0xffffffffffffffff,%rax
je     13e9 <main+0x249>
mov    %rax,%rbp
mov    0x2dcf(%rip),%r14
mov    (%r14),%edx
mov    0x2df5(%rip),%r15
or     (%r15),%edx
or     $0x1b6,%edx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <semget@plt>
cmp    $0xffffffff,%eax
je     13f2 <main+0x252>
mov    %eax,%ebx
movl   $0x0,0x2c(%rsp)
mov    0x2d9d(%rip),%rax
mov    (%rax),%edx
lea    0x2c(%rsp),%rcx
mov    %ebx,%edi
mov    $0x1,%esi
xor    %eax,%eax
call   1080 <semctl@plt>
cmp    $0xffffffff,%eax
je     13fb <main+0x25b>
mov    (%r14),%edx
or     (%r15),%edx
or     $0x1b6,%edx
mov    %rbp,%rdi
mov    $0x32,%esi
call   10a0 <shmget@plt>
cmp    $0xffffffff,%eax
je     1404 <main+0x264>
mov    %eax,%ebp
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <shmat@plt>
test   %rax,%rax
je     1416 <main+0x276>
mov    %rax,%r14
lea    0xd97(%rip),%rdi
call   1040 <puts@plt>
movabs $0xffffffff00000001,%r12
ff ff ff
mov    %r12,(%rsp)
movq   $0x0,0x8(%rsp)
movabs $0x100000000,%r13
mov    %r13,0x10(%rsp)
mov    0x2d2b(%rip),%r15
mov    (%r15),%rax
mov    %rax,0x18(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   10b0 <semop@plt>
cmp    $0xffffffff,%eax
je     140d <main+0x26d>
lea    0xd26(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
movabs $0xffffffff00000000,%rax
ff ff ff
mov    %rax,(%rsp)
mov    (%r15),%rax
mov    %rax,0x8(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   10b0 <semop@plt>
cmp    $0xffffffff,%eax
je     140d <main+0x26d>
mov    %r12,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %r13,0x10(%rsp)
mov    (%r15),%rax
mov    %rax,0x18(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   10b0 <semop@plt>
cmp    $0xffffffff,%eax
je     140d <main+0x26d>
lea    0xcb5(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
movabs $0xffffffff00000000,%rax
ff ff ff
mov    %rax,(%rsp)
mov    (%r15),%rax
mov    %rax,0x8(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   10b0 <semop@plt>
cmp    $0xffffffff,%eax
je     140d <main+0x26d>
mov    0x2c3c(%rip),%r15
mov    (%r15),%edx
mov    %ebx,%edi
mov    $0x1,%esi
xor    %eax,%eax
call   1080 <semctl@plt>
cmp    $0xffffffff,%eax
je     1436 <main+0x296>
mov    %r14,%rdi
call   1050 <shmdt@plt>
cmp    $0xffffffff,%eax
je     143f <main+0x29f>
mov    (%r15),%esi
lea    0x30(%rsp),%rdx
mov    %ebp,%edi
call   1070 <shmctl@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1427 <main+0x287>
lea    0xc5a(%rip),%rdi
jmp    141d <main+0x27d>
lea    0xd33(%rip),%rdi
jmp    141d <main+0x27d>
lea    0xd0e(%rip),%rdi
jmp    141d <main+0x27d>
lea    0xcef(%rip),%rdi
jmp    141d <main+0x27d>
lea    0xcc1(%rip),%rdi
jmp    141d <main+0x27d>
lea    0xca2(%rip),%rdi
jmp    141d <main+0x27d>
lea    0xc6f(%rip),%rdi
jmp    141d <main+0x27d>
lea    0xc7b(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc26(%rip),%rdi
jmp    141d <main+0x27d>
lea    0xc08(%rip),%rdi
jmp    141d <main+0x27d>

LLVM IR (-O0):
%struct.sembuf = type { i32, i32, i8* }
%struct.shmid_ds = type { i32 }
@.str = [10 x i8] c"/dev/null\00"
@.str.1 = [29 x i8] c"main: ftok() for sem failed\0A\00"
@.str.2 = [29 x i8] c"main: ftok() for shm failed\0A\00"
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@.str.3 = [23 x i8] c"main: semget() failed\0A\00"
@SETALL = global i32 0
@.str.4 = [38 x i8] c"main: semctl() initialization failed\0A\00"
@.str.5 = [23 x i8] c"main: shmget() failed\0A\00"
@.str.6 = [22 x i8] c"main: shmat() failed\0A\00"
@.str.7 = [23 x i8] c"Ready for client jobs\0A\00"
@IPC_NOWAIT = global i8* null
@.str.8 = [22 x i8] c"main: semop() failed\0A\00"
@.str.9 = [24 x i8] c"Server Received : \22%s\22\0A\00"
@IPC_RMID = global i32 0
@.str.10 = [33 x i8] c"main: semctl() remove id failed\0A\00"
@.str.11 = [22 x i8] c"main: shmdt() failed\0A\00"
@.str.12 = [23 x i8] c"main: shmctl() failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca [2 x %struct.sembuf]
%14 = alloca %struct.shmid_ds
%15 = alloca [2 x i16]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = call i64 @ftok(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 1)
store i64 %16, i64* %10
%17 = load i64, i64* %10
%18 = icmp eq i64 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %138
21: ; preds = %2
%22 = call i64 @ftok(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 1)
store i64 %22, i64* %11
%23 = load i64, i64* %11
%24 = icmp eq i64 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %138
27: ; preds = %21
%28 = load i64, i64* %10
%29 = load i32, i32* @IPC_CREAT
%30 = or i32 438, %29
%31 = load i32, i32* @IPC_EXCL
%32 = or i32 %30, %31
%33 = call i32 @semget(i64 %28, i32 2, i32 %32)
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %27
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %138
38: ; preds = %27
%39 = getelementptr inbounds [2 x i16], [2 x i16]* %15, i64 0, i64 0
store i16 0, i16* %39
%40 = getelementptr inbounds [2 x i16], [2 x i16]* %15, i64 0, i64 1
store i16 0, i16* %40
%41 = load i32, i32* %7
%42 = load i32, i32* @SETALL
%43 = getelementptr inbounds [2 x i16], [2 x i16]* %15, i64 0, i64 0
%44 = call i32 (i32, i32, i32, ...) @semctl(i32 %41, i32 1, i32 %42, i16* %43)
store i32 %44, i32* %6
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %38
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %138
49: ; preds = %38
%50 = load i64, i64* %11
%51 = load i32, i32* @IPC_CREAT
%52 = or i32 438, %51
%53 = load i32, i32* @IPC_EXCL
%54 = or i32 %52, %53
%55 = call i32 @shmget(i64 %50, i32 50, i32 %54)
store i32 %55, i32* %8
%56 = load i32, i32* %8
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %60
58: ; preds = %49
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %138
60: ; preds = %49
%61 = load i32, i32* %8
%62 = call i8* @shmat(i32 %61, i32* null, i32 0)
store i8* %62, i8** %12
%63 = load i8*, i8** %12
%64 = icmp eq i8* %63, null
br i1 %64, label %65, label %67
65: ; preds = %60
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %138
67: ; preds = %60
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %9
br label %69
69: ; preds = %111, %67
%70 = load i32, i32* %9
%71 = icmp slt i32 %70, 2
br i1 %71, label %72, label %114
72: ; preds = %69
%73 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %13, i64 0, i64 0
%74 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %73, i32 0, i32 0
store i32 1, i32* %74
%75 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %13, i64 0, i64 0
%76 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %75, i32 0, i32 1
store i32 -1, i32* %76
%77 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %13, i64 0, i64 0
%78 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %77, i32 0, i32 2
store i8* null, i8** %78
%79 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %13, i64 0, i64 1
%80 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %79, i32 0, i32 0
store i32 0, i32* %80
%81 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %13, i64 0, i64 1
%82 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %81, i32 0, i32 1
store i32 1, i32* %82
%83 = load i8*, i8** @IPC_NOWAIT
%84 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %13, i64 0, i64 1
%85 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %84, i32 0, i32 2
store i8* %83, i8** %85
%86 = load i32, i32* %7
%87 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %13, i64 0, i64 0
%88 = call i32 @semop(i32 %86, %struct.sembuf* %87, i32 2)
store i32 %88, i32* %6
%89 = load i32, i32* %6
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %93
91: ; preds = %72
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %3
br label %138
93: ; preds = %72
%94 = load i8*, i8** %12
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i8* %94)
%96 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %13, i64 0, i64 0
%97 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %96, i32 0, i32 0
store i32 0, i32* %97
%98 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %13, i64 0, i64 0
%99 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %98, i32 0, i32 1
store i32 -1, i32* %99
%100 = load i8*, i8** @IPC_NOWAIT
%101 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %13, i64 0, i64 0
%102 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %101, i32 0, i32 2
store i8* %100, i8** %102
%103 = load i32, i32* %7
%104 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %13, i64 0, i64 0
%105 = call i32 @semop(i32 %103, %struct.sembuf* %104, i32 1)
store i32 %105, i32* %6
%106 = load i32, i32* %6
%107 = icmp eq i32 %106, -1
br i1 %107, label %108, label %110
108: ; preds = %93
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %3
br label %138
110: ; preds = %93
br label %111
111: ; preds = %110
%112 = load i32, i32* %9
%113 = add nsw i32 %112, 1
store i32 %113, i32* %9
br label %69
114: ; preds = %69
%115 = load i32, i32* %7
%116 = load i32, i32* @IPC_RMID
%117 = call i32 (i32, i32, i32, ...) @semctl(i32 %115, i32 1, i32 %116)
store i32 %117, i32* %6
%118 = load i32, i32* %6
%119 = icmp eq i32 %118, -1
br i1 %119, label %120, label %122
120: ; preds = %114
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
store i32 -1, i32* %3
br label %138
122: ; preds = %114
%123 = load i8*, i8** %12
%124 = call i32 @shmdt(i8* %123)
store i32 %124, i32* %6
%125 = load i32, i32* %6
%126 = icmp eq i32 %125, -1
br i1 %126, label %127, label %129
127: ; preds = %122
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0))
store i32 -1, i32* %3
br label %138
129: ; preds = %122
%130 = load i32, i32* %8
%131 = load i32, i32* @IPC_RMID
%132 = call i32 @shmctl(i32 %130, i32 %131, %struct.shmid_ds* %14)
store i32 %132, i32* %6
%133 = load i32, i32* %6
%134 = icmp eq i32 %133, -1
br i1 %134, label %135, label %137
135: ; preds = %129
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.12, i64 0, i64 0))
store i32 -1, i32* %3
br label %138
137: ; preds = %129
store i32 0, i32* %3
br label %138
138: ; preds = %137, %135, %127, %120, %108, %91, %65, %58, %47, %36, %25, %19
%139 = load i32, i32* %3
ret i32 %139
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i8* }
%struct.shmid_ds = type { i32 }
@.str = [10 x i8] c"/dev/null\00"
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@SETALL = global i32 0
@IPC_NOWAIT = global i8* null
@.str.9 = [24 x i8] c"Server Received : \22%s\22\0A\00"
@IPC_RMID = global i32 0
@str = [22 x i8] c"Ready for client jobs\00"
@str.13 = [22 x i8] c"main: shmctl() failed\00"
@str.14 = [21 x i8] c"main: shmdt() failed\00"
@str.15 = [32 x i8] c"main: semctl() remove id failed\00"
@str.17 = [21 x i8] c"main: semop() failed\00"
@str.18 = [21 x i8] c"main: shmat() failed\00"
@str.19 = [22 x i8] c"main: shmget() failed\00"
@str.20 = [37 x i8] c"main: semctl() initialization failed\00"
@str.21 = [22 x i8] c"main: semget() failed\00"
@str.22 = [28 x i8] c"main: ftok() for shm failed\00"
@str.23 = [28 x i8] c"main: ftok() for sem failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x %struct.sembuf]
%4 = alloca %struct.shmid_ds
%5 = alloca [2 x i16]
%6 = bitcast [2 x %struct.sembuf]* %3 to i8*
%7 = bitcast %struct.shmid_ds* %4 to i8*
%8 = bitcast [2 x i16]* %5 to i8*
%9 = tail call i64 @ftok(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 1)
%10 = icmp eq i64 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.23, i64 0, i64 0))
br label %96
13: ; preds = %2
%14 = tail call i64 @ftok(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 1)
%15 = icmp eq i64 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.22, i64 0, i64 0))
br label %96
18: ; preds = %13
%19 = load i32, i32* @IPC_CREAT
%20 = load i32, i32* @IPC_EXCL
%21 = or i32 %19, %20
%22 = or i32 %21, 438
%23 = tail call i32 @semget(i64 %9, i32 2, i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.21, i64 0, i64 0))
br label %96
27: ; preds = %18
%28 = getelementptr inbounds [2 x i16], [2 x i16]* %5, i64 0, i64 0
store i16 0, i16* %28
%29 = getelementptr inbounds [2 x i16], [2 x i16]* %5, i64 0, i64 1
store i16 0, i16* %29
%30 = load i32, i32* @SETALL
%31 = call i32 (i32, i32, i32, ...) @semctl(i32 %23, i32 1, i32 %30, i16* %28)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.20, i64 0, i64 0))
br label %96
35: ; preds = %27
%36 = load i32, i32* @IPC_CREAT
%37 = load i32, i32* @IPC_EXCL
%38 = or i32 %36, %37
%39 = or i32 %38, 438
%40 = call i32 @shmget(i64 %14, i32 50, i32 %39)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %35
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.19, i64 0, i64 0))
br label %96
44: ; preds = %35
%45 = call i8* @shmat(i32 %40, i32* null, i32 0)
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.18, i64 0, i64 0))
br label %96
49: ; preds = %44
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%51 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %3, i64 0, i64 0
%52 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %3, i64 0, i64 0, i32 0
%53 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %3, i64 0, i64 0, i32 1
%54 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %3, i64 0, i64 0, i32 2
%55 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %3, i64 0, i64 1, i32 0
%56 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %3, i64 0, i64 1, i32 1
%57 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %3, i64 0, i64 1, i32 2
store i32 1, i32* %52
store i32 -1, i32* %53
store i8* null, i8** %54
store i32 0, i32* %55
store i32 1, i32* %56
%58 = load i8*, i8** @IPC_NOWAIT
store i8* %58, i8** %57
%59 = call i32 @semop(i32 %23, %struct.sembuf* %51, i32 2)
%60 = icmp eq i32 %59, -1
br i1 %60, label %74, label %76
61: ; preds = %76
store i32 1, i32* %52
store i32 -1, i32* %53
store i8* null, i8** %54
store i32 0, i32* %55
store i32 1, i32* %56
%62 = load i8*, i8** @IPC_NOWAIT
store i8* %62, i8** %57
%63 = call i32 @semop(i32 %23, %struct.sembuf* %51, i32 2)
%64 = icmp eq i32 %63, -1
br i1 %64, label %74, label %65
65: ; preds = %61
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i8* %45)
store i32 0, i32* %52
store i32 -1, i32* %53
%67 = load i8*, i8** @IPC_NOWAIT
store i8* %67, i8** %54
%68 = call i32 @semop(i32 %23, %struct.sembuf* %51, i32 1)
%69 = icmp eq i32 %68, -1
br i1 %69, label %81, label %70
70: ; preds = %65
%71 = load i32, i32* @IPC_RMID
%72 = call i32 (i32, i32, i32, ...) @semctl(i32 %23, i32 1, i32 %71)
%73 = icmp eq i32 %72, -1
br i1 %73, label %83, label %85
74: ; preds = %61, %49
%75 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.17, i64 0, i64 0))
br label %96
76: ; preds = %49
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i8* %45)
store i32 0, i32* %52
store i32 -1, i32* %53
%78 = load i8*, i8** @IPC_NOWAIT
store i8* %78, i8** %54
%79 = call i32 @semop(i32 %23, %struct.sembuf* %51, i32 1)
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %61
81: ; preds = %65, %76
%82 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.17, i64 0, i64 0))
br label %96
83: ; preds = %70
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.15, i64 0, i64 0))
br label %96
85: ; preds = %70
%86 = call i32 @shmdt(i8* %45)
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %90
88: ; preds = %85
%89 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.14, i64 0, i64 0))
br label %96
90: ; preds = %85
%91 = load i32, i32* @IPC_RMID
%92 = call i32 @shmctl(i32 %40, i32 %91, %struct.shmid_ds* %4)
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %96
94: ; preds = %90
%95 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.13, i64 0, i64 0))
br label %96
96: ; preds = %90, %94, %88, %83, %81, %74, %47, %42, %33, %25, %16, %11
%97 = phi i32 [ -1, %11 ], [ -1, %16 ], [ -1, %25 ], [ -1, %33 ], [ -1, %42 ], [ -1, %47 ], [ -1, %74 ], [ -1, %81 ], [ -1, %83 ], [ -1, %88 ], [ -1, %94 ], [ 0, %90 ]
ret i32 %97
}