#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 {
  void (*sa_handler)(int);
  scalar_t__ sa_flags;
  int /*<<< orphan*/ sa_mask;
};

/* Variables and functions */
int sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int sig_handle(int sig, void (*hndlr)(int)) {
  struct sigaction act;
  act.sa_handler = hndlr;
  sigemptyset(&act.sa_mask);
  act.sa_flags = 0;
  if (sigaction(sig, &act, NULL) == -1) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<sig_handle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
add    $0x10,%rdi
call   1040 <sigemptyset@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0xffffffff,%eax
jne    1171 <sig_handle+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    1178 <sig_handle+0x58>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sig_handle>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
mov    %rsi,0x8(%rsp)
lea    0x18(%rsp),%rdi
call   1040 <sigemptyset@plt>
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <sigaction@plt>
xor    %ecx,%ecx
cmp    $0xffffffff,%eax
sete   %cl
neg    %ecx
mov    %ecx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sigaction = type { void (i32)*, i64, i32 }
define i32 @sig_handle(i32 %0, void (i32)* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca void (i32)*
%6 = alloca %struct.sigaction
store i32 %0, i32* %4
store void (i32)* %1, void (i32)** %5
%7 = load void (i32)*, void (i32)** %5
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 0
store void (i32)* %7, void (i32)** %8
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 2
%10 = call i32 @sigemptyset(i32* %9)
%11 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 1
store i64 0, i64* %11
%12 = load i32, i32* %4
%13 = call i32 @sigaction(i32 %12, %struct.sigaction* %6, i32* null)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %17
16: ; preds = %2
store i32 0, i32* %3
br label %17
17: ; preds = %16, %15
%18 = load i32, i32* %3
ret i32 %18
}

LLVM IR (-O2):
%struct.sigaction = type { void (i32)*, i64, i32 }
define i32 @sig_handle(i32 %0, void (i32)* %1) {
%3 = alloca %struct.sigaction
%4 = bitcast %struct.sigaction* %3 to i8*
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
store void (i32)* %1, void (i32)** %5
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 2
%7 = call i32 @sigemptyset(i32* %6)
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
store i64 0, i64* %8
%9 = call i32 @sigaction(i32 %0, %struct.sigaction* %3, i32* null)
%10 = icmp eq i32 %9, -1
%11 = sext i1 %10 to i32
ret i32 %11
}