#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*/ O_CREAT;
int /*<<< orphan*/ *SEM_FAILED;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sem_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ *sem_open(char *, int /*<<< orphan*/, int,
                             int /*<<< orphan*/);
int /*<<< orphan*/ sem_unlink(char *);
int main(void) {
  sem_t *a = sem_open("/autoconf", O_CREAT, S_IRUSR | S_IWUSR, 0);
  if (a == SEM_FAILED) {
    perror("sem_open");
    return 1;
  }
  printf("All OK!\n");
  sem_close(a);
  sem_unlink("/autoconf");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
mov    0x2e60(%rip),%rax
or     (%rax),%edx
lea    0xe7f(%rip),%rdi
xor    %ecx,%ecx
call   1040 <sem_open@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e49(%rip),%rcx
cmp    (%rcx),%rax
jne    11b8 <main+0x68>
lea    0xe63(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e0 <main+0x90>
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <sem_close@plt>
lea    0xe2c(%rip),%rdi
call   1070 <sem_unlink@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
mov    0x2e65(%rip),%rax
mov    0x2e6e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe8b(%rip),%rdi
xor    %ebp,%ebp
xor    %ecx,%ecx
call   1040 <sem_open@plt>
mov    %rax,%rbx
mov    0x2e58(%rip),%rax
cmp    (%rax),%rbx
je     11b6 <main+0x66>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <sem_close@plt>
lea    0xe58(%rip),%rdi
call   1070 <sem_unlink@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe4d(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%ebp
jmp    11ad <main+0x5d>

LLVM IR (-O0):
@.str = [10 x i8] c"/autoconf\00"
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@SEM_FAILED = global i32* null
@.str.1 = [9 x i8] c"sem_open\00"
@.str.2 = [9 x i8] c"All OK!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @S_IRUSR
%5 = load i32, i32* @S_IWUSR
%6 = or i32 %4, %5
%7 = call i32* @sem_open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %6, i32 0)
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = load i32*, i32** @SEM_FAILED
%10 = icmp eq i32* %8, %9
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %18
13: ; preds = %0
%14 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32*, i32** %2
%16 = call i32 @sem_close(i32* %15)
%17 = call i32 @sem_unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %18
18: ; preds = %13, %11
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [10 x i8] c"/autoconf\00"
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@SEM_FAILED = global i32* null
@.str.1 = [9 x i8] c"sem_open\00"
@str = [8 x i8] c"All OK!\00"
define i32 @main() {
%1 = load i32, i32* @O_CREAT
%2 = load i32, i32* @S_IRUSR
%3 = load i32, i32* @S_IWUSR
%4 = or i32 %3, %2
%5 = tail call i32* @sem_open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %4, i32 0)
%6 = load i32*, i32** @SEM_FAILED
%7 = icmp eq i32* %5, %6
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %14
10: ; preds = %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @sem_close(i32* %5)
%13 = tail call i32 @sem_unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %10, %8
%15 = phi i32 [ 1, %8 ], [ 0, %10 ]
ret i32 %15
}