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

/* Variables and functions */
int /*<<< orphan*/ SA_SIGINFO;
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ forensics_report_crash(char *);
int /*<<< orphan*/ memset(struct sigaction *, int /*<<< orphan*/, int);
int sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
void unregister_handler(int sig) {
  struct sigaction action;
  memset(&action, 0, sizeof(action));
  action.sa_handler = SIG_DFL;
  action.sa_flags = SA_SIGINFO;
  int result = sigaction(sig, &action, NULL);
  if (result != 0) {
    forensics_report_crash("failed to unregister signal handlers");
  }
}


x86 assembly (clang, -O0):
<unregister_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     118c <unregister_handler+0x5c>
lea    0xe79(%rip),%rdi
call   1040 <forensics_report_crash@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unregister_handler>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %eax,%eax
je     117d <unregister_handler+0x4d>
lea    0xe88(%rip),%rdi
call   1040 <forensics_report_crash@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sigaction = type { i32, i32 }
@SIG_DFL = global i32 0
@SA_SIGINFO = global i32 0
@.str = [37 x i8] c"failed to unregister signal handlers\00"
define void @unregister_handler(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sigaction
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 @memset(%struct.sigaction* %3, i32 0, i32 8)
%6 = load i32, i32* @SIG_DFL
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 1
store i32 %6, i32* %7
%8 = load i32, i32* @SA_SIGINFO
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 0
store i32 %8, i32* %9
%10 = load i32, i32* %2
%11 = call i32 @sigaction(i32 %10, %struct.sigaction* %3, i32* null)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @forensics_report_crash(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { i32, i32 }
@SIG_DFL = global i32 0
@SA_SIGINFO = global i32 0
@.str = [37 x i8] c"failed to unregister signal handlers\00"
define void @unregister_handler(i32 %0) {
%2 = alloca %struct.sigaction
%3 = bitcast %struct.sigaction* %2 to i8*
%4 = call i32 @memset(%struct.sigaction* %2, i32 0, i32 8)
%5 = load i32, i32* @SIG_DFL
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i64 0, i32 1
store i32 %5, i32* %6
%7 = load i32, i32* @SA_SIGINFO
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i64 0, i32 0
store i32 %7, i32* %8
%9 = call i32 @sigaction(i32 %0, %struct.sigaction* %2, i32* null)
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = call i32 @forensics_report_crash(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
ret void
}