#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 */

/* Variables and functions */
int IPC_CREAT;
int IPC_EXCL;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ StatShm(int);
int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
scalar_t__ shmget(int, int, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int shmid, size;
  if (argc != 3)
    return 0;
  shmid = atoi(argv[1]);
  if (strcmp(argv[2], "v") == 0) {
    StatShm(shmid);
  } else if (strcmp(argv[2], "d") == 0) {
    if (shmctl(shmid, IPC_RMID, NULL) < 0)
      fprintf(stderr, "%s failed.\n", "Delete Shm");
    else
      fprintf(stderr, "%s success.\n", "Delete Shm");
    ;
  } else {
    size = atoi(argv[2]);
    if (shmget(shmid, size, 0666 | IPC_CREAT | IPC_EXCL) < 0)
      fprintf(stderr, "%s failed.\n", "Create Shm");
    else
      fprintf(stderr, "%s success.\n", "Create Shm");
    ;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     118c <main+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    12d1 <main+0x171>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe55(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11c7 <main+0x67>
mov    -0x14(%rbp),%edi
call   1030 <StatShm@plt>
jmp    12ca <main+0x16a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe2c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1246 <main+0xe6>
mov    -0x14(%rbp),%edi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <shmctl@plt>
cmp    $0x0,%rax
jge    1225 <main+0xc5>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xdf0(%rip),%rsi
lea    0xdf5(%rip),%rdx
call   1050 <fprintf@plt>
jmp    1241 <main+0xe1>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
lea    0xdd4(%rip),%rdx
call   1050 <fprintf@plt>
jmp    12c5 <main+0x165>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    0x2d65(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    0x2d7e(%rip),%rax
or     (%rax),%edx
call   1070 <shmget@plt>
cmp    $0x0,%rax
jge    12a4 <main+0x144>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
lea    0xd71(%rip),%rsi
lea    0xd8e(%rip),%rdx
call   1050 <fprintf@plt>
jmp    12c0 <main+0x160>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
lea    0xd67(%rip),%rsi
lea    0xd6d(%rip),%rdx
call   1050 <fprintf@plt>
jmp    12c5 <main+0x165>
jmp    12ca <main+0x16a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    1231 <main+0xd1>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
lea    0xe7b(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11e5 <main+0x85>
mov    0x10(%rbx),%rdi
lea    0xe68(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11ee <main+0x8e>
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
mov    0x2e14(%rip),%rcx
mov    (%rcx),%edx
mov    0x2e33(%rip),%rcx
or     (%rcx),%edx
or     $0x1b6,%edx
mov    %ebp,%edi
mov    %eax,%esi
call   1070 <shmget@plt>
mov    0x2e03(%rip),%rcx
mov    (%rcx),%edi
test   %rax,%rax
js     121e <main+0xbe>
lea    0xe38(%rip),%rsi
jmp    1225 <main+0xc5>
mov    %ebp,%edi
call   1030 <StatShm@plt>
jmp    1231 <main+0xd1>
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1060 <shmctl@plt>
mov    0x2dd1(%rip),%rcx
mov    (%rcx),%edi
test   %rax,%rax
js     123a <main+0xda>
lea    0xe06(%rip),%rsi
lea    0xdf4(%rip),%rdx
jmp    122c <main+0xcc>
lea    0xddf(%rip),%rsi
lea    0xdfc(%rip),%rdx
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdc3(%rip),%rsi
lea    0xdc8(%rip),%rdx
jmp    122c <main+0xcc>

LLVM IR (-O0):
@.str = [2 x i8] c"v\00"
@.str.1 = [2 x i8] c"d\00"
@IPC_RMID = global i32 0
@stderr = global i32 0
@.str.2 = [12 x i8] c"%s failed.\0A\00"
@.str.3 = [11 x i8] c"Delete Shm\00"
@.str.4 = [13 x i8] c"%s success.\0A\00"
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@.str.5 = [11 x i8] c"Create Shm\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %3
br label %64
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %6
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %11
%22 = load i32, i32* %6
%23 = call i32 @StatShm(i32 %22)
br label %63
24: ; preds = %11
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %42
30: ; preds = %24
%31 = load i32, i32* %6
%32 = load i32, i32* @IPC_RMID
%33 = call i64 @shmctl(i32 %31, i32 %32, i32* null)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %41
38: ; preds = %30
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %38, %35
br label %62
42: ; preds = %24
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @atoi(i8* %45)
store i32 %46, i32* %7
%47 = load i32, i32* %6
%48 = load i32, i32* %7
%49 = load i32, i32* @IPC_CREAT
%50 = or i32 438, %49
%51 = load i32, i32* @IPC_EXCL
%52 = or i32 %50, %51
%53 = call i64 @shmget(i32 %47, i32 %48, i32 %52)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %42
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %61
58: ; preds = %42
%59 = load i32, i32* @stderr
%60 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %61
61: ; preds = %58, %55
br label %62
62: ; preds = %61, %41
br label %63
63: ; preds = %62, %21
store i32 0, i32* %3
br label %64
64: ; preds = %63, %10
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [2 x i8] c"v\00"
@.str.1 = [2 x i8] c"d\00"
@IPC_RMID = global i32 0
@stderr = global i32 0
@.str.2 = [12 x i8] c"%s failed.\0A\00"
@.str.3 = [11 x i8] c"Delete Shm\00"
@.str.4 = [13 x i8] c"%s success.\0A\00"
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@.str.5 = [11 x i8] c"Create Shm\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %4, label %41
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = tail call i32 @StatShm(i32 %7)
br label %41
14: ; preds = %4
%15 = load i8*, i8** %8
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = load i32, i32* @IPC_RMID
%20 = tail call i64 @shmctl(i32 %7, i32 %19, i32* null)
%21 = icmp slt i64 %20, 0
%22 = load i32, i32* @stderr
br i1 %21, label %23, label %25
23: ; preds = %18
%24 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %41
25: ; preds = %18
%26 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %41
27: ; preds = %14
%28 = load i8*, i8** %8
%29 = tail call i32 @atoi(i8* %28)
%30 = load i32, i32* @IPC_CREAT
%31 = load i32, i32* @IPC_EXCL
%32 = or i32 %30, %31
%33 = or i32 %32, 438
%34 = tail call i64 @shmget(i32 %7, i32 %29, i32 %33)
%35 = icmp slt i64 %34, 0
%36 = load i32, i32* @stderr
br i1 %35, label %37, label %39
37: ; preds = %27
%38 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %41
39: ; preds = %27
%40 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %41
41: ; preds = %12, %37, %39, %23, %25, %2
ret i32 0
}