#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;
};

/* Variables and functions */
int /*<<< orphan*/ SIGHUP;
scalar_t__ SIG_DFL;
scalar_t__ SIG_IGN;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sigaction(int /*<<< orphan*/, struct sigaction *,
                     struct sigaction *);
int main(int argc, char *argv[]) {
  struct sigaction old_sa, new_sa;
  if (sigaction(SIGHUP, NULL, &old_sa) < 0) {
    printf("cannot get signal action for SIGHUP: %m\n");
    exit(1);
  }
  if (old_sa.sa_handler != SIG_IGN) {
    printf("SIGHUP action should be SIG_IGN, is %p\n",
           (void *)old_sa.sa_handler);
    exit(1);
  }
  new_sa.sa_handler = SIG_DFL;
  if (sigaction(SIGHUP, &new_sa, NULL) < 0) {
    printf("cannot set signal action for SIGHUP: %m\n");
    exit(1);
  }
  if (sigaction(SIGHUP, NULL, &old_sa) < 0) {
    printf("cannot get signal action for SIGHUP: %m\n");
    exit(1);
  }
  if (old_sa.sa_handler != SIG_DFL) {
    printf("SIGHUP action should be SIG_DFL, is %p\n",
           (void *)old_sa.sa_handler);
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x18(%rbp),%rdx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
jge    117e <main+0x4e>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
mov    0x2e57(%rip),%rcx
cmp    (%rcx),%rax
je     11ae <main+0x7e>
mov    -0x18(%rbp),%rsi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
jge    11f4 <main+0xc4>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x18(%rbp),%rdx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
jge    122c <main+0xfc>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
mov    0x2d99(%rip),%rcx
cmp    (%rcx),%rax
je     125c <main+0x12c>
mov    -0x18(%rbp),%rsi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2eb2(%rip),%rbx
mov    (%rbx),%edi
lea    0x8(%rsp),%rdx
xor    %esi,%esi
call   1030 <sigaction@plt>
test   %rax,%rax
js     11ab <main+0x7b>
mov    0x8(%rsp),%rsi
mov    0x2e83(%rip),%rax
cmp    (%rax),%rsi
jne    11b4 <main+0x84>
mov    0x2e67(%rip),%r14
mov    (%r14),%rax
mov    %rax,0x10(%rsp)
mov    (%rbx),%edi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
js     11bd <main+0x8d>
mov    (%rbx),%edi
lea    0x8(%rsp),%rdx
xor    %esi,%esi
call   1030 <sigaction@plt>
test   %rax,%rax
js     11ab <main+0x7b>
mov    0x8(%rsp),%rsi
cmp    (%r14),%rsi
jne    11d5 <main+0xa5>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe4e(%rip),%rdi
jmp    11c4 <main+0x94>
lea    0xe6e(%rip),%rdi
jmp    11dc <main+0xac>
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.sigaction = type { i64 }
@SIGHUP = global i32 0
@.str = [41 x i8] c"cannot get signal action for SIGHUP: %m\0A\00"
@SIG_IGN = global i64 0
@.str.1 = [40 x i8] c"SIGHUP action should be SIG_IGN, is %p\0A\00"
@SIG_DFL = global i64 0
@.str.2 = [41 x i8] c"cannot set signal action for SIGHUP: %m\0A\00"
@.str.3 = [40 x i8] c"SIGHUP action should be SIG_DFL, is %p\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sigaction
%7 = alloca %struct.sigaction
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @SIGHUP
%9 = call i64 @sigaction(i32 %8, %struct.sigaction* null, %struct.sigaction* %6)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 0
%16 = load i64, i64* %15
%17 = load i64, i64* @SIG_IGN
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 0
%21 = load i64, i64* %20
%22 = inttoptr i64 %21 to i8*
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %14
%26 = load i64, i64* @SIG_DFL
%27 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %7, i32 0, i32 0
store i64 %26, i64* %27
%28 = load i32, i32* @SIGHUP
%29 = call i64 @sigaction(i32 %28, %struct.sigaction* %7, %struct.sigaction* null)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %25
%35 = load i32, i32* @SIGHUP
%36 = call i64 @sigaction(i32 %35, %struct.sigaction* null, %struct.sigaction* %6)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %34
%42 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 0
%43 = load i64, i64* %42
%44 = load i64, i64* @SIG_DFL
%45 = icmp ne i64 %43, %44
br i1 %45, label %46, label %52
46: ; preds = %41
%47 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 0
%48 = load i64, i64* %47
%49 = inttoptr i64 %48 to i8*
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %49)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %41
ret i32 0
}

LLVM IR (-O2):
%struct.sigaction = type { i64 }
@SIGHUP = global i32 0
@.str = [41 x i8] c"cannot get signal action for SIGHUP: %m\0A\00"
@SIG_IGN = global i64 0
@.str.1 = [40 x i8] c"SIGHUP action should be SIG_IGN, is %p\0A\00"
@SIG_DFL = global i64 0
@.str.2 = [41 x i8] c"cannot set signal action for SIGHUP: %m\0A\00"
@.str.3 = [40 x i8] c"SIGHUP action should be SIG_DFL, is %p\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sigaction
%4 = alloca %struct.sigaction
%5 = bitcast %struct.sigaction* %3 to i8*
%6 = bitcast %struct.sigaction* %4 to i8*
%7 = load i32, i32* @SIGHUP
%8 = call i64 @sigaction(i32 %7, %struct.sigaction* null, %struct.sigaction* %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
%15 = load i64, i64* %14
%16 = load i64, i64* @SIG_IGN
%17 = icmp eq i64 %15, %16
br i1 %17, label %22, label %18
18: ; preds = %13
%19 = inttoptr i64 %15 to i8*
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = load i64, i64* @SIG_DFL
%24 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i64 0, i32 0
store i64 %23, i64* %24
%25 = load i32, i32* @SIGHUP
%26 = call i64 @sigaction(i32 %25, %struct.sigaction* %4, %struct.sigaction* null)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %22
%32 = load i32, i32* @SIGHUP
%33 = call i64 @sigaction(i32 %32, %struct.sigaction* null, %struct.sigaction* %3)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31
%39 = load i64, i64* %14
%40 = load i64, i64* @SIG_DFL
%41 = icmp eq i64 %39, %40
br i1 %41, label %46, label %42
42: ; preds = %38
%43 = inttoptr i64 %39 to i8*
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %43)
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %38
ret i32 0
}