#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_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ uc_sigmask;
};
typedef TYPE_1__ ucontext_t;
typedef int /*<<< orphan*/ sigset_t;
typedef int /*<<< orphan*/ siginfo_t;

/* Variables and functions */
int /*<<< orphan*/ CheckSigs(int /*<<< orphan*/ *, char *);
int SIGUSR1;
int /*<<< orphan*/ SIG_SETMASK;
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/ *);
void Handle(int sig, siginfo_t *info, void *vctxt) {
  ucontext_t *ctxt = vctxt;
  sigset_t ss;
  printf("Received %s\n", (sig == SIGUSR1) ? "USR1" : "USR2");
  sigprocmask(SIG_SETMASK, 0, &ss);
  CheckSigs(&ss, "In handler");
  CheckSigs(&ctxt->uc_sigmask, "Previous mask");
}


x86 assembly (clang, -O0):
<Handle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%ecx
mov    0x2e93(%rip),%rax
mov    (%rax),%edx
lea    0xeb4(%rip),%rsi
lea    0xea8(%rip),%rax
cmp    %edx,%ecx
cmove  %rax,%rsi
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
lea    -0x24(%rbp),%rdx
call   1030 <sigprocmask@plt>
lea    -0x24(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1050 <CheckSigs@plt>
mov    -0x20(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1050 <CheckSigs@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Handle>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    0x2eaa(%rip),%rax
cmp    %edi,(%rax)
lea    0xec6(%rip),%rax
lea    0xec4(%rip),%rsi
cmove  %rax,%rsi
lea    0xea7(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rsp),%rbx
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <sigprocmask@plt>
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
call   1050 <CheckSigs@plt>
lea    0xe96(%rip),%rsi
mov    %r14,%rdi
call   1050 <CheckSigs@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.TYPE_2__ = type { i32 }
@.str = [13 x i8] c"Received %s\0A\00"
@SIGUSR1 = global i32 0
@.str.1 = [5 x i8] c"USR1\00"
@.str.2 = [5 x i8] c"USR2\00"
@SIG_SETMASK = global i32 0
@.str.3 = [11 x i8] c"In handler\00"
@.str.4 = [14 x i8] c"Previous mask\00"
define void @Handle(i32 %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca %struct.TYPE_2__*
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = bitcast i8* %9 to %struct.TYPE_2__*
store %struct.TYPE_2__* %10, %struct.TYPE_2__** %7
%11 = load i32, i32* %4
%12 = load i32, i32* @SIGUSR1
%13 = icmp eq i32 %11, %12
%14 = zext i1 %13 to i64
%15 = select i1 %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @SIG_SETMASK
%18 = call i32 @sigprocmask(i32 %17, i32 0, i32* %8)
%19 = call i32 @CheckSigs(i32* %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%20 = load %struct.TYPE_2__*, %struct.TYPE_2__** %7
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
%22 = call i32 @CheckSigs(i32* %21, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"Received %s\0A\00"
@SIGUSR1 = global i32 0
@.str.1 = [5 x i8] c"USR1\00"
@.str.2 = [5 x i8] c"USR2\00"
@SIG_SETMASK = global i32 0
@.str.3 = [11 x i8] c"In handler\00"
@.str.4 = [14 x i8] c"Previous mask\00"
define void @Handle(i32 %0, i32* nocapture readnone %1, i8* %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = load i32, i32* @SIGUSR1
%7 = icmp eq i32 %6, %0
%8 = select i1 %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @SIG_SETMASK
%11 = call i32 @sigprocmask(i32 %10, i32 0, i32* %4)
%12 = call i32 @CheckSigs(i32* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%13 = bitcast i8* %2 to i32*
%14 = call i32 @CheckSigs(i32* %13, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
ret void
}