#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 */

/* Variables and functions */
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ SIG_DFL;
int SIG_IGN();
scalar_t__ isatty(int);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int (*)());
setsig() {
  int sigout();
  if (isatty(1)) {
    if (signal(SIGHUP, SIG_IGN) == SIG_DFL)
      signal(SIGHUP, sigout);
    if (signal(SIGINT, SIG_IGN) == SIG_DFL)
      signal(SIGINT, sigout);
  } else {
    signal(SIGHUP, SIG_IGN);
    signal(SIGINT, SIG_IGN);
  };
  signal(SIGQUIT, sigout);
  signal(SIGTERM, sigout);
}


x86 assembly (clang, -O0):
<setsig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x1,%edi
call   1030 <isatty@plt>
cmp    $0x0,%rax
je     11b3 <setsig+0x93>
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
mov    0x2e7c(%rip),%rsi
call   1040 <signal@plt>
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%eax
jne    1175 <setsig+0x55>
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
mov    0x2e40(%rip),%rsi
call   1040 <signal@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    0x2e43(%rip),%rsi
call   1040 <signal@plt>
mov    0x2e27(%rip),%rcx
cmp    (%rcx),%eax
jne    11ae <setsig+0x8e>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    0x2e07(%rip),%rsi
call   1040 <signal@plt>
jmp    11dd <setsig+0xbd>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    0x2e05(%rip),%rsi
call   1040 <signal@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    0x2df0(%rip),%rsi
call   1040 <signal@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    0x2dc3(%rip),%rsi
call   1040 <signal@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
mov    0x2dae(%rip),%rsi
call   1040 <signal@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setsig>:
push   %r15
push   %r14
push   %rbx
mov    $0x1,%edi
call   1030 <isatty@plt>
mov    %rax,%r14
mov    0x2eb7(%rip),%r15
mov    (%r15),%edi
mov    0x2e85(%rip),%rbx
mov    %rbx,%rsi
call   1040 <signal@plt>
test   %r14,%r14
je     118a <setsig+0x6a>
mov    0x2e61(%rip),%rbx
cmp    (%rbx),%eax
jne    116a <setsig+0x4a>
mov    (%r15),%edi
mov    0x2e4b(%rip),%rsi
call   1040 <signal@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
mov    0x2e4e(%rip),%rsi
call   1040 <signal@plt>
cmp    (%rbx),%eax
jne    119b <setsig+0x7b>
mov    0x2e26(%rip),%rbx
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1040 <signal@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    0x2e05(%rip),%rbx
mov    %rbx,%rsi
call   1040 <signal@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <signal@plt>

LLVM IR (-O0):
@SIGHUP = global i32 0
@SIG_DFL = global i32 0
@SIGINT = global i32 0
@SIGQUIT = global i32 0
@SIGTERM = global i32 0
define i32 @setsig() {
%1 = alloca i32
%2 = call i64 @isatty(i32 1)
%3 = icmp ne i64 %2, 0
br i1 %3, label %4, label %21
4: ; preds = %0
%5 = load i32, i32* @SIGHUP
%6 = call i32 @signal(i32 %5, i32 (...)* @SIG_IGN)
%7 = load i32, i32* @SIG_DFL
%8 = icmp eq i32 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i32, i32* @SIGHUP
%11 = call i32 @signal(i32 %10, i32 (...)* @sigout)
br label %12
12: ; preds = %9, %4
%13 = load i32, i32* @SIGINT
%14 = call i32 @signal(i32 %13, i32 (...)* @SIG_IGN)
%15 = load i32, i32* @SIG_DFL
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* @SIGINT
%19 = call i32 @signal(i32 %18, i32 (...)* @sigout)
br label %20
20: ; preds = %17, %12
br label %26
21: ; preds = %0
%22 = load i32, i32* @SIGHUP
%23 = call i32 @signal(i32 %22, i32 (...)* @SIG_IGN)
%24 = load i32, i32* @SIGINT
%25 = call i32 @signal(i32 %24, i32 (...)* @SIG_IGN)
br label %26
26: ; preds = %21, %20
%27 = load i32, i32* @SIGQUIT
%28 = call i32 @signal(i32 %27, i32 (...)* @sigout)
%29 = load i32, i32* @SIGTERM
%30 = call i32 @signal(i32 %29, i32 (...)* @sigout)
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@SIGHUP = global i32 0
@SIG_DFL = global i32 0
@SIGINT = global i32 0
@SIGQUIT = global i32 0
@SIGTERM = global i32 0
define i32 @setsig() {
%1 = tail call i64 @isatty(i32 1)
%2 = icmp eq i64 %1, 0
%3 = load i32, i32* @SIGHUP
%4 = tail call i32 @signal(i32 %3, i32 (...)* @SIG_IGN)
br i1 %2, label %16, label %5
5: ; preds = %0
%6 = load i32, i32* @SIG_DFL
%7 = icmp eq i32 %4, %6
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load i32, i32* @SIGHUP
%10 = tail call i32 @signal(i32 %9, i32 (...)* @sigout)
br label %11
11: ; preds = %8, %5
%12 = load i32, i32* @SIGINT
%13 = tail call i32 @signal(i32 %12, i32 (...)* @SIG_IGN)
%14 = load i32, i32* @SIG_DFL
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %0, %11
%17 = phi i32 (...)* [ @sigout, %11 ], [ @SIG_IGN, %0 ]
%18 = load i32, i32* @SIGINT
%19 = tail call i32 @signal(i32 %18, i32 (...)* %17)
br label %20
20: ; preds = %16, %11
%21 = load i32, i32* @SIGQUIT
%22 = tail call i32 @signal(i32 %21, i32 (...)* @sigout)
%23 = load i32, i32* @SIGTERM
%24 = tail call i32 @signal(i32 %23, i32 (...)* @sigout)
ret i32 undef
}