#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 (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     11d4 <main+0x94>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x6b,%eax
je     11a8 <main+0x68>
jmp    1197 <main+0x57>
mov    -0x24(%rbp),%eax
sub    $0x6e,%eax
je     11be <main+0x7e>
jmp    11cf <main+0x8f>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    11cf <main+0x8f>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    1164 <main+0x24>
mov    -0x1c(%rbp),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
or     $0x1ff,%edx
mov    $0x800,%esi
call   1050 <shmget@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1209 <main+0xc9>
movl   $0x1,-0x4(%rbp)
jmp    1222 <main+0xe2>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xdf0(%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
mov    $0x8888,%r14d
lea    0xea6(%rip),%r15
mov    0x2e97(%rip),%r12
jmp    1179 <main+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12),%edi
call   1060 <atoi@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <getopt@plt>
cmp    $0x6e,%eax
je     1170 <main+0x30>
cmp    $0xffffffff,%eax
je     11a3 <main+0x63>
cmp    $0x6b,%eax
jne    1179 <main+0x39>
mov    (%r12),%edi
call   1060 <atoi@plt>
mov    %eax,%r14d
jmp    1179 <main+0x39>
mov    0x2e2e(%rip),%rax
mov    $0x1ff,%edx
or     (%rax),%edx
mov    %r14d,%edi
mov    $0x800,%esi
call   1050 <shmget@plt>
cmp    $0xffffffff,%eax
je     11d8 <main+0x98>
lea    0xe3c(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
call   1030 <printf@plt>
xor    %eax,%eax
jmp    11dd <main+0x9d>
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 = %23, %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 %24
15: ; preds = %10
%16 = load i32, i32* %6
switch i32 %16, label %23 [
i32 107, label %17
i32 110, label %20
]
17: ; preds = %15
%18 = load i32, i32* @optarg
%19 = call i32 @atoi(i32 %18)
store i32 %19, i32* %8
br label %23
20: ; preds = %15
%21 = load i32, i32* @optarg
%22 = call i32 @atoi(i32 %21)
store i32 %22, i32* %7
br label %23
23: ; preds = %15, %20, %17
br label %10
24: ; preds = %10
%25 = load i32, i32* %8
%26 = load i32, i32* @IPC_CREAT
%27 = or i32 %26, 511
%28 = call i32 @shmget(i32 %25, i32 2048, i32 %27)
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %32
31: ; preds = %24
store i32 1, i32* %3
br label %36
32: ; preds = %24
%33 = load i32, i32* %8
%34 = load i32, i32* %9
%35 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %34)
store i32 0, i32* %3
br label %36
36: ; preds = %32, %31
%37 = load i32, i32* %3
ret i32 %37
}

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) {
br label %3
3: ; preds = %8, %2
%4 = phi i32 [ %10, %8 ], [ 34952, %2 ]
br label %5
5: ; preds = %7, %3
%6 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
switch i32 %6, label %7 [
i32 -1, label %14
i32 107, label %8
i32 110, label %11
]
7: ; preds = %5, %11
br label %5
8: ; preds = %5
%9 = load i32, i32* @optarg
%10 = tail call i32 @atoi(i32 %9)
br label %3
11: ; preds = %5
%12 = load i32, i32* @optarg
%13 = tail call i32 @atoi(i32 %12)
br label %7
14: ; preds = %5
%15 = load i32, i32* @IPC_CREAT
%16 = or i32 %15, 511
%17 = tail call i32 @shmget(i32 %4, i32 2048, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %21, label %19
19: ; preds = %14
%20 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 %17)
br label %21
21: ; preds = %14, %19
%22 = phi i32 [ 0, %19 ], [ 1, %14 ]
ret i32 %22
}