#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SEM_UNDO;
int /*<<< orphan*/ perror(char *);
scalar_t__ semop(int, struct sembuf *, int);
int P(int semid) {
  struct sembuf buf = {0, -1, SEM_UNDO};
  if (semop(semid, &buf, 1)) {
    perror("Error for operation P .");
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<P>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    0x2eb0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
cmp    $0x0,%rax
je     117d <P+0x5d>
lea    0xe99(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1189 <P+0x69>
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<P>:
sub    $0x18,%rsp
movabs $0xffffffff00000000,%rax
ff ff ff
mov    %rax,0x8(%rsp)
mov    0x2eb6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
test   %rax,%rax
jne    1162 <P+0x42>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
ret
lea    0xe97(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e63(%rip),%rax
jmp    115b <P+0x3b>

LLVM IR (-O0):
%struct.sembuf = type { i32, i32, i32 }
@SEM_UNDO = global i32 0
@.str = [24 x i8] c"Error for operation P .\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @P(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sembuf
store i32 %0, i32* %3
%5 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %4, i32 0, i32 0
store i32 0, i32* %5
%6 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %4, i32 0, i32 1
store i32 -1, i32* %6
%7 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %4, i32 0, i32 2
%8 = load i32, i32* @SEM_UNDO
store i32 %8, i32* %7
%9 = load i32, i32* %3
%10 = call i64 @semop(i32 %9, %struct.sembuf* %4, i32 1)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %2
br label %17
15: ; preds = %1
%16 = load i32, i32* @EXIT_SUCCESS
store i32 %16, i32* %2
br label %17
17: ; preds = %15, %12
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i32 }
@SEM_UNDO = global i32 0
@.str = [24 x i8] c"Error for operation P .\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @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 0, i32* %4
%5 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %2, i64 0, i32 1
store i32 -1, i32* %5
%6 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %2, i64 0, i32 2
%7 = load i32, i32* @SEM_UNDO
store i32 %7, i32* %6
%8 = call i64 @semop(i32 %0, %struct.sembuf* %2, i32 1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %1, %10
%13 = phi i32* [ @EXIT_FAILURE, %10 ], [ @EXIT_SUCCESS, %1 ]
%14 = load i32, i32* %13
ret i32 %14
}