#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 {
  scalar_t__ sa_handler;
};
typedef int /*<<< orphan*/ hostname;

/* Variables and functions */
int SIGRTMAX;
scalar_t__ SIG_DFL;
scalar_t__ SIG_IGN;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ gethostname(char *, int);
int /*<<< orphan*/ sigaction(int, int /*<<< orphan*/ *, struct sigaction *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int main(int ac, char **av) {
  char hostname[1024];
  int i, rc = 0;
  struct sigaction act;
  if (gethostname(hostname, sizeof(hostname)) < 0) {
    fprintf(stderr, "Failed to get hostname on this node\n");
    strcpy(hostname, "Unknown");
  }
  for (i = 1; i < SIGRTMAX; i++) {
    sigaction(i, NULL, &act);
    if (act.sa_handler == SIG_IGN) {
      fprintf(stderr, "%s: Signal %d is ignored!\n", hostname, i);
      rc = 1;
    } else if (act.sa_handler != SIG_DFL) {
      fprintf(stderr, "%s: Signal %d has handler function!\n", hostname, i);
      rc = 1;
    }
  }
  return (rc);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   1060 <gethostname@plt>
cmp    $0x0,%rax
jge    11a8 <main+0x68>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    -0x410(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x414(%rbp)
mov    -0x414(%rbp),%eax
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%eax
jge    128a <main+0x14a>
mov    -0x414(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x420(%rbp),%rdx
call   1040 <sigaction@plt>
mov    -0x420(%rbp),%rax
mov    0x2dfd(%rip),%rcx
cmp    (%rcx),%rax
jne    1227 <main+0xe7>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
mov    -0x414(%rbp),%ecx
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x418(%rbp)
jmp    1271 <main+0x131>
mov    -0x420(%rbp),%rax
mov    0x2d93(%rip),%rcx
cmp    (%rcx),%rax
je     126c <main+0x12c>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
mov    -0x414(%rbp),%ecx
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x418(%rbp)
jmp    1271 <main+0x131>
jmp    1276 <main+0x136>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    11b2 <main+0x72>
mov    -0x418(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
call   1060 <gethostname@plt>
test   %rax,%rax
jns    118d <main+0x4d>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xea2(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
mov    0x2e44(%rip),%r12
xor    %ebp,%ebp
cmpl   $0x2,(%r12)
jl     1214 <main+0xd4>
mov    $0x1,%ebx
lea    0x8(%rsp),%r14
mov    0x2e3a(%rip),%r13
lea    0xe78(%rip),%r15
xor    %ebp,%ebp
jmp    11e5 <main+0xa5>
nopl   0x0(%rax)
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%ebp
add    $0x1,%ebx
cmp    (%r12),%ebx
jge    1214 <main+0xd4>
mov    %ebx,%edi
xor    %esi,%esi
mov    %r14,%rdx
call   1040 <sigaction@plt>
mov    0x8(%rsp),%rax
mov    %r15,%rsi
cmp    0x0(%r13),%rax
je     11c0 <main+0x80>
lea    0xe42(%rip),%rsi
mov    0x2dbb(%rip),%rcx
cmp    (%rcx),%rax
jne    11c0 <main+0x80>
jmp    11dc <main+0x9c>
mov    %ebp,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sigaction = type { i64 }
@stderr = global i32 0
@.str = [37 x i8] c"Failed to get hostname on this node\0A\00"
@.str.1 = [8 x i8] c"Unknown\00"
@SIGRTMAX = global i32 0
@SIG_IGN = global i64 0
@.str.2 = [27 x i8] c"%s: Signal %d is ignored!\0A\00"
@SIG_DFL = global i64 0
@.str.3 = [37 x i8] c"%s: Signal %d has handler function!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sigaction
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = call i64 @gethostname(i8* %10, i32 1024)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %13, %2
store i32 1, i32* %7
br label %19
19: ; preds = %47, %18
%20 = load i32, i32* %7
%21 = load i32, i32* @SIGRTMAX
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %50
23: ; preds = %19
%24 = load i32, i32* %7
%25 = call i32 @sigaction(i32 %24, i32* null, %struct.sigaction* %9)
%26 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %9, i32 0, i32 0
%27 = load i64, i64* %26
%28 = load i64, i64* @SIG_IGN
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %35
30: ; preds = %23
%31 = load i32, i32* @stderr
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%33 = load i32, i32* %7
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %32, i32 %33)
store i32 1, i32* %8
br label %46
35: ; preds = %23
%36 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %9, i32 0, i32 0
%37 = load i64, i64* %36
%38 = load i64, i64* @SIG_DFL
%39 = icmp ne i64 %37, %38
br i1 %39, label %40, label %45
40: ; preds = %35
%41 = load i32, i32* @stderr
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%43 = load i32, i32* %7
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %42, i32 %43)
store i32 1, i32* %8
br label %45
45: ; preds = %40, %35
br label %46
46: ; preds = %45, %30
br label %47
47: ; preds = %46
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %19
50: ; preds = %19
%51 = load i32, i32* %8
ret i32 %51
}

LLVM IR (-O2):
%struct.sigaction = type { i64 }
@stderr = global i32 0
@.str = [37 x i8] c"Failed to get hostname on this node\0A\00"
@.str.1 = [8 x i8] c"Unknown\00"
@SIGRTMAX = global i32 0
@SIG_IGN = global i64 0
@.str.2 = [27 x i8] c"%s: Signal %d is ignored!\0A\00"
@SIG_DFL = global i64 0
@.str.3 = [37 x i8] c"%s: Signal %d has handler function!\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.sigaction
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sigaction* %4 to i8*
%7 = call i64 @gethostname(i8* %5, i32 1024)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %9, %2
%14 = load i32, i32* @SIGRTMAX
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %37
16: ; preds = %13
%17 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i64 0, i32 0
br label %18
18: ; preds = %16, %32
%19 = phi i32 [ 0, %16 ], [ %33, %32 ]
%20 = phi i32 [ 1, %16 ], [ %34, %32 ]
%21 = call i32 @sigaction(i32 %20, i32* null, %struct.sigaction* %4)
%22 = load i64, i64* %17
%23 = load i64, i64* @SIG_IGN
%24 = icmp eq i64 %22, %23
br i1 %24, label %28, label %25
25: ; preds = %18
%26 = load i64, i64* @SIG_DFL
%27 = icmp eq i64 %22, %26
br i1 %27, label %32, label %28
28: ; preds = %25, %18
%29 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), %18 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), %25 ]
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* %29, i8* %5, i32 %20)
br label %32
32: ; preds = %28, %25
%33 = phi i32 [ %19, %25 ], [ 1, %28 ]
%34 = add nuw nsw i32 %20, 1
%35 = load i32, i32* @SIGRTMAX
%36 = icmp slt i32 %34, %35
br i1 %36, label %18, label %37
37: ; preds = %32, %13
%38 = phi i32 [ 0, %13 ], [ %33, %32 ]
ret i32 %38
}