#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*/ *SEM_FAILED;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *sem_open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sem_post(int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
void child() {
  sem_t *sem;
  sem = sem_open("/test_sem", 0);
  if (sem == SEM_FAILED) {
    perror("sem_open");
  }
  sleep(1);
  do {
    if (4 <= 4) {
      fprintf(stderr,
              "%s %d: "
              "child going to post\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",
              47);
    }
  } while (0);
  sem_post(sem);
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%rax
jne    118a <child+0x3a>
lea    0xe85(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
lea    0xe84(%rip),%rdx
mov    $0x2f,%ecx
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <sem_post@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child>:
push   %rbx
lea    0xea8(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
mov    %rax,%rbx
mov    0x2e7f(%rip),%rax
cmp    (%rax),%rbx
je     11a2 <child+0x52>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
lea    0xea0(%rip),%rdx
mov    $0x2f,%ecx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <sem_post@plt>
lea    0xe61(%rip),%rdi
call   1060 <perror@plt>
jmp    116e <child+0x1e>

LLVM IR (-O0):
@.str = [10 x i8] c"/test_sem\00"
@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: child going to post\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 @child() {
%1 = alloca i32*
%2 = call i32* @sem_open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 0)
store i32* %2, i32** %1
%3 = load i32*, i32** %1
%4 = load i32*, i32** @SEM_FAILED
%5 = icmp eq i32* %3, %4
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i32 @sleep(i32 1)
br label %10
10: ; preds = %8
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, 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 47)
br label %13
13: ; preds = %10
%14 = load i32*, i32** %1
%15 = call i32 @sem_post(i32* %14)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"/test_sem\00"
@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: child going to post\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 @child() {
%1 = tail call i32* @sem_open(i8* getelementptr inbounds ([10 x i8], [10 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 @sleep(i32 1)
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, 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 47)
%10 = tail call i32 @sem_post(i32* %1)
ret void
}