#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 */
typedef int key_t;

/* Variables and functions */
int IPC_CREAT;
int IPC_EXCL;
int IPC_PRIVATE;
int atoi(char *);
int /*<<< orphan*/ err_sys(char *);
int ftok(char *, int);
int msgget(int, int);
int /*<<< orphan*/ printf(char *, ...);
int semget(int, int, int);
int shmget(int, int, int);
scalar_t__ strcasecmp(char const *, char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    printf("Usage: xsiget type <msg|sem|shm> projid\n");
    return -1;
  }
  char const *type = argv[1];
  int id = atoi(argv[2]);
  key_t key = IPC_PRIVATE;
  key = ftok("./xsiget.c", id);
  int flag = IPC_CREAT;
  flag |= IPC_EXCL;
  if (strcasecmp(type, "msg") == 0) {
    int ret = msgget(key, flag);
    if (ret < 0)
      err_sys("msgget failed");
    printf("create msgqueue %d with key 0x%08x ok\n", ret, key);
  } else if (strcasecmp(type, "sem") == 0) {
    int ret = semget(key, 1, flag);
    if (ret < 0)
      err_sys("semget failed");
    printf("create semphore %d with key 0x%08x ok\n", ret, key);
  } else if (strcasecmp(type, "shm") == 0) {
    int ret = shmget(key, 1024, flag);
    if (ret < 0)
      err_sys("shmget failed");
    printf("create share memory %d with key 0x%08x ok\n", ret, key);
  } else
    printf("unknown type %s\n", type);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11ba <main+0x3a>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1341 <main+0x1c1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe3d(%rip),%rdi
