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

/* Variables and functions */
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ memset(struct sigaction *, int /*<<< orphan*/, int);
scalar_t__ sigaction(int, struct sigaction *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
void clearhandler(int sig) {
  struct sigaction sa;
  memset(&sa, 0, sizeof(sa));
  sa.sa_handler = SIG_DFL;
  sigemptyset(&sa.sa_mask);
  if (sigaction(sig, &sa, 0))
    err(1, "sigaction");
}


x86 assembly (clang, -O0):
<clearhandler>:
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    0x2e7e(%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    %edx,%edx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
je     1199 <clearhandler+0x59>
mov    $0x1,%edi
lea    0xe6c(%rip),%rsi
call   1060 <err@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clearhandler>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %rbx,%rdi
call   1050 <sigemptyset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
je     118e <clearhandler+0x4e>
lea    0xe7c(%rip),%rsi
mov    $0x1,%edi
call   1060 <err@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sigaction = type { i32, i32 }
@SIG_DFL = global i32 0
@.str = [10 x i8] c"sigaction\00"
define void @clearhandler(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sigaction
store i32 %0, i32* %2
%4 = call i32 @memset(%struct.sigaction* %3, i32 0, i32 8)
%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 0)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { i32, i32 }
@SIG_DFL = global i32 0
@.str = [10 x i8] c"sigaction\00"
define void @clearhandler(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 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i64 0, i32 0
%8 = call i32 @sigemptyset(i32* %7)
%9 = call i64 @sigaction(i32 %0, %struct.sigaction* %2, i32 0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
ret void
}