#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int semop(int, struct sembuf *, int);
void release_lock(int sem_id) {
  struct sembuf actions[1];
  actions[0].sem_num = 0;
  actions[0].sem_op = -1;
  actions[0].sem_flg = SEM_UNDO;
  if (semop(sem_id, actions, 1) == -1) {
    perror("semop: unlocking");
    exit(10);
  };
}


x86 assembly (clang, -O0):
<release_lock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
cmp    $0xffffffff,%eax
jne    1186 <release_lock+0x56>
lea    0xe89(%rip),%rdi
call   1030 <perror@plt>
mov    $0xa,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<release_lock>:
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
movl   $0xffffffff,(%rsp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
cmp    $0xffffffff,%eax
je     1168 <release_lock+0x38>
add    $0x18,%rsp
ret
lea    0xe91(%rip),%rdi
call   1030 <perror@plt>
mov    $0xa,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i64 }
@SEM_UNDO = global i32 0
@.str = [17 x i8] c"semop: unlocking\00"
define void @release_lock(i32 %0) {
%2 = alloca [1 x %struct.sembuf]
%3 = bitcast [1 x %struct.sembuf]* %2 to i8*
%4 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %2, i64 0, i64 0, i32 2
store i64 0, i64* %5
%6 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %2, i64 0, i64 0, i32 0
store i32 -1, i32* %6
%7 = load i32, i32* @SEM_UNDO
%8 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %2, i64 0, i64 0, i32 1
store i32 %7, i32* %8
%9 = call i32 @semop(i32 %0, %struct.sembuf* %4, i32 1)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 10)
unreachable
14: ; preds = %1
ret void
}