#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 msqid_ds {
  int dummy;
};

/* Variables and functions */
int IPC_CREAT;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ IPC_SET;
int /*<<< orphan*/ IPC_STAT;
int atoi(int /*<<< orphan*/);
int getopt(int, char **, char *);
int msgctl(int, int /*<<< orphan*/, struct msqid_ds *);
int msgget(int, int);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int ch;
  int key = 0x8888;
  int id;
  int error;
  struct msqid_ds buf;
  while ((ch = getopt(argc, argv, "k:")) != -1) {
    switch ((char)ch) {
    case 'k':
      key = atoi(optarg);
      break;
    }
  }
  id = msgget(key, IPC_CREAT | 0444);
  if (id == -1)
    return 1;
  error = msgctl(id, IPC_STAT, &buf);
  printf("%d", error);
  error = msgctl(id, IPC_SET, &buf);
  printf(" %d", error);
  error = msgctl(id, IPC_RMID, 0);
  printf(" %d", error);
  printf("\n");
  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)
movl   $0x8888,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe85(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11b2 <main+0x62>
mov    -0x14(%rbp),%al
sub    $0x6b,%al
jne    11ad <main+0x5d>
jmp    119c <main+0x4c>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    116d <main+0x1d>
mov    -0x18(%rbp),%edi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
or     $0x124,%esi
call   1030 <msgget@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11e2 <main+0x92>
movl   $0x1,-0x4(%rbp)
jmp    1272 <main+0x122>
mov    -0x1c(%rbp),%edi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <msgctl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <msgctl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <msgctl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe88(%rip),%rdx
call   1070 <getopt@plt>
mov    $0x8888,%r14d
cmp    $0xffffffff,%eax
je     11c4 <main+0x64>
mov    0x2e69(%rip),%r12
lea    0xe6a(%rip),%r15
jmp    11b2 <main+0x52>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1070 <getopt@plt>
cmp    $0xffffffff,%eax
je     11c4 <main+0x64>
cmp    $0x6b,%al
jne    11a0 <main+0x40>
mov    (%r12),%edi
call   1080 <atoi@plt>
mov    %eax,%r14d
jmp    11a0 <main+0x40>
mov    0x2df5(%rip),%rax
mov    $0x124,%esi
or     (%rax),%esi
mov    %r14d,%edi
call   1030 <msgget@plt>
cmp    $0xffffffff,%eax
je     125b <main+0xfb>
mov    %eax,%ebp
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%r14
mov    %ebp,%edi
mov    %r14,%rdx
call   1060 <msgctl@plt>
lea    0xe04(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1060 <msgctl@plt>
lea    0xdde(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1060 <msgctl@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    1260 <main+0x100>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.msqid_ds = type { i32 }
@.str = [3 x i8] c"k:\00"
@optarg = global i32 0
@IPC_CREAT = global i32 0
@IPC_STAT = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@IPC_SET = global i32 0
@.str.2 = [4 x i8] c" %d\00"
@IPC_RMID = global i32 0
@.str.3 = [2 x i8] c"\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 %struct.msqid_ds
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 34952, i32* %7
br label %11
11: ; preds = %23, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %6
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = load i32, i32* %6
%18 = trunc i32 %17 to i8
%19 = sext i8 %18 to i32
switch i32 %19, label %23 [
i32 107, label %20
]
20: ; preds = %16
%21 = load i32, i32* @optarg
%22 = call i32 @atoi(i32 %21)
store i32 %22, i32* %7
br label %23
23: ; preds = %16, %20
br label %11
24: ; preds = %11
%25 = load i32, i32* %7
%26 = load i32, i32* @IPC_CREAT
%27 = or i32 %26, 292
%28 = call i32 @msgget(i32 %25, i32 %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %32
31: ; preds = %24
store i32 1, i32* %3
br label %49
32: ; preds = %24
%33 = load i32, i32* %8
%34 = load i32, i32* @IPC_STAT
%35 = call i32 @msgctl(i32 %33, i32 %34, %struct.msqid_ds* %10)
store i32 %35, i32* %9
%36 = load i32, i32* %9
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %8
%39 = load i32, i32* @IPC_SET
%40 = call i32 @msgctl(i32 %38, i32 %39, %struct.msqid_ds* %10)
store i32 %40, i32* %9
%41 = load i32, i32* %9
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %8
%44 = load i32, i32* @IPC_RMID
%45 = call i32 @msgctl(i32 %43, i32 %44, %struct.msqid_ds* null)
store i32 %45, i32* %9
%46 = load i32, i32* %9
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %49
49: ; preds = %32, %31
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
%struct.msqid_ds = type { i32 }
@.str = [3 x i8] c"k:\00"
@optarg = global i32 0
@IPC_CREAT = global i32 0
@IPC_STAT = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@IPC_SET = global i32 0
@.str.2 = [4 x i8] c" %d\00"
@IPC_RMID = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.msqid_ds
%4 = bitcast %struct.msqid_ds* %3 to i8*
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, -1
br i1 %6, label %19, label %7
7: ; preds = %2, %15
%8 = phi i32 [ %17, %15 ], [ %5, %2 ]
%9 = phi i32 [ %16, %15 ], [ 34952, %2 ]
%10 = and i32 %8, 255
%11 = icmp eq i32 %10, 107
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i32, i32* @optarg
%14 = tail call i32 @atoi(i32 %13)
br label %15
15: ; preds = %7, %12
%16 = phi i32 [ %14, %12 ], [ %9, %7 ]
%17 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %7
19: ; preds = %15, %2
%20 = phi i32 [ 34952, %2 ], [ %16, %15 ]
%21 = load i32, i32* @IPC_CREAT
%22 = or i32 %21, 292
%23 = tail call i32 @msgget(i32 %20, i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %36, label %25
25: ; preds = %19
%26 = load i32, i32* @IPC_STAT
%27 = call i32 @msgctl(i32 %23, i32 %26, %struct.msqid_ds* %3)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i32, i32* @IPC_SET
%30 = call i32 @msgctl(i32 %23, i32 %29, %struct.msqid_ds* %3)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = load i32, i32* @IPC_RMID
%33 = call i32 @msgctl(i32 %23, i32 %32, %struct.msqid_ds* null)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = call i32 @putchar(i32 10)
br label %36
36: ; preds = %19, %25
%37 = phi i32 [ 0, %25 ], [ 1, %19 ]
ret i32 %37
}