#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;
typedef unsigned long *sigjmp_buf;
typedef int /*<<< orphan*/ jmp_buf;

/* Variables and functions */
int /*<<< orphan*/ SIG_SETMASK;
int /*<<< orphan*/ longjmp(void *, int);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
void siglongjmp(sigjmp_buf buf, int ret) {
  unsigned long *flag = buf + sizeof(jmp_buf) / sizeof(long) - 1;
  sigset_t *mask = (void *)(flag + 1);
  if (*flag)
    sigprocmask(SIG_SETMASK, mask, NULL);
  longjmp((void *)buf, ret);
}


x86 assembly (clang, -O0):
<siglongjmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0xfffffffffffffff8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     116b <siglongjmp+0x4b>
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <longjmp@plt>

x86 assembly (clang, -O2):
<siglongjmp>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
cmpq   $0x0,-0x8(%rdi)
je     1142 <siglongjmp+0x22>
mov    0x2eb2(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <longjmp@plt>

LLVM IR (-O0):
@SIG_SETMASK = global i32 0
define void @siglongjmp(i64* %0, i32 %1) {
%3 = alloca i64*
%4 = alloca i32
%5 = alloca i64*
%6 = alloca i32*
store i64* %0, i64** %3
store i32 %1, i32* %4
%7 = load i64*, i64** %3
%8 = getelementptr inbounds i64, i64* %7, i64 0
%9 = getelementptr inbounds i64, i64* %8, i64 -1
store i64* %9, i64** %5
%10 = load i64*, i64** %5
%11 = getelementptr inbounds i64, i64* %10, i64 1
%12 = bitcast i64* %11 to i8*
%13 = bitcast i8* %12 to i32*
store i32* %13, i32** %6
%14 = load i64*, i64** %5
%15 = load i64, i64* %14
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* @SIG_SETMASK
%19 = load i32*, i32** %6
%20 = call i32 @sigprocmask(i32 %18, i32* %19, i32* null)
br label %21
21: ; preds = %17, %2
%22 = load i64*, i64** %3
%23 = bitcast i64* %22 to i8*
%24 = load i32, i32* %4
%25 = call i32 @longjmp(i8* %23, i32 %24)
unreachable
}

LLVM IR (-O2):
@SIG_SETMASK = global i32 0
define void @siglongjmp(i64* %0, i32 %1) {
%3 = getelementptr inbounds i64, i64* %0, i64 -1
%4 = load i64, i64* %3
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = bitcast i64* %0 to i32*
%8 = load i32, i32* @SIG_SETMASK
%9 = tail call i32 @sigprocmask(i32 %8, i32* %7, i32* null)
br label %10
10: ; preds = %6, %2
%11 = bitcast i64* %0 to i8*
%12 = tail call i32 @longjmp(i8* %11, i32 %1)
unreachable
}