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

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int semop(int, struct sembuf *, int);
void p(int semid) {
  struct sembuf sem_p;
  sem_p.sem_op = -1;
  sem_p.sem_num = 0;
  sem_p.sem_flg = 0;
  if (semop(semid, &sem_p, 1) == -1) {
    perror("semop");
    printf("p operation is fail!\n");
  }
}


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

x86 assembly (clang, -O2):
<p>:
sub    $0x18,%rsp
movl   $0xffffffff,(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
mov    %rsp,%rsi
mov    $0x1,%edx
call   1050 <semop@plt>
cmp    $0xffffffff,%eax
je     115a <p+0x2a>
add    $0x18,%rsp
ret
lea    0xe9f(%rip),%rdi
call   1040 <perror@plt>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.sembuf = type { i32, i64, i64 }
@.str = [6 x i8] c"semop\00"
@.str.1 = [22 x i8] c"p operation is fail!\0A\00"
define void @p(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sembuf
store i32 %0, i32* %2
%4 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 0
store i32 -1, i32* %4
%5 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 2
store i64 0, i64* %5
%6 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 1
store i64 0, i64* %6
%7 = load i32, i32* %2
%8 = call i32 @semop(i32 %7, %struct.sembuf* %3, i32 1)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %10, %1
ret void
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i64, i64 }
@.str = [6 x i8] c"semop\00"
@str = [21 x i8] c"p operation is fail!\00"
define void @p(i32 %0) {
%2 = alloca %struct.sembuf
%3 = bitcast %struct.sembuf* %2 to i8*
%4 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %2, i64 0, i32 0
store i32 -1, i32* %4
%5 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %2, i64 0, i32 1
%6 = bitcast i64* %5 to i8*
%7 = call i32 @semop(i32 %0, %struct.sembuf* %2, i32 1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %9, %1
ret void
}