#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 */
scalar_t__ EPERM;
int IPC_CREAT;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ _exit(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ semctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int semget(int, int, int);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int main(void) {
  int val;
  errno = 0;
  val = semget(17842, 1, 0600 | IPC_CREAT);
  if (val >= 0) {
    fprintf(stderr, "failed: semget() successfully created a semaphore\n");
    semctl(val, 0, IPC_RMID);
    _exit(111);
  }
  if (errno != EPERM) {
    fprintf(stderr, "failed: semget() returned %s\n", strerror(errno));
    _exit(111);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
movq   $0x0,(%rax)
mov    0x2e44(%rip),%rax
mov    (%rax),%edx
or     $0x180,%edx
mov    $0x45b2,%edi
mov    $0x1,%esi
call   1030 <semget@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11dc <main+0x7c>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%edi
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <semctl@plt>
mov    $0x6f,%edi
call   1040 <_exit@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%rax
mov    0x2dcb(%rip),%rcx
cmp    (%rcx),%rax
je     122f <main+0xcf>
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    %rax,%rdx
lea    0xe15(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x6f,%edi
call   1040 <_exit@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e6d(%rip),%r14
movq   $0x0,(%r14)
mov    0x2e4f(%rip),%rax
mov    $0x180,%edx
or     (%rax),%edx
mov    $0x45b2,%edi
mov    $0x1,%esi
call   1030 <semget@plt>
test   %eax,%eax
js     11c8 <main+0x68>
mov    %eax,%ebx
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1060 <semctl@plt>
mov    $0x6f,%edi
call   1040 <_exit@plt>
mov    (%r14),%rdi
mov    0x2de6(%rip),%rax
cmp    (%rax),%rdi
jne    11de <main+0x7e>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%ebx
call   1080 <strerror@plt>
lea    0xe40(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x6f,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@IPC_CREAT = global i32 0
@stderr = global i32 0
@.str = [51 x i8] c"failed: semget() successfully created a semaphore\0A\00"
@IPC_RMID = global i32 0
@EPERM = global i64 0
@.str.1 = [30 x i8] c"failed: semget() returned %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i64 0, i64* @errno
%3 = load i32, i32* @IPC_CREAT
%4 = or i32 384, %3
%5 = call i32 @semget(i32 17842, i32 1, i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %2
%12 = load i32, i32* @IPC_RMID
%13 = call i32 @semctl(i32 %11, i32 0, i32 %12)
%14 = call i32 @_exit(i32 111)
unreachable
15: ; preds = %0
%16 = load i64, i64* @errno
%17 = load i64, i64* @EPERM
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = load i64, i64* @errno
%22 = call i8* @strerror(i64 %21)
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i32 @_exit(i32 111)
unreachable
25: ; preds = %15
%26 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@errno = global i64 0
@IPC_CREAT = global i32 0
@stderr = global i32 0
@.str = [51 x i8] c"failed: semget() successfully created a semaphore\0A\00"
@IPC_RMID = global i32 0
@EPERM = global i64 0
@.str.1 = [30 x i8] c"failed: semget() returned %s\0A\00"
define i32 @main() {
store i64 0, i64* @errno
%1 = load i32, i32* @IPC_CREAT
%2 = or i32 %1, 384
%3 = tail call i32 @semget(i32 17842, i32 1, i32 %2)
%4 = icmp sgt i32 %3, -1
br i1 %4, label %5, label %11
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @IPC_RMID
%9 = tail call i32 @semctl(i32 %3, i32 0, i32 %8)
%10 = tail call i32 @_exit(i32 111)
unreachable
11: ; preds = %0
%12 = load i64, i64* @errno
%13 = load i64, i64* @EPERM
%14 = icmp eq i64 %12, %13
br i1 %14, label %20, label %15
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = tail call i8* @strerror(i64 %12)
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = tail call i32 @_exit(i32 111)
unreachable
20: ; preds = %11
%21 = tail call i32 @exit(i32 0)
unreachable
}