#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);
  int sa_flags;
  int /*<<< orphan*/ sa_mask;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigfillset(int /*<<< orphan*/ *);
void sighandle(void (*handler)(int), int flags, int sig) {
  struct sigaction act = {.sa_handler = handler, .sa_flags = flags};
  sigfillset(&act.sa_mask);
  if (sigaction(sig, &act, NULL)) {
    do {
      perror("sigaction");
      exit(1);
    } while (0);
  }
}


x86 assembly (clang, -O0):
<sighandle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
add    $0xc,%rdi
call   1040 <sigfillset@plt>
mov    -0x10(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
je     11a9 <sighandle+0x69>
jmp    1193 <sighandle+0x53>
lea    0xe66(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sighandle>:
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebx
mov    %rdi,(%rsp)
mov    %esi,0x8(%rsp)
lea    0xc(%rsp),%rdi
movl   $0x0,0xc(%rsp)
call   1040 <sigfillset@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
jne    1178 <sighandle+0x38>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe81(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sigaction = type { void (i32)*, i32, i32 }
@.str = [10 x i8] c"sigaction\00"
define void @sighandle(void (i32)* %0, i32 %1, i32 %2) {
%4 = alloca void (i32)*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sigaction
store void (i32)* %0, void (i32)** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %7, i32 0, i32 0
%9 = load void (i32)*, void (i32)** %4
store void (i32)* %9, void (i32)** %8
%10 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %7, i32 0, i32 1
%11 = load i32, i32* %5
store i32 %11, i32* %10
%12 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %7, i32 0, i32 2
store i32 0, i32* %12
%13 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %7, i32 0, i32 2
%14 = call i32 @sigfillset(i32* %13)
%15 = load i32, i32* %6
%16 = call i64 @sigaction(i32 %15, %struct.sigaction* %7, i32* null)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %3
br label %19
19: ; preds = %18
%20 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; No predecessors!
br label %23
23: ; preds = %22, %3
ret void
}

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