#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 O_CREAT;
int O_RDWR;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ perror(char *);
int semaphore_open(char *, int, int, int);
int semaphore_create() {
  int flag_sem = O_CREAT | O_RDWR;
  int init_value = 1;
  if (semaphore_open("/tmp/Semaphore", flag_sem,
                     (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH),
                     init_value) == -1) {
    perror("semaphore_create fail");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<semaphore_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ec9(%rip),%rax
mov    (%rax),%eax
mov    0x2ea8(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
mov    0x2e81(%rip),%rax
or     (%rax),%edx
mov    0x2e68(%rip),%rax
or     (%rax),%edx
mov    0x2e57(%rip),%rax
or     (%rax),%edx
mov    -0xc(%rbp),%ecx
lea    0xe8b(%rip),%rdi
call   1030 <semaphore_open@plt>
cmp    $0xffffffff,%eax
jne    119b <semaphore_create+0x7b>
lea    0xe85(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a2 <semaphore_create+0x82>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<semaphore_create>:
push   %rax
mov    0x2ed0(%rip),%rax
mov    0x2eb1(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e7e(%rip),%rax
mov    0x2e97(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e7c(%rip),%rax
or     (%rax),%edx
mov    0x2e6b(%rip),%rax
or     (%rax),%edx
lea    0xea2(%rip),%rdi
mov    $0x1,%ecx
call   1030 <semaphore_open@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     1173 <semaphore_create+0x53>
pop    %rcx
ret
lea    0xe95(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str = [15 x i8] c"/tmp/Semaphore\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [22 x i8] c"semaphore_create fail\00"
define i32 @semaphore_create() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = load i32, i32* @O_CREAT
%5 = load i32, i32* @O_RDWR
%6 = or i32 %4, %5
store i32 %6, i32* %2
store i32 1, i32* %3
%7 = load i32, i32* %2
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IRGRP
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IROTH
%14 = or i32 %12, %13
%15 = load i32, i32* %3
%16 = call i32 @semaphore_open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %14, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %21
20: ; preds = %0
store i32 0, i32* %1
br label %21
21: ; preds = %20, %18
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str = [15 x i8] c"/tmp/Semaphore\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [22 x i8] c"semaphore_create fail\00"
define i32 @semaphore_create() {
%1 = load i32, i32* @O_CREAT
%2 = load i32, i32* @O_RDWR
%3 = or i32 %2, %1
%4 = load i32, i32* @S_IRUSR
%5 = load i32, i32* @S_IWUSR
%6 = or i32 %5, %4
%7 = load i32, i32* @S_IRGRP
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IROTH
%10 = or i32 %8, %9
%11 = tail call i32 @semaphore_open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %10, i32 1)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %0, %13
%16 = phi i32 [ -1, %13 ], [ 0, %0 ]
ret i32 %16
}