#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 */
struct sembuf {
  int member_1;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int semop(int, struct sembuf *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void sem_p(int semid) {
  struct sembuf sb = {0, -1, 0};
  if (semop(semid, &sb, 1) == -1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day0b/mutex.c",
              45, "semop", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
}


x86 assembly (clang, -O0):
<sem_p>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0xeae(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xeac(%rip),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
cmp    $0xffffffff,%eax
jne    11cb <sem_p+0x8b>
jmp    117e <sem_p+0x3e>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%r9
lea    0xe67(%rip),%rsi
lea    0xe70(%rip),%rdx
mov    $0x2d,%ecx
lea    0xef8(%rip),%r8
call   1030 <fprintf@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sem_p>:
push   %rbx
sub    $0x10,%rsp
mov    0xebd(%rip),%eax
mov    %eax,0x8(%rsp)
mov    0xeaa(%rip),%rax
mov    %rax,(%rsp)
mov    %rsp,%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
cmp    $0xffffffff,%eax
je     1172 <sem_p+0x32>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e67(%rip),%rax
mov    (%rax),%ebx
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe7c(%rip),%rsi
lea    0xe85(%rip),%rdx
lea    0xf12(%rip),%r8
mov    %ebx,%edi
mov    $0x2d,%ecx
mov    %rax,%r9
call   1030 <fprintf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.sembuf = type { i32, i32, i32 }
@__const.sem_p.sb = %struct.sembuf { i32 0, i32 -1, i32 0 }
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [148 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day0b/mutex.c\00"
@.str.2 = [6 x i8] c"semop\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @sem_p(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sembuf
store i32 %0, i32* %2
%4 = bitcast %struct.sembuf* %3 to i8*
%5 = load i32, i32* %2
%6 = call i32 @semop(i32 %5, %struct.sembuf* %3, i32 1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %17
8: ; preds = %1
br label %9
9: ; preds = %8
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; No predecessors!
br label %17
17: ; preds = %16, %1
ret void
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i32 }
@__const.sem_p.sb = %struct.sembuf { i32 0, i32 -1, i32 0 }
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [148 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day0b/mutex.c\00"
@.str.2 = [6 x i8] c"semop\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @sem_p(i32 %0) {
%2 = alloca %struct.sembuf
%3 = bitcast %struct.sembuf* %2 to i8*
%4 = call i32 @semop(i32 %0, %struct.sembuf* %2, i32 1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %1
ret void
}