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

/* Variables and functions */
int /*<<< orphan*/ SA_RESTART;
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ SIGTSTP;
int /*<<< orphan*/ SIGTTIN;
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ exit_on_error(int /*<<< orphan*/, char *);
int /*<<< orphan*/ sigaction(int /*<<< orphan*/, struct sigaction *,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int setup_child_signals() {
  struct sigaction s;
  s.sa_handler = SIG_DFL;
  sigemptyset(&s.sa_mask);
  s.sa_flags = SA_RESTART;
  exit_on_error(sigaction(SIGINT, &s, NULL),
                "Error in setting action for SIGINT");
  exit_on_error(sigaction(SIGTSTP, &s, NULL),
                "Error in setting action for SIGTSTP");
  exit_on_error(sigaction(SIGTTIN, &s, NULL),
                "Error in setting action for SIGTTIN");
  exit_on_error(sigaction(SIGCHLD, &s, NULL),
                "Error in setting action for SIGCHLD");
  exit_on_error(sigaction(SIGQUIT, &s, NULL),
                "Error in setting action for SIGQUIT");
  return 0;
}


x86 assembly (clang, -O0):
<setup_child_signals>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
add    $0x4,%rdi
call   1050 <sigemptyset@plt>
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    %eax,%edi
lea    0xe84(%rip),%rsi
call   1040 <exit_on_error@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    %eax,%edi
lea    0xe83(%rip),%rsi
call   1040 <exit_on_error@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    %eax,%edi
lea    0xe83(%rip),%rsi
call   1040 <exit_on_error@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    %eax,%edi
lea    0xe83(%rip),%rsi
call   1040 <exit_on_error@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    %eax,%edi
lea    0xe83(%rip),%rsi
call   1040 <exit_on_error@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_child_signals>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0x4(%rsp),%rdi
call   1050 <sigemptyset@plt>
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
lea    0xe8b(%rip),%rsi
mov    %eax,%edi
call   1040 <exit_on_error@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
lea    0xe8d(%rip),%rsi
mov    %eax,%edi
call   1040 <exit_on_error@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
lea    0xe90(%rip),%rsi
mov    %eax,%edi
call   1040 <exit_on_error@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
lea    0xe93(%rip),%rsi
mov    %eax,%edi
call   1040 <exit_on_error@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
lea    0xe96(%rip),%rsi
mov    %eax,%edi
call   1040 <exit_on_error@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sigaction = type { i32, i32, i32 }
@SIG_DFL = global i32 0
@SA_RESTART = global i32 0
@SIGINT = global i32 0
@.str = [35 x i8] c"Error in setting action for SIGINT\00"
@SIGTSTP = global i32 0
@.str.1 = [36 x i8] c"Error in setting action for SIGTSTP\00"
@SIGTTIN = global i32 0
@.str.2 = [36 x i8] c"Error in setting action for SIGTTIN\00"
@SIGCHLD = global i32 0
@.str.3 = [36 x i8] c"Error in setting action for SIGCHLD\00"
@SIGQUIT = global i32 0
@.str.4 = [36 x i8] c"Error in setting action for SIGQUIT\00"
define i32 @setup_child_signals() {
%1 = alloca %struct.sigaction
%2 = load i32, i32* @SIG_DFL
%3 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i32 0, i32 2
store i32 %2, i32* %3
%4 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i32 0, i32 1
%5 = call i32 @sigemptyset(i32* %4)
%6 = load i32, i32* @SA_RESTART
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i32 0, i32 0
store i32 %6, i32* %7
%8 = load i32, i32* @SIGINT
%9 = call i32 @sigaction(i32 %8, %struct.sigaction* %1, i32* null)
%10 = call i32 @exit_on_error(i32 %9, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @SIGTSTP
%12 = call i32 @sigaction(i32 %11, %struct.sigaction* %1, i32* null)
%13 = call i32 @exit_on_error(i32 %12, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @SIGTTIN
%15 = call i32 @sigaction(i32 %14, %struct.sigaction* %1, i32* null)
%16 = call i32 @exit_on_error(i32 %15, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* @SIGCHLD
%18 = call i32 @sigaction(i32 %17, %struct.sigaction* %1, i32* null)
%19 = call i32 @exit_on_error(i32 %18, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32, i32* @SIGQUIT
%21 = call i32 @sigaction(i32 %20, %struct.sigaction* %1, i32* null)
%22 = call i32 @exit_on_error(i32 %21, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sigaction = type { i32, i32, i32 }
@SIG_DFL = global i32 0
@SA_RESTART = global i32 0
@SIGINT = global i32 0
@.str = [35 x i8] c"Error in setting action for SIGINT\00"
@SIGTSTP = global i32 0
@.str.1 = [36 x i8] c"Error in setting action for SIGTSTP\00"
@SIGTTIN = global i32 0
@.str.2 = [36 x i8] c"Error in setting action for SIGTTIN\00"
@SIGCHLD = global i32 0
@.str.3 = [36 x i8] c"Error in setting action for SIGCHLD\00"
@SIGQUIT = global i32 0
@.str.4 = [36 x i8] c"Error in setting action for SIGQUIT\00"
define i32 @setup_child_signals() {
%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 2
store i32 %3, i32* %4
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 1
%6 = call i32 @sigemptyset(i32* %5)
%7 = load i32, i32* @SA_RESTART
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 0
store i32 %7, i32* %8
%9 = load i32, i32* @SIGINT
%10 = call i32 @sigaction(i32 %9, %struct.sigaction* %1, i32* null)
%11 = call i32 @exit_on_error(i32 %10, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @SIGTSTP
%13 = call i32 @sigaction(i32 %12, %struct.sigaction* %1, i32* null)
%14 = call i32 @exit_on_error(i32 %13, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @SIGTTIN
%16 = call i32 @sigaction(i32 %15, %struct.sigaction* %1, i32* null)
%17 = call i32 @exit_on_error(i32 %16, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32, i32* @SIGCHLD
%19 = call i32 @sigaction(i32 %18, %struct.sigaction* %1, i32* null)
%20 = call i32 @exit_on_error(i32 %19, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* @SIGQUIT
%22 = call i32 @sigaction(i32 %21, %struct.sigaction* %1, i32* null)
%23 = call i32 @exit_on_error(i32 %22, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}