#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 EOF;
int IPC_CREAT;
int atoi(int /*<<< orphan*/);
int getopt(int, char **, char *);
int msgget(int, int);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, int, int);
int main(int argc, char **argv) {
  int ch;
  int key = 0x8888;
  int id;
  int perms = 0444;
  while ((ch = getopt(argc, argv, "k:p:")) != EOF) {
    switch (ch) {
    case 'k':
      key = atoi(optarg);
      break;
    case 'p':
      perms = atoi(optarg);
      break;
    }
  }
  id = msgget(key, IPC_CREAT | perms);
  if (id == -1)
    return 1;
  printf("msgget succeeded: key = %d, id = %d\n", key, id);
  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)
movl   $0x124,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe8e(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e5f(%rip),%rcx
cmp    (%rcx),%eax
je     11da <main+0x9a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x6b,%eax
je     11ae <main+0x6e>
jmp    119d <main+0x5d>
mov    -0x24(%rbp),%eax
sub    $0x70,%eax
je     11c4 <main+0x84>
jmp    11d5 <main+0x95>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    11d5 <main+0x95>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    1164 <main+0x24>
mov    -0x18(%rbp),%edi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
or     -0x20(%rbp),%esi
call   1030 <msgget@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1207 <main+0xc7>
movl   $0x1,-0x4(%rbp)
jmp    1220 <main+0xe0>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xdf1(%rip),%rdi
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    0xea9(%rip),%rdx
call   1050 <getopt@plt>
mov    0x2e7d(%rip),%r13
cmp    0x0(%r13),%eax
jne    11a4 <main+0x64>
mov    $0x124,%r15d
mov    $0x8888,%r14d
mov    0x2e54(%rip),%rax
or     (%rax),%r15d
mov    %r14d,%edi
mov    %r15d,%esi
call   1030 <msgget@plt>
cmp    $0xffffffff,%eax
je     1201 <main+0xc1>
lea    0xe6f(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
jmp    1206 <main+0xc6>
mov    $0x8888,%r14d
mov    $0x124,%r15d
lea    0xe49(%rip),%r12
jmp    11e4 <main+0xa4>
nopl   0x0(%rax)
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,%r15d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1050 <getopt@plt>
cmp    0x0(%r13),%eax
je     1175 <main+0x35>
cmp    $0x70,%eax
je     11c0 <main+0x80>
cmp    $0x6b,%eax
jne    11d1 <main+0x91>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,%r14d
jmp    11d1 <main+0x91>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"k:p:\00"
@EOF = global i32 0
@optarg = global i32 0
@IPC_CREAT = global i32 0
@.str.1 = [37 x i8] c"msgget succeeded: key = %d, id = %d\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 34952, i32* %7
store i32 292, i32* %9
br label %10
10: ; preds = %24, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %6
%14 = load i32, i32* @EOF
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %25
16: ; preds = %10
%17 = load i32, i32* %6
switch i32 %17, label %24 [
i32 107, label %18
i32 112, label %21
]
18: ; preds = %16
%19 = load i32, i32* @optarg
%20 = call i32 @atoi(i32 %19)
store i32 %20, i32* %7
br label %24
21: ; preds = %16
%22 = load i32, i32* @optarg
%23 = call i32 @atoi(i32 %22)
store i32 %23, i32* %9
br label %24
24: ; preds = %16, %21, %18
br label %10
25: ; preds = %10
%26 = load i32, i32* %7
%27 = load i32, i32* @IPC_CREAT
%28 = load i32, i32* %9
%29 = or i32 %27, %28
%30 = call i32 @msgget(i32 %26, 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 = %25
store i32 1, i32* %3
br label %38
34: ; preds = %25
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %35, i32 %36)
store i32 0, i32* %3
br label %38
38: ; preds = %34, %33
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [5 x i8] c"k:p:\00"
@EOF = global i32 0
@optarg = global i32 0
@IPC_CREAT = global i32 0
@.str.1 = [37 x i8] c"msgget succeeded: key = %d, id = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %22, label %6
6: ; preds = %2, %16
%7 = phi i32 [ %19, %16 ], [ %3, %2 ]
%8 = phi i32 [ %18, %16 ], [ 292, %2 ]
%9 = phi i32 [ %17, %16 ], [ 34952, %2 ]
switch i32 %7, label %16 [
i32 107, label %10
i32 112, label %13
]
10: ; preds = %6
%11 = load i32, i32* @optarg
%12 = tail call i32 @atoi(i32 %11)
br label %16
13: ; preds = %6
%14 = load i32, i32* @optarg
%15 = tail call i32 @atoi(i32 %14)
br label %16
16: ; preds = %6, %13, %10
%17 = phi i32 [ %9, %6 ], [ %9, %13 ], [ %12, %10 ]
%18 = phi i32 [ %8, %6 ], [ %15, %13 ], [ %8, %10 ]
%19 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %6
22: ; preds = %16, %2
%23 = phi i32 [ 34952, %2 ], [ %17, %16 ]
%24 = phi i32 [ 292, %2 ], [ %18, %16 ]
%25 = load i32, i32* @IPC_CREAT
%26 = or i32 %25, %24
%27 = tail call i32 @msgget(i32 %23, i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %31, label %29
29: ; preds = %22
%30 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %27)
br label %31
31: ; preds = %22, %29
%32 = phi i32 [ 0, %29 ], [ 1, %22 ]
ret i32 %32
}