#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 EXIT_SUCCESS;
int IPC_CREAT;
int IPC_EXCL;
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ ftok(char *, int /*<<< orphan*/);
int getopt(int, char **, char *);
int optind;
int /*<<< orphan*/ printf(char *);
int semget(int /*<<< orphan*/, int, int);
int main(int argc, char *argv[]) {
  int c, oflag, semid, nsems;
  oflag = (0400 | 0200 | 0400 >> 3 | 0400 >> 6) | IPC_CREAT;
  while ((c = getopt(argc, argv, "e")) != -1) {
    switch (c) {
    case 'e':
      oflag |= IPC_EXCL;
      break;
    }
  }
  if (optind != argc - 2) {
    printf("usage: semcreate [-e] <pathname> <nsems>");
    exit(-1);
  }
  nsems = atoi(argv[optind + 1]);
  semid = semget(ftok(argv[optind], 0), nsems, oflag);
  return EXIT_SUCCESS;
}


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)
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
or     $0x1a4,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe6b(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11cb <main+0x6b>
mov    -0x14(%rbp),%eax
sub    $0x65,%eax
jne    11c6 <main+0x66>
jmp    11b7 <main+0x57>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1187 <main+0x27>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
je     11f8 <main+0x98>
lea    0xe19(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x2ddd(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2dbe(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %esi,%esi
call   1080 <ftok@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <semget@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d89(%rip),%rax
mov    (%rax),%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    0x2e54(%rip),%rax
mov    $0x1a4,%r14d
or     (%rax),%r14d
lea    0xe7c(%rip),%r15
mov    0x2e65(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <getopt@plt>
cmp    $0xffffffff,%eax
je     11ad <main+0x4d>
cmp    $0x65,%eax
jne    1190 <main+0x30>
or     (%r12),%r14d
jmp    1190 <main+0x30>
mov    0x2e2c(%rip),%rax
movslq (%rax),%r15
add    $0xfffffffe,%ebp
cmp    %ebp,%r15d
jne    11f4 <main+0x94>
mov    0x8(%rbx,%r15,8),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    (%rbx,%r15,8),%rdi
xor    %esi,%esi
call   1080 <ftok@plt>
mov    %eax,%edi
mov    %ebp,%esi
mov    %r14d,%edx
call   1030 <semget@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe07(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@.str = [2 x i8] c"e\00"
@IPC_EXCL = global i32 0
@optind = global i32 0
@.str.1 = [41 x i8] c"usage: semcreate [-e] <pathname> <nsems>\00"
@EXIT_SUCCESS = global i32 0
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
%10 = load i32, i32* @IPC_CREAT
%11 = or i32 420, %10
store i32 %11, i32* %7
br label %12
12: ; preds = %23, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %6
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %24
17: ; preds = %12
%18 = load i32, i32* %6
switch i32 %18, label %23 [
i32 101, label %19
]
19: ; preds = %17
%20 = load i32, i32* @IPC_EXCL
%21 = load i32, i32* %7
%22 = or i32 %21, %20
store i32 %22, i32* %7
br label %23
23: ; preds = %17, %19
br label %12
24: ; preds = %12
%25 = load i32, i32* @optind
%26 = load i32, i32* %4
%27 = sub nsw i32 %26, 2
%28 = icmp ne i32 %25, %27
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 -1)
unreachable
32: ; preds = %24
%33 = load i8**, i8*** %5
%34 = load i32, i32* @optind
%35 = add nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %33, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %9
%40 = load i8**, i8*** %5
%41 = load i32, i32* @optind
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call i32 @ftok(i8* %44, i32 0)
%46 = load i32, i32* %9
%47 = load i32, i32* %7
%48 = call i32 @semget(i32 %45, i32 %46, i32 %47)
store i32 %48, i32* %8
%49 = load i32, i32* @EXIT_SUCCESS
ret i32 %49
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str = [2 x i8] c"e\00"
@IPC_EXCL = global i32 0
@optind = global i32 0
@.str.1 = [41 x i8] c"usage: semcreate [-e] <pathname> <nsems>\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @IPC_CREAT
%4 = or i32 %3, 420
br label %5
5: ; preds = %9, %2
%6 = phi i32 [ %11, %9 ], [ %4, %2 ]
br label %7
7: ; preds = %5, %7
%8 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
switch i32 %8, label %7 [
i32 -1, label %12
i32 101, label %9
]
9: ; preds = %7
%10 = load i32, i32* @IPC_EXCL
%11 = or i32 %10, %6
br label %5
12: ; preds = %7
%13 = load i32, i32* @optind
%14 = add nsw i32 %0, -2
%15 = icmp eq i32 %13, %14
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %12
%20 = add nsw i32 %13, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %1, i64 %21
%23 = load i8*, i8** %22
%24 = tail call i32 @atoi(i8* %23)
%25 = sext i32 %13 to i64
%26 = getelementptr inbounds i8*, i8** %1, i64 %25
%27 = load i8*, i8** %26
%28 = tail call i32 @ftok(i8* %27, i32 0)
%29 = tail call i32 @semget(i32 %28, i32 %24, i32 %6)
%30 = load i32, i32* @EXIT_SUCCESS
ret i32 %30
}