#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 */
struct sigaction {
  scalar_t__ sa_handler;
  int /*<<< orphan*/ sa_mask;
};
typedef int /*<<< orphan*/ sigset_t;
typedef int /*<<< orphan*/ sa;

/* Variables and functions */
int /*<<< orphan*/ SIGABRT;
int /*<<< orphan*/ SIG_BLOCK;
scalar_t__ SIG_DFL;
int /*<<< orphan*/ __sigdelset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ __sigfillset(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sigaction *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sigaction(int /*<<< orphan*/, struct sigaction *,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
void block_signals(void) {
  struct sigaction sa;
  sigset_t mask;
  __sigfillset(&mask);
  __sigdelset(&mask, SIGABRT);
  sigprocmask(SIG_BLOCK, &mask, NULL);
  memset(&sa, 0, sizeof(sa));
  __sigfillset(&sa.sa_mask);
  if (SIG_DFL)
    sa.sa_handler = SIG_DFL;
  sigaction(SIGABRT, &sa, NULL);
}


x86 assembly (clang, -O0):
<block_signals>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x14(%rbp),%rdi
call   1060 <__sigfillset@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1070 <__sigdelset@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    -0x10(%rbp),%rdi
add    $0x8,%rdi
call   1060 <__sigfillset@plt>
mov    0x2e2b(%rip),%rax
cmpq   $0x0,(%rax)
je     11c5 <block_signals+0x75>
mov    0x2e1a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigaction@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<block_signals>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0x14(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <__sigfillset@plt>
mov    0x2e65(%rip),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   1070 <__sigdelset@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    0x8(%rsp),%rdi
call   1060 <__sigfillset@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%rax
test   %rax,%rax
je     11b5 <block_signals+0x65>
mov    %rax,(%rsp)
mov    (%r14),%edi
mov    %rsp,%rsi
xor    %edx,%edx
call   1040 <sigaction@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sigaction = type { i64, i32 }
@SIGABRT = global i32 0
@SIG_BLOCK = global i32 0
@SIG_DFL = global i64 0
define void @block_signals() {
%1 = alloca %struct.sigaction
%2 = alloca i32
%3 = call i32 @__sigfillset(i32* %2)
%4 = load i32, i32* @SIGABRT
%5 = call i32 @__sigdelset(i32* %2, i32 %4)
%6 = load i32, i32* @SIG_BLOCK
%7 = call i32 @sigprocmask(i32 %6, i32* %2, i32* null)
%8 = call i32 @memset(%struct.sigaction* %1, i32 0, i32 16)
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i32 0, i32 1
%10 = call i32 @__sigfillset(i32* %9)
%11 = load i64, i64* @SIG_DFL
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = load i64, i64* @SIG_DFL
%15 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i32 0, i32 0
store i64 %14, i64* %15
br label %16
16: ; preds = %13, %0
%17 = load i32, i32* @SIGABRT
%18 = call i32 @sigaction(i32 %17, %struct.sigaction* %1, i32* null)
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { i64, i32 }
@SIGABRT = global i32 0
@SIG_BLOCK = global i32 0
@SIG_DFL = global i64 0
define void @block_signals() {
%1 = alloca %struct.sigaction
%2 = alloca i32
%3 = bitcast %struct.sigaction* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @__sigfillset(i32* %2)
%6 = load i32, i32* @SIGABRT
%7 = call i32 @__sigdelset(i32* %2, i32 %6)
%8 = load i32, i32* @SIG_BLOCK
%9 = call i32 @sigprocmask(i32 %8, i32* %2, i32* null)
%10 = call i32 @memset(%struct.sigaction* %1, i32 0, i32 16)
%11 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 1
%12 = call i32 @__sigfillset(i32* %11)
%13 = load i64, i64* @SIG_DFL
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %0
%16 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 0
store i64 %13, i64* %16
br label %17
17: ; preds = %15, %0
%18 = load i32, i32* @SIGABRT
%19 = call i32 @sigaction(i32 %18, %struct.sigaction* %1, i32* null)
ret void
}