#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 {
  int /*<<< orphan*/ sa_handler;
};
typedef int /*<<< orphan*/ act;

/* Variables and functions */
int /*<<< orphan*/ SIG_DFL;
int _NSIG;
int /*<<< orphan*/ bzero(struct sigaction *, int);
int /*<<< orphan*/ sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
void reset_sighandlers(void) {
  int i = 0;
  struct sigaction act;
  bzero(&act, sizeof(act));
  act.sa_handler = SIG_DFL;
  for (i = 1; i < _NSIG; i++) {
    sigaction(i, &act, NULL);
  }
}


x86 assembly (clang, -O0):
<reset_sighandlers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
mov    $0x4,%esi
call   1040 <bzero@plt>
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e96(%rip),%rcx
cmp    (%rcx),%eax
jge    1180 <reset_sighandlers+0x60>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1150 <reset_sighandlers+0x30>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reset_sighandlers>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2eb8(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2ec3(%rip),%r15
cmpl   $0x2,(%r15)
jl     1154 <reset_sighandlers+0x44>
mov    $0x1,%ebx
lea    0x8(%rsp),%r14
nopl   (%rax)
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
add    $0x1,%ebx
cmp    (%r15),%ebx
jl     1140 <reset_sighandlers+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sigaction = type { i32 }
@SIG_DFL = global i32 0
@_NSIG = global i32 0
define void @reset_sighandlers() {
%1 = alloca i32
%2 = alloca %struct.sigaction
store i32 0, i32* %1
%3 = call i32 @bzero(%struct.sigaction* %2, i32 4)
%4 = load i32, i32* @SIG_DFL
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i32 0, i32 0
store i32 %4, i32* %5
store i32 1, i32* %1
br label %6
6: ; preds = %13, %0
%7 = load i32, i32* %1
%8 = load i32, i32* @_NSIG
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %16
10: ; preds = %6
%11 = load i32, i32* %1
%12 = call i32 @sigaction(i32 %11, %struct.sigaction* %2, i32* null)
br label %13
13: ; preds = %10
%14 = load i32, i32* %1
%15 = add nsw i32 %14, 1
store i32 %15, i32* %1
br label %6
16: ; preds = %6
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { i32 }
@SIG_DFL = global i32 0
@_NSIG = global i32 0
define void @reset_sighandlers() {
%1 = alloca %struct.sigaction
%2 = bitcast %struct.sigaction* %1 to i8*
%3 = load i32, i32* @SIG_DFL
%4 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 0
store i32 %3, i32* %4
%5 = load i32, i32* @_NSIG
%6 = icmp sgt i32 %5, 1
br i1 %6, label %7, label %13
7: ; preds = %0, %7
%8 = phi i32 [ %10, %7 ], [ 1, %0 ]
%9 = call i32 @sigaction(i32 %8, %struct.sigaction* %1, i32* null)
%10 = add nuw nsw i32 %8, 1
%11 = load i32, i32* @_NSIG
%12 = icmp slt i32 %10, %11
br i1 %12, label %7, label %13
13: ; preds = %7, %0
ret void
}