#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;
};

/* Variables and functions */
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ exit_errno(int);
int /*<<< orphan*/ memset(struct sigaction *, int /*<<< orphan*/, int);
int sigaction(int const, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ unblock_signals();
void reset_signal_handler(const int list[], const int list_len) {
  struct sigaction act;
  memset(&act, 0, sizeof(struct sigaction));
  act.sa_handler = SIG_DFL;
  for (int i = 0; i < list_len; ++i) {
    if (sigaction(list[i], &act, NULL) == -1)
      exit_errno(70);
  }
  unblock_signals();
}


x86 assembly (clang, -O0):
<reset_signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bc <reset_signal_handler+0x7c>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0xffffffff,%eax
jne    11a9 <reset_signal_handler+0x69>
mov    $0x46,%edi
call   1060 <exit_errno@plt>
jmp    11ae <reset_signal_handler+0x6e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1172 <reset_signal_handler+0x32>
mov    $0x0,%al
call   1050 <unblock_signals@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reset_signal_handler>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r15
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
test   %ebp,%ebp
jle    11a8 <reset_signal_handler+0x68>
mov    %ebp,%ebp
xor    %ebx,%ebx
mov    %rsp,%r14
jmp    1189 <reset_signal_handler+0x49>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11a8 <reset_signal_handler+0x68>
mov    (%r15,%rbx,4),%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
cmp    $0xffffffff,%eax
jne    1180 <reset_signal_handler+0x40>
mov    $0x46,%edi
call   1060 <exit_errno@plt>
jmp    1180 <reset_signal_handler+0x40>
xor    %eax,%eax
call   1050 <unblock_signals@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sigaction = type { i32 }
@SIG_DFL = global i32 0
define void @reset_signal_handler(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca %struct.sigaction
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = call i32 @memset(%struct.sigaction* %5, i32 0, i32 4)
%8 = load i32, i32* @SIG_DFL
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 0
store i32 %8, i32* %9
store i32 0, i32* %6
br label %10
10: ; preds = %25, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %28
14: ; preds = %10
%15 = load i32*, i32** %3
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = call i32 @sigaction(i32 %19, %struct.sigaction* %5, i32* null)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 @exit_errno(i32 70)
br label %24
24: ; preds = %22, %14
br label %25
25: ; preds = %24
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %10
28: ; preds = %10
%29 = call i32 (...) @unblock_signals()
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { i32 }
@SIG_DFL = global i32 0
define void @reset_signal_handler(i32* nocapture %0, i32 %1) {
%3 = alloca %struct.sigaction
%4 = bitcast %struct.sigaction* %3 to i8*
%5 = call i32 @memset(%struct.sigaction* %3, i32 0, i32 4)
%6 = load i32, i32* @SIG_DFL
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
store i32 %6, i32* %7
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = zext i32 %1 to i64
br label %13
11: ; preds = %21, %2
%12 = call i32 (...) @unblock_signals()
ret void
13: ; preds = %9, %21
%14 = phi i64 [ 0, %9 ], [ %22, %21 ]
%15 = getelementptr inbounds i32, i32* %0, i64 %14
%16 = load i32, i32* %15
%17 = call i32 @sigaction(i32 %16, %struct.sigaction* %3, i32* null)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @exit_errno(i32 70)
br label %21
21: ; preds = %13, %19
%22 = add nuw nsw i64 %14, 1
%23 = icmp eq i64 %22, %10
br i1 %23, label %11, label %13
}