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

/* Variables and functions */
int /*<<< orphan*/ SIGUSR1;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ assert(int);
int sigismember(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
size_t write(int /*<<< orphan*/, char const *, size_t);
void signal_handler(int signo, siginfo_t *info, void *uc) {
  ssize_t written;
  const char str[] = "Signal caught.\n";
  size_t len = sizeof(str) - 1;
  sigset_t current;
  written = write(STDOUT_FILENO, str, len);
  assert(written == len);
  assert(!sigprocmask(SIG_BLOCK, NULL, &current));
  assert(sigismember(&current, SIGUSR1));
}


x86 assembly (clang, -O0):
<signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0xea6(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xea3(%rip),%rax
mov    %rax,-0x28(%rbp)
movq   $0xf,-0x38(%rbp)
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <write@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x38(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x3c(%rbp),%rdx
call   1030 <sigprocmask@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
lea    -0x3c(%rbp),%rdi
call   1060 <sigismember@plt>
mov    %eax,%edi
call   1050 <assert@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_handler>:
push   %rbx
sub    $0x20,%rsp
movaps 0xeb4(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
mov    $0xf,%edx
call   1040 <write@plt>
xor    %edi,%edi
cmp    $0xf,%rax
sete   %dil
call   1050 <assert@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rbx
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <sigprocmask@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <sigismember@plt>
mov    %eax,%edi
call   1050 <assert@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.signal_handler.str = [16 x i8] c"Signal caught.\0A\00"
@STDOUT_FILENO = global i32 0
@SIG_BLOCK = global i32 0
@SIGUSR1 = global i32 0
define void @signal_handler(i32 %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [16 x i8]
%9 = alloca i64
%10 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%11 = bitcast [16 x i8]* %8 to i8*
store i64 15, i64* %9
%12 = load i32, i32* @STDOUT_FILENO
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%14 = load i64, i64* %9
%15 = call i64 @write(i32 %12, i8* %13, i64 %14)
store i64 %15, i64* %7
%16 = load i64, i64* %7
%17 = load i64, i64* %9
%18 = icmp eq i64 %16, %17
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* @SIG_BLOCK
%22 = call i32 @sigprocmask(i32 %21, i32* null, i32* %10)
%23 = icmp ne i32 %22, 0
%24 = xor i1 %23, true
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i32, i32* @SIGUSR1
%28 = call i32 @sigismember(i32* %10, i32 %27)
%29 = call i32 @assert(i32 %28)
ret void
}

LLVM IR (-O2):
@__const.signal_handler.str = [16 x i8] c"Signal caught.\0A\00"
@STDOUT_FILENO = global i32 0
@SIG_BLOCK = global i32 0
@SIGUSR1 = global i32 0
define void @signal_handler(i32 %0, i32* nocapture readnone %1, i8* nocapture readnone %2) {
%4 = alloca [16 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%7 = bitcast i32* %5 to i8*
%8 = load i32, i32* @STDOUT_FILENO
%9 = call i64 @write(i32 %8, i8* %6, i64 15)
%10 = icmp eq i64 %9, 15
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = load i32, i32* @SIG_BLOCK
%14 = call i32 @sigprocmask(i32 %13, i32* null, i32* %5)
%15 = icmp eq i32 %14, 0
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i32, i32* @SIGUSR1
%19 = call i32 @sigismember(i32* %5, i32 %18)
%20 = call i32 @assert(i32 %19)
ret void
}