#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 */
char EOF;
int IPC_CREAT;
int atoi(int /*<<< orphan*/);
char getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, int, int);
int semget(int, int, int);
int main(int argc, char **argv) {
  char ch;
  int num = 1;
  int key = 0x8888;
  int id;
  while ((ch = getopt(argc, argv, "k:-n:")) != EOF) {
    switch (ch) {
    case 'k':
      key = atoi(optarg);
      break;
    case 'n':
      num = atoi(optarg);
      break;
    }
  }
  id = semget(key, num, IPC_CREAT | 0777);
  if (id == -1)
    return 1;
  printf("semget 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   1050 <getopt@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e5c(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11e1 <main+0xa1>
movsbl -0x11(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x6b,%eax
je     11b5 <main+0x75>
jmp    11a4 <main+0x64>
mov    -0x24(%rbp),%eax
sub    $0x6e,%eax
je     11cb <main+0x8b>
jmp    11dc <main+0x9c>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    11dc <main+0x9c>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    1164 <main+0x24>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    0x2de2(%rip),%rax
mov    (%rax),%edx
or     $0x1ff,%edx
call   1030 <semget@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1214 <main+0xd4>
movl   $0x1,-0x4(%rbp)
jmp    122d <main+0xed>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xde5(%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),%r14
mov    $0x8888,%r15d
mov    $0x1,%r12d
cmp    (%r14),%al
jne    11bb <main+0x7b>
mov    0x2e55(%rip),%rax
mov    $0x1ff,%edx
or     (%rax),%edx
mov    %r15d,%edi
mov    %r12d,%esi
call   1030 <semget@plt>
cmp    $0xffffffff,%eax
mov    $0x1,%ecx
je     11aa <main+0x6a>
lea    0xe68(%rip),%rdi
mov    %r15d,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r12d
mov    $0x8888,%r15d
lea    0xe32(%rip),%r13
jmp    11f3 <main+0xb3>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,%r12d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1050 <getopt@plt>
cmp    (%r14),%al
je     1174 <main+0x34>
movsbl %al,%eax
cmp    $0x6e,%eax
je     11d0 <main+0x90>
cmp    $0x6b,%eax
jne    11e1 <main+0xa1>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,%r15d
jmp    11e1 <main+0xa1>

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

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