#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 O_CREAT;
int O_EXCL;
int /*<<< orphan*/ *SEM_FAILED;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sem_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ *sem_open(char *, int, ...);
int /*<<< orphan*/ sem_post(int /*<<< orphan*/ *);
int /*<<< orphan*/ sem_unlink(char *);
int /*<<< orphan*/ sem_wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void parent() {
  sem_t *sem;
  sem = sem_open("/test_sem", O_CREAT | O_EXCL, 0666, 0);
  if (sem == SEM_FAILED) {
    sem = sem_open("/test_sem", 0);
    if (sem == SEM_FAILED) {
      perror("sem_open");
      return;
    }
  }
  sem_wait(sem);
  do {
    if (4 <= 4) {
      fprintf(stderr,
              "%s %d: "
              "parent wait succedd\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/master/"
              "POSIX_sem/process_sem.c",
              29);
    }
  } while (0);
  sem_post(sem);
  sem_close(sem);
  sem_unlink("/test_sem");
}


x86 assembly (clang, -O0):
<parent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
mov    0x2e40(%rip),%rax
or     (%rax),%esi
lea    0xe6f(%rip),%rdi
mov    $0x1b6,%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1050 <sem_open@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%rax
jne    11f5 <parent+0x85>
lea    0xe42(%rip),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1050 <sem_open@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2e0a(%rip),%rcx
cmp    (%rcx),%rax
jne    11f0 <parent+0x80>
lea    0xe24(%rip),%rdi
call   1080 <perror@plt>
jmp    123d <parent+0xcd>
jmp    11f5 <parent+0x85>
mov    -0x8(%rbp),%rdi
call   1030 <sem_wait@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
lea    0xe1a(%rip),%rdx
mov    $0x1d,%ecx
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <sem_post@plt>
mov    -0x8(%rbp),%rdi
call   1070 <sem_close@plt>
lea    0xdc8(%rip),%rdi
call   1090 <sem_unlink@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parent>:
push   %r14
push   %rbx
push   %rax
mov    0x2e7d(%rip),%rax
mov    0x2e46(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe73(%rip),%rdi
mov    $0x1b6,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1050 <sem_open@plt>
mov    %rax,%rbx
mov    0x2e3b(%rip),%r14
cmp    (%r14),%rax
jne    11c2 <parent+0x52>
lea    0xe4f(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <sem_open@plt>
mov    %rax,%rbx
cmp    (%r14),%rax
je     120e <parent+0x9e>
mov    %rbx,%rdi
call   1030 <sem_wait@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
lea    0xe4e(%rip),%rdx
mov    $0x1d,%ecx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <sem_post@plt>
mov    %rbx,%rdi
call   1070 <sem_close@plt>
lea    0xdfe(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1090 <sem_unlink@plt>
lea    0xdf5(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <perror@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/test_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"
@stderr = global i32 0
@.str.2 = [28 x i8] c"%s %d: parent wait succedd\0A\00"
@.str.3 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/master/POSIX_sem/process_sem.c\00"
define void @parent() {
%1 = alloca i32*
%2 = load i32, i32* @O_CREAT
%3 = load i32, i32* @O_EXCL
%4 = or i32 %2, %3
%5 = call i32* (i8*, i32, ...) @sem_open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4, i32 438, i32 0)
store i32* %5, i32** %1
%6 = load i32*, i32** %1
%7 = load i32*, i32** @SEM_FAILED
%8 = icmp eq i32* %6, %7
br i1 %8, label %9, label %17
9: ; preds = %0
%10 = call i32* (i8*, i32, ...) @sem_open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 0)
store i32* %10, i32** %1
%11 = load i32*, i32** %1
%12 = load i32*, i32** @SEM_FAILED
%13 = icmp eq i32* %11, %12
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %29
16: ; preds = %9
br label %17
17: ; preds = %16, %0
%18 = load i32*, i32** %1
%19 = call i32 @sem_wait(i32* %18)
br label %20
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.3, i64 0, i64 0), i32 29)
br label %23
23: ; preds = %20
%24 = load i32*, i32** %1
%25 = call i32 @sem_post(i32* %24)
%26 = load i32*, i32** %1
%27 = call i32 @sem_close(i32* %26)
%28 = call i32 @sem_unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %23, %14
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"/test_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"
@stderr = global i32 0
@.str.2 = [28 x i8] c"%s %d: parent wait succedd\0A\00"
@.str.3 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/master/POSIX_sem/process_sem.c\00"
define void @parent() {
%1 = load i32, i32* @O_CREAT
%2 = load i32, i32* @O_EXCL
%3 = or i32 %2, %1
%4 = tail call i32* (i8*, i32, ...) @sem_open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3, i32 438, i32 0)
%5 = load i32*, i32** @SEM_FAILED
%6 = icmp eq i32* %4, %5
br i1 %6, label %7, label %13
7: ; preds = %0
%8 = tail call i32* (i8*, i32, ...) @sem_open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 0)
%9 = load i32*, i32** @SEM_FAILED
%10 = icmp eq i32* %8, %9
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %21
13: ; preds = %7, %0
%14 = phi i32* [ %8, %7 ], [ %4, %0 ]
%15 = tail call i32 @sem_wait(i32* %14)
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.3, i64 0, i64 0), i32 29)
%18 = tail call i32 @sem_post(i32* %14)
%19 = tail call i32 @sem_close(i32* %14)
%20 = tail call i32 @sem_unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %13, %11
ret void
}