#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ semop(int, struct sembuf *, int);
void waitOrSignal(int semid, struct sembuf operation) {
  if (semop(semid, &operation, 1) < 0) {
    perror("ERROR ON SEMAPHORE WAIT/SIGNAL!");
    printf("\tSEMID: %d\n", semid);
    _exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<waitOrSignal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %esi,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x1,%edx
call   1060 <semop@plt>
cmp    $0x0,%rax
jge    1192 <waitOrSignal+0x52>
lea    0xe90(%rip),%rdi
call   1050 <perror@plt>
mov    -0xc(%rbp),%esi
lea    0xea1(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitOrSignal>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %esi,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x1,%edx
call   1060 <semop@plt>
test   %rax,%rax
js     1165 <waitOrSignal+0x25>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe94(%rip),%rdi
call   1050 <perror@plt>
lea    0xea8(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
%struct.sembuf = type { i32 }
@.str = [32 x i8] c"ERROR ON SEMAPHORE WAIT/SIGNAL!\00"
@.str.1 = [12 x i8] c"\09SEMID: %d\0A\00"
@EXIT_FAILURE = global i32 0
define void @waitOrSignal(i32 %0, i32 %1) {
%3 = alloca %struct.sembuf
%4 = alloca i32
%5 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 0
store i32 %1, i32* %5
store i32 %0, i32* %4
%6 = load i32, i32* %4
%7 = call i64 @semop(i32 %6, %struct.sembuf* %3, i32 1)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %4
%12 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @_exit(i32 %13)
unreachable
15: ; preds = %2
ret void
}

LLVM IR (-O2):
%struct.sembuf = type { i32 }
@.str = [32 x i8] c"ERROR ON SEMAPHORE WAIT/SIGNAL!\00"
@.str.1 = [12 x i8] c"\09SEMID: %d\0A\00"
@EXIT_FAILURE = global i32 0
define void @waitOrSignal(i32 %0, i32 %1) {
%3 = alloca %struct.sembuf
%4 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i64 0, i32 0
store i32 %1, i32* %4
%5 = call i64 @semop(i32 %0, %struct.sembuf* %3, i32 1)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @_exit(i32 %10)
unreachable
12: ; preds = %2
ret void
}