#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 /*<<< orphan*/ *SEM_FAILED;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *sem_open(char *, int /*<<< orphan*/);
int sem_post(int /*<<< orphan*/ *);
int main() {
  sem_t *sem;
  sem = sem_open("/mysem", 0);
  if (sem == SEM_FAILED)
    perror("sem_open");
  if (sem_post(sem) == -1)
    perror("sem_post");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e7c(%rip),%rcx
cmp    (%rcx),%rax
jne    1181 <main+0x41>
lea    0xe8b(%rip),%rdi
call   1050 <perror@plt>
mov    -0x10(%rbp),%rdi
call   1030 <sem_post@plt>
cmp    $0xffffffff,%eax
jne    119f <main+0x5f>
lea    0xe76(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
mov    %rax,%rbx
mov    0x2e8f(%rip),%rax
cmp    (%rax),%rbx
jne    116a <main+0x2a>
lea    0xea2(%rip),%rdi
call   1050 <perror@plt>
mov    %rbx,%rdi
call   1030 <sem_post@plt>
cmp    $0xffffffff,%eax
jne    1183 <main+0x43>
lea    0xe92(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"/mysem\00"
@SEM_FAILED = global i32* null
@.str.1 = [9 x i8] c"sem_open\00"
@.str.2 = [9 x i8] c"sem_post\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i32* @sem_open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 0)
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = load i32*, i32** @SEM_FAILED
%6 = icmp eq i32* %4, %5
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = load i32*, i32** %2
%11 = call i32 @sem_post(i32* %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = load i32, i32* @EXIT_SUCCESS
%17 = call i32 @exit(i32 %16)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"/mysem\00"
@SEM_FAILED = global i32* null
@.str.1 = [9 x i8] c"sem_open\00"
@.str.2 = [9 x i8] c"sem_post\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32* @sem_open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 0)
%2 = load i32*, i32** @SEM_FAILED
%3 = icmp eq i32* %1, %2
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %4, %0
%7 = tail call i32 @sem_post(i32* %1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = load i32, i32* @EXIT_SUCCESS
%13 = tail call i32 @exit(i32 %12)
unreachable
}