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

/* Variables and functions */
int /*<<< orphan*/ SEM_UNDO;
int semget(int, int, int /*<<< orphan*/);
int semop(int, struct sembuf *, int);
int semunlock() {
  int ret = 0;
  struct sembuf lock[1];
  int lockid = semget(34552, 1, 0);
  if (lockid == -1)
    return -1;
  lock[0].sem_num = 0;
  lock[0].sem_op = 1;
  lock[0].sem_flg = SEM_UNDO;
  ret = semop(lockid, lock, 1);
  return ret;
}


x86 assembly (clang, -O0):
<semunlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x8(%rbp)
mov    $0x86f8,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <semget@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1159 <semunlock+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    118e <semunlock+0x6e>
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x20(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<semunlock>:
sub    $0x18,%rsp
mov    $0x86f8,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <semget@plt>
cmp    $0xffffffff,%eax
je     116b <semunlock+0x4b>
movq   $0x0,0x8(%rsp)
movl   $0x1,(%rsp)
mov    0x2e9f(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x4(%rsp)
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1040 <semop@plt>
add    $0x18,%rsp
ret
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i64 }
@SEM_UNDO = global i32 0
define i32 @semunlock() {
%1 = alloca [1 x %struct.sembuf]
%2 = bitcast [1 x %struct.sembuf]* %1 to i8*
%3 = tail call i32 @semget(i32 34552, i32 1, i32 0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %12, label %5
5: ; preds = %0
%6 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %1, i64 0, i64 0
%7 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %1, i64 0, i64 0, i32 2
store i64 0, i64* %7
%8 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %1, i64 0, i64 0, i32 0
store i32 1, i32* %8
%9 = load i32, i32* @SEM_UNDO
%10 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %1, i64 0, i64 0, i32 1
store i32 %9, i32* %10
%11 = call i32 @semop(i32 %3, %struct.sembuf* %6, i32 1)
br label %12
12: ; preds = %0, %5
%13 = phi i32 [ %11, %5 ], [ -1, %0 ]
ret i32 %13
}