#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 atoi(int /*<<< orphan*/);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, int, int);
int shmget(int, int, int);
int main(int argc, char **argv) {
  int ch;
  int num = 1;
  int key = 0x8888;
  int id;
  while ((ch = getopt(argc, argv, "k:-n:")) != -1) {
    switch ((char)ch) {
    case 'k':
      key = atoi(optarg);
      break;
    case 'n':
      num = atoi(optarg);
      break;
    }
  }
  id = shmget(key, 2048, IPC_CREAT | 0777);
  if (id == -1)
    return 1;
  printf("shmget 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   $0x1,-0x18(%rbp)
movl   $0x8888,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe8e(%rip),%rdx
call   1040 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11d5 <main+0x95>
movsbl -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x6b,%eax
je     11a9 <main+0x69>
jmp    1198 <main+0x58>
mov    -0x24(%rbp),%eax
sub    $0x6e,%eax
je     11bf <main+0x7f>
jmp    11d0 <main+0x90>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    11d0 <main+0x90>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    1164 <main+0x24>
mov    -0x1c(%rbp),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
or     $0x1ff,%edx
mov    $0x800,%esi
call   1050 <shmget@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    120a <main+0xca>
movl   $0x1,-0x4(%rbp)
jmp    1223 <main+0xe3>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xdef(%rip),%rdi
call   1030 <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
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xeac(%rip),%rdx
call   1040 <getopt@plt>
mov    $0x8888,%r14d
cmp    $0xffffffff,%eax
je     11b5 <main+0x75>
mov    0x2e8d(%rip),%r12
lea    0xe8e(%rip),%r15
jmp    119b <main+0x5b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12),%edi
call   1060 <atoi@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <getopt@plt>
cmp    $0xffffffff,%eax
je     11b5 <main+0x75>
cmp    $0x6e,%al
je     1180 <main+0x40>
movsbl %al,%eax
cmp    $0x6b,%eax
jne    1189 <main+0x49>
mov    (%r12),%edi
call   1060 <atoi@plt>
mov    %eax,%r14d
jmp    1189 <main+0x49>
mov    0x2e1c(%rip),%rax
mov    $0x1ff,%edx
or     (%rax),%edx
mov    %r14d,%edi
mov    $0x800,%esi
call   1050 <shmget@plt>
cmp    $0xffffffff,%eax
je     11ea <main+0xaa>
lea    0xe2a(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
call   1030 <printf@plt>
xor    %eax,%eax
jmp    11ef <main+0xaf>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"k:-n:\00"
@optarg = global i32 0
@IPC_CREAT = global i32 0
@.str.1 = [37 x i8] c"shmget 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 1, i32* %7
store i32 34952, i32* %8
br label %10
10: ; preds = %25, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %6
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %26
15: ; preds = %10
%16 = load i32, i32* %6
%17 = trunc i32 %16 to i8
%18 = sext i8 %17 to i32
switch i32 %18, label %25 [
i32 107, label %19
i32 110, label %22
]
19: ; preds = %15
%20 = load i32, i32* @optarg
%21 = call i32 @atoi(i32 %20)
store i32 %21, i32* %8
br label %25
22: ; preds = %15
%23 = load i32, i32* @optarg
%24 = call i32 @atoi(i32 %23)
store i32 %24, i32* %7
br label %25
25: ; preds = %15, %22, %19
br label %10
26: ; preds = %10
%27 = load i32, i32* %8
%28 = load i32, i32* @IPC_CREAT
%29 = or i32 %28, 511
%30 = call i32 @shmget(i32 %27, i32 2048, i32 %29)
store i32 %30, i32* %9
%31 = load i32, i32* %9
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %34
33: ; preds = %26
store i32 1, i32* %3
br label %38
34: ; preds = %26
%35 = load i32, i32* %8
%36 = load i32, i32* %9
%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 = [6 x i8] c"k:-n:\00"
@optarg = global i32 0
@IPC_CREAT = global i32 0
@.str.1 = [37 x i8] c"shmget 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 ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, -1
br i1 %4, label %20, label %5
5: ; preds = %2, %16
%6 = phi i32 [ %18, %16 ], [ %3, %2 ]
%7 = phi i32 [ %17, %16 ], [ 34952, %2 ]
%8 = shl i32 %6, 24
%9 = ashr exact i32 %8, 24
switch i32 %9, label %16 [
i32 107, label %10
i32 110, label %13
]
10: ; preds = %5
%11 = load i32, i32* @optarg
%12 = tail call i32 @atoi(i32 %11)
br label %16
13: ; preds = %5
%14 = load i32, i32* @optarg
%15 = tail call i32 @atoi(i32 %14)
br label %16
16: ; preds = %5, %13, %10
%17 = phi i32 [ %7, %5 ], [ %7, %13 ], [ %12, %10 ]
%18 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %5
20: ; preds = %16, %2
%21 = phi i32 [ 34952, %2 ], [ %17, %16 ]
%22 = load i32, i32* @IPC_CREAT
%23 = or i32 %22, 511
%24 = tail call i32 @shmget(i32 %21, i32 2048, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %28, label %26
26: ; preds = %20
%27 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %24)
br label %28
28: ; preds = %20, %26
%29 = phi i32 [ 0, %26 ], [ 1, %20 ]
ret i32 %29
}