call   10a0 <ftok@plt>
mov    %eax,-0x20(%rbp)
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1050 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1266 <main+0xe6>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1030 <msgget@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    124d <main+0xcd>
lea    0xdf0(%rip),%rdi
call   1060 <err_sys@plt>
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    133a <main+0x1ba>
mov    -0x18(%rbp),%rdi
lea    0xdfc(%rip),%rsi
call   1050 <strcasecmp@plt>
cmp    $0x0,%rax
jne    12c2 <main+0x142>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%edx
mov    $0x1,%esi
call   1040 <semget@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    12a9 <main+0x129>
lea    0xdcd(%rip),%rdi
call   1060 <err_sys@plt>
mov    -0x2c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1335 <main+0x1b5>
mov    -0x18(%rbp),%rdi
lea    0xdd9(%rip),%rsi
call   1050 <strcasecmp@plt>
cmp    $0x0,%rax
jne    131e <main+0x19e>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%edx
mov    $0x400,%esi
call   1080 <shmget@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1305 <main+0x185>
lea    0xdaa(%rip),%rdi
call   1060 <err_sys@plt>
mov    -0x30(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1330 <main+0x1b0>
mov    -0x18(%rbp),%rsi
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1335 <main+0x1b5>
jmp    133a <main+0x1ba>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jg     11af <main+0x1f>
lea    0xf2b(%rip),%rdi
call   1060 <puts@plt>
mov    $0xffffffff,%ebp
jmp    12b8 <main+0x128>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rdi
call   10a0 <atoi@plt>
lea    0xe3d(%rip),%rdi
mov    %eax,%esi
call   10b0 <ftok@plt>
mov    %eax,%r14d
mov    0x2e04(%rip),%rax
mov    0x2e15(%rip),%rcx
mov    (%rcx),%ebp
or     (%rax),%ebp
lea    0xe25(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcasecmp@plt>
test   %rax,%rax
je     1233 <main+0xa3>
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcasecmp@plt>
test   %rax,%rax
je     1258 <main+0xc8>
lea    0xe6f(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcasecmp@plt>
test   %rax,%rax
je     1282 <main+0xf2>
lea    0xe98(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    12b8 <main+0x128>
mov    %r14d,%edi
mov    %ebp,%esi
call   1030 <msgget@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    124f <main+0xbf>
lea    0xdc5(%rip),%rdi
call   1070 <err_sys@plt>
lea    0xdc7(%rip),%rdi
jmp    12aa <main+0x11a>
mov    %r14d,%edi
mov    $0x1,%esi
mov    %ebp,%edx
call   1040 <semget@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1279 <main+0xe9>
lea    0xdd4(%rip),%rdi
call   1070 <err_sys@plt>
lea    0xdd6(%rip),%rdi
jmp    12aa <main+0x11a>
mov    %r14d,%edi
mov    $0x400,%esi
mov    %ebp,%edx
call   1090 <shmget@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    12a3 <main+0x113>
lea    0xde3(%rip),%rdi
call   1070 <err_sys@plt>
lea    0xde5(%rip),%rdi
xor    %ebp,%ebp
mov    %ebx,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Usage: xsiget type <msg|sem|shm> projid\0A\00"
@IPC_PRIVATE = global i32 0
@.str.1 = [11 x i8] c"./xsiget.c\00"
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@.str.2 = [4 x i8] c"msg\00"
@.str.3 = [14 x i8] c"msgget failed\00"
@.str.4 = [39 x i8] c"create msgqueue %d with key 0x%08x ok\0A\00"
@.str.5 = [4 x i8] c"sem\00"
@.str.6 = [14 x i8] c"semget failed\00"
@.str.7 = [39 x i8] c"create semphore %d with key 0x%08x ok\0A\00"
@.str.8 = [4 x i8] c"shm\00"
@.str.9 = [14 x i8] c"shmget failed\00"
@.str.10 = [43 x i8] c"create share memory %d with key 0x%08x ok\0A\00"
@.str.11 = [17 x i8] c"unknown type %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %85
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %6
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %7
%25 = load i32, i32* @IPC_PRIVATE
store i32 %25, i32* %8
%26 = load i32, i32* %7
%27 = call i32 @ftok(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %26)
store i32 %27, i32* %8
%28 = load i32, i32* @IPC_CREAT
store i32 %28, i32* %9
%29 = load i32, i32* @IPC_EXCL
%30 = load i32, i32* %9
%31 = or i32 %30, %29
store i32 %31, i32* %9
%32 = load i8*, i8** %6
%33 = call i64 @strcasecmp(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %47
35: ; preds = %17
%36 = load i32, i32* %8
%37 = load i32, i32* %9
%38 = call i32 @msgget(i32 %36, i32 %37)
store i32 %38, i32* %10
%39 = load i32, i32* %10
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %35
%44 = load i32, i32* %10
%45 = load i32, i32* %8
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %44, i32 %45)
br label %84
47: ; preds = %17
%48 = load i8*, i8** %6
%49 = call i64 @strcasecmp(i8* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %63
51: ; preds = %47
%52 = load i32, i32* %8
%53 = load i32, i32* %9
%54 = call i32 @semget(i32 %52, i32 1, i32 %53)
store i32 %54, i32* %11
%55 = load i32, i32* %11
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %51
%58 = call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %59
59: ; preds = %57, %51
%60 = load i32, i32* %11
%61 = load i32, i32* %8
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i32 %60, i32 %61)
br label %83
63: ; preds = %47
%64 = load i8*, i8** %6
%65 = call i64 @strcasecmp(i8* %64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %79
67: ; preds = %63
%68 = load i32, i32* %8
%69 = load i32, i32* %9
%70 = call i32 @shmget(i32 %68, i32 1024, i32 %69)
store i32 %70, i32* %12
%71 = load i32, i32* %12
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %67
%74 = call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
br label %75
75: ; preds = %73, %67
%76 = load i32, i32* %12
%77 = load i32, i32* %8
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.10, i64 0, i64 0), i32 %76, i32 %77)
br label %82
79: ; preds = %63
%80 = load i8*, i8** %6
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0), i8* %80)
br label %82
82: ; preds = %79, %75
br label %83
83: ; preds = %82, %59
br label %84
84: ; preds = %83, %43
store i32 0, i32* %3
br label %85
85: ; preds = %84, %15
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
@IPC_PRIVATE = global i32 0
@.str.1 = [11 x i8] c"./xsiget.c\00"
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@.str.2 = [4 x i8] c"msg\00"
@.str.3 = [14 x i8] c"msgget failed\00"
@.str.4 = [39 x i8] c"create msgqueue %d with key 0x%08x ok\0A\00"
@.str.5 = [4 x i8] c"sem\00"
@.str.6 = [14 x i8] c"semget failed\00"
@.str.7 = [39 x i8] c"create semphore %d with key 0x%08x ok\0A\00"
@.str.8 = [4 x i8] c"shm\00"
@.str.9 = [14 x i8] c"shmget failed\00"
@.str.10 = [43 x i8] c"create share memory %d with key 0x%08x ok\0A\00"
@.str.11 = [17 x i8] c"unknown type %s\0A\00"
@str = [40 x i8] c"Usage: xsiget type <msg|sem|shm> projid\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %47
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = tail call i32 @ftok(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @IPC_CREAT
%14 = load i32, i32* @IPC_EXCL
%15 = or i32 %14, %13
%16 = tail call i64 @strcasecmp(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %6
%19 = tail call i32 @msgget(i32 %12, i32 %15)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %19, i32 %12)
br label %47
25: ; preds = %6
%26 = tail call i64 @strcasecmp(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = tail call i32 @semget(i32 %12, i32 1, i32 %15)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = tail call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i32 %29, i32 %12)
br label %47
35: ; preds = %25
%36 = tail call i64 @strcasecmp(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %35
%39 = tail call i32 @shmget(i32 %12, i32 1024, i32 %15)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = tail call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
br label %43
43: ; preds = %41, %38
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.10, i64 0, i64 0), i32 %39, i32 %12)
br label %47
45: ; preds = %35
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0), i8* %8)
br label %47
47: ; preds = %23, %43, %45, %33, %4
%48 = phi i32 [ -1, %4 ], [ 0, %33 ], [ 0, %45 ], [ 0, %43 ], [ 0, %23 ]
ret i32 %48
}