#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 */
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ SIGALRM;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ SIG_UNBLOCK;
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
void lock_buffer(int locked) {
  sigset_t set;
  sigemptyset(&set);
  sigaddset(&set, SIGALRM);
  if (locked)
    sigprocmask(SIG_BLOCK, &set, NULL);
  else
    sigprocmask(SIG_UNBLOCK, &set, NULL);
}


x86 assembly (clang, -O0):
<lock_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1040 <sigemptyset@plt>
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1050 <sigaddset@plt>
cmpl   $0x0,-0x4(%rbp)
je     117b <lock_buffer+0x4b>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
jmp    1191 <lock_buffer+0x61>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lock_buffer>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <sigemptyset@plt>
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <sigaddset@plt>
test   %ebp,%ebp
jne    1160 <lock_buffer+0x30>
mov    0x2e8a(%rip),%rax
jmp    1167 <lock_buffer+0x37>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SIGALRM = global i32 0
@SIG_BLOCK = global i32 0
@SIG_UNBLOCK = global i32 0
define void @lock_buffer(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 @sigemptyset(i32* %3)
%5 = load i32, i32* @SIGALRM
%6 = call i32 @sigaddset(i32* %3, i32 %5)
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* @SIG_BLOCK
%11 = call i32 @sigprocmask(i32 %10, i32* %3, i32* null)
br label %15
12: ; preds = %1
%13 = load i32, i32* @SIG_UNBLOCK
%14 = call i32 @sigprocmask(i32 %13, i32* %3, i32* null)
br label %15
15: ; preds = %12, %9
ret void
}

LLVM IR (-O2):
@SIGALRM = global i32 0
@SIG_BLOCK = global i32 0
@SIG_UNBLOCK = global i32 0
define void @lock_buffer(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @sigemptyset(i32* %2)
%5 = load i32, i32* @SIGALRM
%6 = call i32 @sigaddset(i32* %2, i32 %5)
%7 = icmp eq i32 %0, 0
%8 = load i32, i32* @SIG_UNBLOCK
%9 = load i32, i32* @SIG_BLOCK
%10 = select i1 %7, i32 %8, i32 %9
%11 = call i32 @sigprocmask(i32 %10, i32* %2, i32* null)
ret void
}