#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);
int P(int semID) {
  struct sembuf buff;
  buff.sem_num = 0;
  buff.sem_op = -1;
  buff.sem_flg = 0;
  printf("CFSCHED In P operation\n");
  if (semop(semID, &buff, 1) == -1) {
    perror("CFSCHED semop P operation error");
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<P>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0xffffffff,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1050 <semop@plt>
cmp    $0xffffffff,%eax
jne    1190 <P+0x60>
lea    0xe99(%rip),%rdi
call   1040 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1197 <P+0x67>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<P>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
movl   $0xffffffff,0x8(%rsp)
ff
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
lea    0xed2(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1050 <semop@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0xffffffff,%ecx
je     1176 <P+0x46>
add    $0x20,%rsp
pop    %rbx
ret
lea    0xe83(%rip),%rdi
call   1040 <perror@plt>
xor    %eax,%eax
jmp    1170 <P+0x40>

LLVM IR (-O0):
%struct.sembuf = type { i32, i64, i64 }
@.str = [24 x i8] c"CFSCHED In P operation\0A\00"
@.str.1 = [32 x i8] c"CFSCHED semop P operation error\00"
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 2
store i64 0, i64* %5
%6 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %4, i32 0, i32 0
store i32 -1, i32* %6
%7 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %4, i32 0, i32 1
store i64 0, i64* %7
%8 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %3
%10 = call i32 @semop(i32 %9, %struct.sembuf* %4, i32 1)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %15
14: ; preds = %1
store i32 -1, i32* %2
br label %15
15: ; preds = %14, %12
%16 = load i32, i32* %2
ret i32 %16
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i64, i64 }
@.str.1 = [32 x i8] c"CFSCHED semop P operation error\00"
@str = [23 x i8] c"CFSCHED In P operation\00"
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 -1, i32* %4
%5 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %2, i64 0, i32 1
%6 = bitcast i64* %5 to <2 x i64>*
store <2 x i64> zeroinitializer, <2 x i64>* %6
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%8 = call i32 @semop(i32 %0, %struct.sembuf* %2, i32 1)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %1, %10
%13 = phi i32 [ 0, %10 ], [ -1, %1 ]
ret i32 %13
}