#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 {
  void (*sa_handler)(int);
  int /*<<< orphan*/ sa_mask;
};

/* Variables and functions */
int /*<<< orphan*/ LOG_CRIT;
int /*<<< orphan*/ elog(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                        int const);
int /*<<< orphan*/ errno;
scalar_t__ sigaction(int const, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigfillset(int /*<<< orphan*/ *);
void setup_signals(void (*handler)(int sig), const int *table) {
  struct sigaction sa = {
      .sa_handler = handler,
  };
  int j;
  sigfillset(&sa.sa_mask);
  for (j = 0; table[j]; ++j) {
    if (sigaction(table[j], &sa, NULL) < 0)
      elog(LOG_CRIT, errno, "sigaction %i", table[j]);
  }
}


x86 assembly (clang, -O0):
<setup_signals>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
add    $0x8,%rdi
call   1040 <sigfillset@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     11d3 <setup_signals+0xa3>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
jge    11c0 <setup_signals+0x90>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xe45(%rip),%rdx
call   1050 <elog@plt>
jmp    11c5 <setup_signals+0x95>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1163 <setup_signals+0x33>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_signals>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,(%rsp)
lea    0x8(%rsp),%rdi
movl   $0x0,0x8(%rsp)
call   1040 <sigfillset@plt>
mov    (%rbx),%edi
test   %edi,%edi
je     11ae <setup_signals+0x7e>
add    $0x4,%rbx
mov    %rsp,%r14
mov    0x2e7e(%rip),%r12
mov    0x2e67(%rip),%r13
lea    0xe88(%rip),%r15
jmp    118a <setup_signals+0x5a>
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%edi
add    $0x4,%rbx
test   %edi,%edi
je     11ae <setup_signals+0x7e>
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
jns    1180 <setup_signals+0x50>
mov    (%r12),%edi
mov    0x0(%r13),%esi
mov    -0x4(%rbx),%ecx
mov    %r15,%rdx
call   1050 <elog@plt>
jmp    1180 <setup_signals+0x50>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sigaction = type { void (i32)*, i32 }
@LOG_CRIT = global i32 0
@errno = global i32 0
@.str = [13 x i8] c"sigaction %i\00"
define void @setup_signals(void (i32)* %0, i32* %1) {
%3 = alloca void (i32)*
%4 = alloca i32*
%5 = alloca %struct.sigaction
%6 = alloca i32
store void (i32)* %0, void (i32)** %3
store i32* %1, i32** %4
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 0
%8 = load void (i32)*, void (i32)** %3
store void (i32)* %8, void (i32)** %7
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 1
store i32 0, i32* %9
%10 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 1
%11 = call i32 @sigfillset(i32* %10)
store i32 0, i32* %6
br label %12
12: ; preds = %37, %2
%13 = load i32*, i32** %4
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = load i32, i32* %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %40
19: ; preds = %12
%20 = load i32*, i32** %4
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = call i64 @sigaction(i32 %24, %struct.sigaction* %5, i32* null)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %19
%28 = load i32, i32* @LOG_CRIT
%29 = load i32, i32* @errno
%30 = load i32*, i32** %4
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = call i32 @elog(i32 %28, i32 %29, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %27, %19
br label %37
37: ; preds = %36
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %12
40: ; preds = %12
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { void (i32)*, i32 }
@LOG_CRIT = global i32 0
@errno = global i32 0
@.str = [13 x i8] c"sigaction %i\00"
define void @setup_signals(void (i32)* %0, i32* nocapture %1) {
%3 = alloca %struct.sigaction
%4 = bitcast %struct.sigaction* %3 to i8*
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
store void (i32)* %0, void (i32)** %5
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
store i32 0, i32* %6
%7 = call i32 @sigfillset(i32* %6)
%8 = load i32, i32* %1
%9 = icmp eq i32 %8, 0
br i1 %9, label %26, label %10
10: ; preds = %2, %21
%11 = phi i64 [ %22, %21 ], [ 0, %2 ]
%12 = phi i32 [ %24, %21 ], [ %8, %2 ]
%13 = phi i32* [ %23, %21 ], [ %1, %2 ]
%14 = call i64 @sigaction(i32 %12, %struct.sigaction* %3, i32* null)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = load i32, i32* @LOG_CRIT
%18 = load i32, i32* @errno
%19 = load i32, i32* %13
%20 = call i32 @elog(i32 %17, i32 %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %10, %16
%22 = add nuw i64 %11, 1
%23 = getelementptr inbounds i32, i32* %1, i64 %22
%24 = load i32, i32* %23
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %10
26: ; preds = %21, %2
ret void
}