#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 sem_num;
  int sem_op;
  scalar_t__ sem_flg;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ semop(int, struct sembuf *, int);
int p(int semid, int semnum) {
  struct sembuf oper;
  oper.sem_num = semnum;
  oper.sem_op = -1;
  oper.sem_flg = 0;
  if (semop(semid, &oper, 1) != 0) {
    perror("No se pudo hacer P del semáforo");
    exit(-1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<p>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
cmp    $0x0,%rax
je     1184 <p+0x54>
lea    0xe8b(%rip),%rdi
call   1030 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p>:
sub    $0x18,%rsp
mov    %esi,0x8(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
test   %rax,%rax
jne    1164 <p+0x34>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xe95(%rip),%rdi
call   1030 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.sembuf = type { i32, i32, i64 }
@.str = [33 x i8] c"No se pudo hacer P del sem\C3\A1foro\00"
define i32 @p(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sembuf
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %5, i32 0, i32 0
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %5, i32 0, i32 1
store i32 -1, i32* %8
%9 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %5, i32 0, i32 2
store i64 0, i64* %9
%10 = load i32, i32* %3
%11 = call i64 @semop(i32 %10, %struct.sembuf* %5, i32 1)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
ret i32 0
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i64 }
@.str = [33 x i8] c"No se pudo hacer P del sem\C3\A1foro\00"
define i32 @p(i32 %0, i32 %1) {
%3 = alloca %struct.sembuf
%4 = bitcast %struct.sembuf* %3 to i8*
%5 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i64 0, i32 0
store i32 %1, i32* %5
%6 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i64 0, i32 1
store i32 -1, i32* %6
%7 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i64 0, i32 2
store i64 0, i64* %7
%8 = call i64 @semop(i32 %0, %struct.sembuf* %3, i32 1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
ret i32 0
}