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

/* Variables and functions */
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
void UnHandle(int sig) {
  struct sigaction sa = {};
  sa.sa_handler = SIG_DFL;
  sigemptyset(&sa.sa_mask);
  if (sigaction(sig, &sa, NULL) != 0) {
    perror("sigaction(sig, &sa, NULL)");
    exit(1);
  };
}


x86 assembly (clang, -O0):
<UnHandle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <sigemptyset@plt>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
je     11b0 <UnHandle+0x60>
lea    0xe5f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UnHandle>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
movq   $0x0,(%rsp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <sigemptyset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
jne    117f <UnHandle+0x3f>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe7a(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sigaction = type { i32, i32 }
@SIG_DFL = global i32 0
@.str = [26 x i8] c"sigaction(sig, &sa, NULL)\00"
define void @UnHandle(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sigaction
store i32 %0, i32* %2
%4 = bitcast %struct.sigaction* %3 to i8*
%5 = load i32, i32* @SIG_DFL
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 1
store i32 %5, i32* %6
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 0
%8 = call i32 @sigemptyset(i32* %7)
%9 = load i32, i32* %2
%10 = call i64 @sigaction(i32 %9, %struct.sigaction* %3, i32* null)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { i32, i32 }
@SIG_DFL = global i32 0
@.str = [26 x i8] c"sigaction(sig, &sa, NULL)\00"
define void @UnHandle(i32 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to %struct.sigaction*
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = load i32, i32* @SIG_DFL
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
store i32 %5, i32* %6
%7 = bitcast i64* %2 to i32*
%8 = call i32 @sigemptyset(i32* %7)
%9 = call i64 @sigaction(i32 %0, %struct.sigaction* %3, i32* null)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
ret void
}