#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;
  int sem_num;
  int /*<<< orphan*/ sem_flg;
};

/* Variables and functions */
int /*<<< orphan*/ SEM_UNDO;
int semop(int, struct sembuf *, int);
int updateSem(int semid, int op, int num) {
  struct sembuf buf;
  buf.sem_op = op;
  buf.sem_flg = SEM_UNDO;
  buf.sem_num = num;
  if (semop(semid, &buf, 1) == -1)
    return -1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<updateSem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2ec2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1030 <semop@plt>
cmp    $0xffffffff,%eax
jne    115f <updateSem+0x4f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1166 <updateSem+0x56>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<updateSem>:
sub    $0x18,%rsp
mov    %esi,0x8(%rsp)
mov    0x2ed1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %edx,0xc(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x1,%edx
call   1030 <semop@plt>
xor    %ecx,%ecx
cmp    $0xffffffff,%eax
sete   %cl
neg    %ecx
mov    %ecx,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.sembuf = type { i32, i32, i32 }
@SEM_UNDO = global i32 0
define i32 @updateSem(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sembuf
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %6
%10 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %8, i32 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* @SEM_UNDO
%12 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %8, i32 0, i32 2
store i32 %11, i32* %12
%13 = load i32, i32* %7
%14 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %8, i32 0, i32 1
store i32 %13, i32* %14
%15 = load i32, i32* %5
%16 = call i32 @semop(i32 %15, %struct.sembuf* %8, i32 1)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %3
store i32 -1, i32* %4
br label %20
19: ; preds = %3
store i32 0, i32* %4
br label %20
20: ; preds = %19, %18
%21 = load i32, i32* %4
ret i32 %21
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i32 }
@SEM_UNDO = global i32 0
define i32 @updateSem(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.sembuf
%5 = bitcast %struct.sembuf* %4 to i8*
%6 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %4, i64 0, i32 0
store i32 %1, i32* %6
%7 = load i32, i32* @SEM_UNDO
%8 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %4, i64 0, i32 2
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %4, i64 0, i32 1
store i32 %2, i32* %9
%10 = call i32 @semop(i32 %0, %struct.sembuf* %4, i32 1)
%11 = icmp eq i32 %10, -1
%12 = sext i1 %11 to i32
ret i32 %12
}