#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 key = 0x8888;
  int id;
  while ((ch = getopt(argc, argv, "k:")) != -1) {
    switch (ch) {
    case 'k':
      key = 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    $0x20,%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    0xe95(%rip),%rdx
call   1040 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11a3 <main+0x63>
mov    -0x14(%rbp),%eax
sub    $0x6b,%eax
jne    119e <main+0x5e>
jmp    118d <main+0x4d>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    115d <main+0x1d>
mov    -0x18(%rbp),%edi
mov    0x2e2b(%rip),%rax
mov    (%rax),%edx
or     $0x1ff,%edx
mov    $0x800,%esi
call   1050 <shmget@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11d8 <main+0x98>
movl   $0x1,-0x4(%rbp)
jmp    11f1 <main+0xb1>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe1e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%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
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <getopt@plt>
cmp    $0xffffffff,%eax
je     1195 <main+0x55>
cmp    $0x6b,%eax
jne    1170 <main+0x30>
mov    (%r12),%edi
call   1060 <atoi@plt>
mov    %eax,%r14d
jmp    1170 <main+0x30>
mov    0x2e3c(%rip),%rax
mov    $0x1ff,%edx
or     (%rax),%edx
mov    %r14d,%edi
mov    $0x800,%esi
call   1050 <shmget@plt>
cmp    $0xffffffff,%eax
je     11ca <main+0x8a>
lea    0xe47(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
call   1030 <printf@plt>
xor    %eax,%eax
jmp    11cf <main+0x8f>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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