#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 */
char EOF;
int IPC_CREAT;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ IPC_SET;
int /*<<< orphan*/ IPC_STAT;
int atoi(int /*<<< orphan*/);
char 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) {
  char 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    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e53(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11be <main+0x6e>
mov    -0x11(%rbp),%al
sub    $0x6b,%al
jne    11b9 <main+0x69>
jmp    11a8 <main+0x58>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    116d <main+0x1d>
mov    -0x18(%rbp),%edi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
or     $0x124,%esi
call   1030 <msgget@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11ee <main+0x9e>
movl   $0x1,-0x4(%rbp)
jmp    127e <main+0x12e>
mov    -0x1c(%rbp),%edi
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <msgctl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <msgctl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    0x2d76(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <msgctl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd97(%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),%al
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     1279 <main+0x119>
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    127e <main+0x11e>
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),%al
je     1193 <main+0x33>
cmp    $0x6b,%al
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 i8 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 i8
%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 = %25, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call signext i8 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8 %14, i8* %6
%15 = sext i8 %14 to i32
%16 = load i8, i8* @EOF
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %15, %17
br i1 %18, label %19, label %26
19: ; preds = %11
%20 = load i8, i8* %6
%21 = sext i8 %20 to i32
switch i32 %21, label %25 [
i32 107, label %22
]
22: ; preds = %19
%23 = load i32, i32* @optarg
%24 = call i32 @atoi(i32 %23)
store i32 %24, i32* %7
br label %25
25: ; preds = %19, %22
br label %11
26: ; preds = %11
%27 = load i32, i32* %7
%28 = load i32, i32* @IPC_CREAT
%29 = or i32 %28, 292
%30 = call i32 @msgget(i32 %27, i32 %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %34
33: ; preds = %26
store i32 1, i32* %3
br label %51
34: ; preds = %26
%35 = load i32, i32* %8
%36 = load i32, i32* @IPC_STAT
%37 = call i32 @msgctl(i32 %35, i32 %36, %struct.msqid_ds* %10)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %8
%41 = load i32, i32* @IPC_SET
%42 = call i32 @msgctl(i32 %40, i32 %41, %struct.msqid_ds* %10)
store i32 %42, i32* %9
%43 = load i32, i32* %9
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %8
%46 = load i32, i32* @IPC_RMID
%47 = call i32 @msgctl(i32 %45, i32 %46, %struct.msqid_ds* null)
store i32 %47, i32* %9
%48 = load i32, i32* %9
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %48)
%50 = 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 %51
51: ; preds = %34, %33
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
%struct.msqid_ds = type { i32 }
@.str = [3 x i8] c"k:\00"
@EOF = global i8 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 signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = load i8, i8* @EOF
%7 = icmp eq i8 %5, %6
br i1 %7, label %20, label %8
8: ; preds = %2, %15
%9 = phi i8 [ %17, %15 ], [ %5, %2 ]
%10 = phi i32 [ %16, %15 ], [ 34952, %2 ]
%11 = icmp eq i8 %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 signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%18 = load i8, i8* @EOF
%19 = icmp eq i8 %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
}