#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_flags;
  int /*<<< orphan*/ sa_handler;
  int /*<<< orphan*/ sa_mask;
};
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ SIG_UNBLOCK;
int /*<<< orphan*/ sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
void signal_reset() {
  for (int signo = 1; signo < 64; ++signo) {
    struct sigaction action;
    sigset_t mask;
    sigemptyset(&action.sa_mask);
    action.sa_handler = SIG_DFL;
    action.sa_flags = 0;
    sigaction(signo, &action, NULL);
    sigemptyset(&mask);
    sigaddset(&mask, signo);
    sigprocmask(SIG_UNBLOCK, &mask, NULL);
  }
}


x86 assembly (clang, -O0):
<signal_reset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x1,-0x4(%rbp)
cmpl   $0x40,-0x4(%rbp)
jge    11c3 <signal_reset+0x83>
lea    -0x18(%rbp),%rdi
add    $0xc,%rdi
call   1050 <sigemptyset@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigaction@plt>
lea    -0x1c(%rbp),%rdi
call   1050 <sigemptyset@plt>
mov    -0x4(%rbp),%esi
lea    -0x1c(%rbp),%rdi
call   1060 <sigaddset@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    -0x1c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    114f <signal_reset+0xf>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_reset>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%ebx
lea    0xc(%rsp),%r14
mov    0x2e79(%rip),%r13
mov    %rsp,%r15
lea    0x14(%rsp),%r12
mov    0x2e7a(%rip),%rbp
xchg   %ax,%ax
mov    %r14,%rdi
call   1050 <sigemptyset@plt>
mov    0x0(%r13),%eax
mov    %eax,0x8(%rsp)
movq   $0x0,(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
xor    %edx,%edx
call   1040 <sigaction@plt>
mov    %r12,%rdi
call   1050 <sigemptyset@plt>
mov    %r12,%rdi
mov    %ebx,%esi
call   1060 <sigaddset@plt>
mov    0x0(%rbp),%edi
mov    %r12,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
add    $0x1,%ebx
cmp    $0x40,%ebx
jne    1170 <signal_reset+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sigaction = type { i64, i32, i32 }
@SIG_DFL = global i32 0
@SIG_UNBLOCK = global i32 0
define void @signal_reset() {
%1 = alloca i32
%2 = alloca %struct.sigaction
%3 = alloca i32
store i32 1, i32* %1
br label %4
4: ; preds = %20, %0
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 64
br i1 %6, label %7, label %23
7: ; preds = %4
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i32 0, i32 2
%9 = call i32 @sigemptyset(i32* %8)
%10 = load i32, i32* @SIG_DFL
%11 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i32 0, i32 1
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i32 0, i32 0
store i64 0, i64* %12
%13 = load i32, i32* %1
%14 = call i32 @sigaction(i32 %13, %struct.sigaction* %2, i32* null)
%15 = call i32 @sigemptyset(i32* %3)
%16 = load i32, i32* %1
%17 = call i32 @sigaddset(i32* %3, i32 %16)
%18 = load i32, i32* @SIG_UNBLOCK
%19 = call i32 @sigprocmask(i32 %18, i32* %3, i32* null)
br label %20
20: ; preds = %7
%21 = load i32, i32* %1
%22 = add nsw i32 %21, 1
store i32 %22, i32* %1
br label %4
23: ; preds = %4
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { i64, i32, i32 }
@SIG_DFL = global i32 0
@SIG_UNBLOCK = global i32 0
define void @signal_reset() {
%1 = alloca %struct.sigaction
%2 = alloca i32
%3 = bitcast %struct.sigaction* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 2
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 1
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 0
br label %9
8: ; preds = %9
ret void
9: ; preds = %0, %9
%10 = phi i32 [ 1, %0 ], [ %18, %9 ]
%11 = call i32 @sigemptyset(i32* %5)
%12 = load i32, i32* @SIG_DFL
store i32 %12, i32* %6
store i64 0, i64* %7
%13 = call i32 @sigaction(i32 %10, %struct.sigaction* %1, i32* null)
%14 = call i32 @sigemptyset(i32* %2)
%15 = call i32 @sigaddset(i32* %2, i32 %10)
%16 = load i32, i32* @SIG_UNBLOCK
%17 = call i32 @sigprocmask(i32 %16, i32* %2, i32* null)
%18 = add nuw nsw i32 %10, 1
%19 = icmp eq i32 %18, 64
br i1 %19, label %8, label %9
}