#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 */
typedef int /*<<< orphan*/ sem_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int O_CREAT;
int O_EXCL;
int /*<<< orphan*/ *SEM_FAILED;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int sem_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ *sem_open(char *, int, int, int);
void create_it(void) {
  sem_t *mysem;
  if ((mysem = sem_open("/my_sem", O_CREAT | O_EXCL, 0666, 1)) == SEM_FAILED) {
    perror("sem_open");
    exit(errno);
  };
  if ((sem_close(mysem)) == -1) {
    perror("sem_close");
    exit(errno);
  };
  printf("Semaphore successfully created and initialized\n");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<create_it>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
mov    0x2e68(%rip),%rax
or     (%rax),%esi
lea    0xe8f(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x1,%ecx
call   1040 <sem_open@plt>
mov    %rax,-0x8(%rbp)
mov    0x2e55(%rip),%rcx
cmp    (%rcx),%rax
jne    11ae <create_it+0x5e>
lea    0xe6d(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1050 <sem_close@plt>
cmp    $0xffffffff,%eax
jne    11da <create_it+0x8a>
lea    0xe4a(%rip),%rdi
call   1060 <perror@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xe3a(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<create_it>:
push   %rax
mov    0x2ea0(%rip),%rax
mov    0x2e71(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe96(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x1,%ecx
call   1040 <sem_open@plt>
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%rax
jne    118e <create_it+0x3e>
lea    0xe7c(%rip),%rdi
jmp    11a2 <create_it+0x52>
mov    %rax,%rdi
call   1050 <sem_close@plt>
cmp    $0xffffffff,%eax
jne    11b5 <create_it+0x65>
lea    0xe6f(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xe5f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"/my_sem\00"
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@SEM_FAILED = global i32* null
@.str.1 = [9 x i8] c"sem_open\00"
@errno = global i32 0
@.str.2 = [10 x i8] c"sem_close\00"
@.str.3 = [48 x i8] c"Semaphore successfully created and initialized\0A\00"
@EXIT_SUCCESS = global i32 0
define void @create_it() {
%1 = alloca i32*
%2 = load i32, i32* @O_CREAT
%3 = load i32, i32* @O_EXCL
%4 = or i32 %2, %3
%5 = call i32* @sem_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %4, i32 438, i32 1)
store i32* %5, i32** %1
%6 = load i32*, i32** @SEM_FAILED
%7 = icmp eq i32* %5, %6
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @errno
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = load i32*, i32** %1
%14 = call i32 @sem_close(i32* %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32, i32* @errno
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %12
%21 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%22 = load i32, i32* @EXIT_SUCCESS
%23 = call i32 @exit(i32 %22)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"/my_sem\00"
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@SEM_FAILED = global i32* null
@.str.1 = [9 x i8] c"sem_open\00"
@errno = global i32 0
@.str.2 = [10 x i8] c"sem_close\00"
@EXIT_SUCCESS = global i32 0
@str = [47 x i8] c"Semaphore successfully created and initialized\00"
define void @create_it() {
%1 = load i32, i32* @O_CREAT
%2 = load i32, i32* @O_EXCL
%3 = or i32 %2, %1
%4 = tail call i32* @sem_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %3, i32 438, i32 1)
%5 = load i32*, i32** @SEM_FAILED
%6 = icmp eq i32* %4, %5
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @errno
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = tail call i32 @sem_close(i32* %4)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* @errno
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %11
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_SUCCESS
%21 = tail call i32 @exit(i32 %20)
unreachable
}