#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;
  int /*<<< orphan*/ sa_flags;
};
typedef int /*<<< orphan*/ sa;

/* Variables and functions */
int /*<<< orphan*/ SA_SIGINFO;
int const SIGHUP;
int const SIGINT;
int const SIGTSTP;
int const SIGTTIN;
int const SIGTTOU;
int /*<<< orphan*/ SIG_IGN;
int errno;
int /*<<< orphan*/ memset(struct sigaction *, int /*<<< orphan*/, int);
scalar_t__ sigaction(int const, struct sigaction *, int /*<<< orphan*/ *);
int _ignore_signals(void) {
  const int signals[] = {SIGHUP, SIGINT, SIGTSTP, SIGTTIN, SIGTTOU};
  int num_signals;
  struct sigaction sa;
  memset(&sa, 0, sizeof(sa));
  sa.sa_flags = SA_SIGINFO;
  sa.sa_handler = SIG_IGN;
  num_signals = (sizeof((signals)) / sizeof((signals)[0]));
  while (num_signals--) {
    if (sigaction(signals[num_signals], &sa, NULL) < 0)
      return -errno;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_ignore_signals>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2ec1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
movl   $0x5,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x24(%rbp)
cmp    $0x0,%eax
je     11de <_ignore_signals+0xbe>
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
jge    11d9 <_ignore_signals+0xb9>
xor    %eax,%eax
mov    0x2de1(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e5 <_ignore_signals+0xc5>
jmp    1193 <_ignore_signals+0x73>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ignore_signals>:
push   %r14
push   %rbx
push   %rax
mov    %rsp,%rbx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
xor    %edi,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
js     11a9 <_ignore_signals+0x89>
mov    %rsp,%rsi
xor    %edi,%edi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
js     11a9 <_ignore_signals+0x89>
mov    %rsp,%rsi
xor    %edi,%edi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
js     11a9 <_ignore_signals+0x89>
xor    %ebx,%ebx
mov    %rsp,%rsi
xor    %edi,%edi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
js     11a9 <_ignore_signals+0x89>
mov    %rsp,%rsi
xor    %edi,%edi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
jns    11b6 <_ignore_signals+0x96>
mov    0x2e28(%rip),%rax
sub    (%rax),%r14d
mov    %r14d,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sigaction = type { i32, i32 }
@SIGHUP = constant i32 0
@SIGINT = constant i32 0
@SIGTSTP = constant i32 0
@SIGTTIN = constant i32 0
@SIGTTOU = constant i32 0
@SA_SIGINFO = global i32 0
@SIG_IGN = global i32 0
@errno = global i32 0
define i32 @_ignore_signals() {
%1 = alloca i32
%2 = alloca [5 x i32]
%3 = alloca i32
%4 = alloca %struct.sigaction
%5 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%6 = load i32, i32* @SIGHUP
store i32 %6, i32* %5
%7 = getelementptr inbounds i32, i32* %5, i64 1
%8 = load i32, i32* @SIGINT
store i32 %8, i32* %7
%9 = getelementptr inbounds i32, i32* %7, i64 1
%10 = load i32, i32* @SIGTSTP
store i32 %10, i32* %9
%11 = getelementptr inbounds i32, i32* %9, i64 1
%12 = load i32, i32* @SIGTTIN
store i32 %12, i32* %11
%13 = getelementptr inbounds i32, i32* %11, i64 1
%14 = load i32, i32* @SIGTTOU
store i32 %14, i32* %13
%15 = call i32 @memset(%struct.sigaction* %4, i32 0, i32 8)
%16 = load i32, i32* @SA_SIGINFO
%17 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i32 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* @SIG_IGN
%19 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i32 0, i32 0
store i32 %18, i32* %19
store i32 5, i32* %3
br label %20
20: ; preds = %34, %0
%21 = load i32, i32* %3
%22 = add nsw i32 %21, -1
store i32 %22, i32* %3
%23 = icmp ne i32 %21, 0
br i1 %23, label %24, label %35
24: ; preds = %20
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = call i64 @sigaction(i32 %28, %struct.sigaction* %4, i32* null)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %24
%32 = load i32, i32* @errno
%33 = sub nsw i32 0, %32
store i32 %33, i32* %1
br label %36
34: ; preds = %24
br label %20
35: ; preds = %20
store i32 0, i32* %1
br label %36
36: ; preds = %35, %31
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
%struct.sigaction = type { i32, i32 }
@SIGHUP = constant i32 0
@SIGINT = constant i32 0
@SIGTSTP = constant i32 0
@SIGTTIN = constant i32 0
@SIGTTOU = constant i32 0
@SA_SIGINFO = global i32 0
@SIG_IGN = global i32 0
@errno = global i32 0
define i32 @_ignore_signals() {
%1 = alloca %struct.sigaction
%2 = bitcast %struct.sigaction* %1 to i8*
%3 = call i32 @memset(%struct.sigaction* %1, i32 0, i32 8)
%4 = load i32, i32* @SA_SIGINFO
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 1
store i32 %4, i32* %5
%6 = load i32, i32* @SIG_IGN
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 0
store i32 %6, i32* %7
%8 = call i64 @sigaction(i32 0, %struct.sigaction* %1, i32* null)
%9 = icmp slt i64 %8, 0
br i1 %9, label %22, label %10
10: ; preds = %0
%11 = call i64 @sigaction(i32 0, %struct.sigaction* %1, i32* null)
%12 = icmp slt i64 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %10
%14 = call i64 @sigaction(i32 0, %struct.sigaction* %1, i32* null)
%15 = icmp slt i64 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = call i64 @sigaction(i32 0, %struct.sigaction* %1, i32* null)
%18 = icmp slt i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = call i64 @sigaction(i32 0, %struct.sigaction* %1, i32* null)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19, %16, %13, %10, %0
%23 = load i32, i32* @errno
%24 = sub nsw i32 0, %23
br label %25
25: ; preds = %19, %22
%26 = phi i32 [ %24, %22 ], [ 0, %19 ]
ret i32 %26
}