#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*/ printf(char *, int);
int semInit(int /*<<< orphan*/, int);
int semget(int, int, int);
int semop(int, struct sembuf *, int);
void semV(int key) {
  int semId = semget(key, 1, 0666);
  if (semId < 0) {
    semId = semInit(0, key);
    if (!semId)
      return;
  }
  struct sembuf operations[1];
  operations[0].sem_num = 0;
  operations[0].sem_op = 1;
  operations[0].sem_flg = 0;
  int retval = semop(semId, operations, 1);
  if (retval == 0) {
    ;
  } else {
    printf("V-operation did not succeed %d\n", key);
  }
}


x86 assembly (clang, -O0):
<semV>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
mov    $0x1b6,%edx
call   1030 <semget@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    118b <semV+0x4b>
mov    -0x4(%rbp),%esi
xor    %edi,%edi
call   1050 <semInit@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1186 <semV+0x46>
jmp    11d4 <semV+0x94>
jmp    118b <semV+0x4b>
movq   $0x0,-0x10(%rbp)
movl   $0x1,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1060 <semop@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11c5 <semV+0x85>
jmp    11d4 <semV+0x94>
mov    -0x4(%rbp),%esi
lea    0xe31(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<semV>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
mov    $0x1,%esi
mov    $0x1b6,%edx
call   1030 <semget@plt>
test   %eax,%eax
jns    1167 <semV+0x27>
xor    %edi,%edi
mov    %ebx,%esi
call   1050 <semInit@plt>
test   %eax,%eax
je     1197 <semV+0x57>
movl   $0x1,(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1060 <semop@plt>
test   %eax,%eax
je     1197 <semV+0x57>
lea    0xe70(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sembuf = type { i32, i64, i64 }
@.str = [32 x i8] c"V-operation did not succeed %d\0A\00"
define void @semV(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1 x %struct.sembuf]
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = call i32 @semget(i32 %6, i32 1, i32 438)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %1
%11 = load i32, i32* %2
%12 = call i32 @semInit(i32 0, i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %10
br label %33
16: ; preds = %10
br label %17
17: ; preds = %16, %1
%18 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %4, i64 0, i64 0
%19 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %18, i32 0, i32 2
store i64 0, i64* %19
%20 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %4, i64 0, i64 0
%21 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %20, i32 0, i32 0
store i32 1, i32* %21
%22 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %4, i64 0, i64 0
%23 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %22, i32 0, i32 1
store i64 0, i64* %23
%24 = load i32, i32* %3
%25 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %4, i64 0, i64 0
%26 = call i32 @semop(i32 %24, %struct.sembuf* %25, i32 1)
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %17
br label %33
30: ; preds = %17
%31 = load i32, i32* %2
%32 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %15, %30, %29
ret void
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i64, i64 }
@.str = [32 x i8] c"V-operation did not succeed %d\0A\00"
define void @semV(i32 %0) {
%2 = alloca [1 x %struct.sembuf]
%3 = tail call i32 @semget(i32 %0, i32 1, i32 438)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @semInit(i32 0, i32 %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %5, %1
%9 = phi i32 [ %6, %5 ], [ %3, %1 ]
%10 = bitcast [1 x %struct.sembuf]* %2 to i8*
%11 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %2, i64 0, i64 0
%12 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %2, i64 0, i64 0, i32 0
store i32 1, i32* %12
%13 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %2, i64 0, i64 0, i32 1
%14 = bitcast i64* %13 to <2 x i64>*
store <2 x i64> zeroinitializer, <2 x i64>* %14
%15 = call i32 @semop(i32 %9, %struct.sembuf* %11, i32 1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %8
%18 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %19
19: ; preds = %8, %17
br label %20
20: ; preds = %5, %19
ret void
}