#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 EOF;
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:")) != EOF) {
    switch (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)
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%eax
je     11b9 <main+0x69>
mov    -0x14(%rbp),%eax
sub    $0x6b,%eax
jne    11b4 <main+0x64>
jmp    11a3 <main+0x53>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    116d <main+0x1d>
mov    -0x18(%rbp),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
or     $0x124,%esi
call   1030 <msgget@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11e9 <main+0x99>
movl   $0x1,-0x4(%rbp)
jmp    1279 <main+0x129>
mov    -0x1c(%rbp),%edi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <msgctl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <msgctl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <msgctl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd9c(%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   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe89(%rip),%rdx
call   1070 <getopt@plt>
mov    0x2e5d(%rip),%r12
mov    $0x8888,%r14d
cmp    (%r12),%eax
jne    122c <main+0xcc>
mov    0x2e1e(%rip),%rax
mov    $0x124,%esi
or     (%rax),%esi
mov    %r14d,%edi
call   1030 <msgget@plt>
cmp    $0xffffffff,%eax
je     127a <main+0x11a>
mov    %eax,%ebp
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r14
mov    %ebp,%edi
mov    %r14,%rdx
call   1060 <msgctl@plt>
lea    0xe33(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1060 <msgctl@plt>
lea    0xe0d(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2db7(%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    127f <main+0x11f>
mov    $0x8888,%r14d
mov    0x2dbf(%rip),%r13
lea    0xdc0(%rip),%r15
jmp    1267 <main+0x107>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1070 <getopt@plt>
cmp    (%r12),%eax
je     1193 <main+0x33>
cmp    $0x6b,%eax
jne    1250 <main+0xf0>
mov    0x0(%r13),%edi
call   1080 <atoi@plt>
mov    %eax,%r14d
jmp    1250 <main+0xf0>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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