#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ sigset_t;
typedef TYPE_1__ *sigjmp_buf;
struct TYPE_4__ {
  int /*<<< orphan*/ __jmpbuf;
  int /*<<< orphan*/ __saved_mask;
  scalar_t__ __mask_was_saved;
};

/* Variables and functions */
int /*<<< orphan*/ SIG_SETMASK;
int /*<<< orphan*/ __longjmp(int /*<<< orphan*/, int);
int /*<<< orphan*/ __sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                                 int /*<<< orphan*/ *);
int /*<<< orphan*/ _longjmp_unwind(TYPE_1__ *, int);
void __libc_siglongjmp(sigjmp_buf env, int val) {
  _longjmp_unwind(env, val);
  if (env[0].__mask_was_saved)
    (void)__sigprocmask(SIG_SETMASK, &env[0].__saved_mask, (sigset_t *)NULL);
  __longjmp(env[0].__jmpbuf, val ?: 1);
}


x86 assembly (clang, -O0):
<__libc_siglongjmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <_longjmp_unwind@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     1174 <__libc_siglongjmp+0x44>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
add    $0x4,%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <__sigprocmask@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     1197 <__libc_siglongjmp+0x67>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11a4 <__libc_siglongjmp+0x74>
mov    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a4 <__libc_siglongjmp+0x74>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <__longjmp@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__libc_siglongjmp>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <_longjmp_unwind@plt>
cmpq   $0x0,0x8(%rbx)
je     1158 <__libc_siglongjmp+0x28>
mov    0x2e9d(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rbx),%rsi
xor    %edx,%edx
call   1050 <__sigprocmask@plt>
mov    (%rbx),%edi
test   %ebp,%ebp
mov    $0x1,%esi
cmovne %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <__longjmp@plt>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32, i64 }
@SIG_SETMASK = global i32 0
define void @__libc_siglongjmp(%struct.TYPE_4__* %0, i32 %1) {
%3 = alloca %struct.TYPE_4__*
%4 = alloca i32
store %struct.TYPE_4__* %0, %struct.TYPE_4__** %3
store i32 %1, i32* %4
%5 = load %struct.TYPE_4__*, %struct.TYPE_4__** %3
%6 = load i32, i32* %4
%7 = call i32 @_longjmp_unwind(%struct.TYPE_4__* %5, i32 %6)
%8 = load %struct.TYPE_4__*, %struct.TYPE_4__** %3
%9 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %8, i64 0
%10 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %9, i32 0, i32 2
%11 = load i64, i64* %10
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @SIG_SETMASK
%15 = load %struct.TYPE_4__*, %struct.TYPE_4__** %3
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %15, i64 0
%17 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %16, i32 0, i32 1
%18 = call i32 @__sigprocmask(i32 %14, i32* %17, i32* null)
br label %19
19: ; preds = %13, %2
%20 = load %struct.TYPE_4__*, %struct.TYPE_4__** %3
%21 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %20, i64 0
%22 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %19
br label %28
27: ; preds = %19
br label %28
28: ; preds = %27, %26
%29 = phi i32 [ %24, %26 ], [ 1, %27 ]
%30 = call i32 @__longjmp(i32 %23, i32 %29)
ret void
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32, i64 }
@SIG_SETMASK = global i32 0
define void @__libc_siglongjmp(%struct.TYPE_4__* %0, i32 %1) {
%3 = tail call i32 @_longjmp_unwind(%struct.TYPE_4__* %0, i32 %1)
%4 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 2
%5 = load i64, i64* %4
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i32, i32* @SIG_SETMASK
%9 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 1
%10 = tail call i32 @__sigprocmask(i32 %8, i32* %9, i32* null)
br label %11
11: ; preds = %7, %2
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 0
%13 = load i32, i32* %12
%14 = icmp eq i32 %1, 0
%15 = select i1 %14, i32 1, i32 %1
%16 = tail call i32 @__longjmp(i32 %13, i32 %15)
ret void
}