#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 */
scalar_t__ SIG_IGN;
int /*<<< orphan*/ sigaction(int, struct sigaction *, struct sigaction *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ verbose(int, char *, int);
void redefineSignalHandler(int sigid, void (*my_func)(int signum)) {
  struct sigaction handler, old_handler;
  handler.sa_handler = my_func;
  sigemptyset(&handler.sa_mask);
  handler.sa_flags = 0;
  sigaction(sigid, NULL, &old_handler);
  if (old_handler.sa_handler != SIG_IGN)
    sigaction(sigid, &handler, NULL);
  else
    verbose(1,
            "[redefineSignalHandler]:: signal %d is already ignored.. "
            "redefinition ignored ",
            sigid);
}


x86 assembly (clang, -O0):
<redefineSignalHandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%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    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x40(%rbp),%rdx
call   1030 <sigaction@plt>
mov    -0x40(%rbp),%rax
mov    0x2e71(%rip),%rcx
mov    (%rcx),%rcx
cmp    %rcx,%rax
je     1198 <redefineSignalHandler+0x68>
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
jmp    11ac <redefineSignalHandler+0x7c>
mov    -0x4(%rbp),%edx
mov    $0x1,%edi
lea    0xe59(%rip),%rsi
call   1050 <verbose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<redefineSignalHandler>:
push   %rbx
sub    $0x30,%rsp
mov    %edi,%ebx
mov    %rsi,(%rsp)
lea    0x10(%rsp),%rdi
call   1040 <sigemptyset@plt>
movq   $0x0,0x8(%rsp)
lea    0x18(%rsp),%rdx
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <sigaction@plt>
mov    0x18(%rsp),%rax
mov    0x2e80(%rip),%rcx
cmp    (%rcx),%rax
je     117b <redefineSignalHandler+0x4b>
mov    %rsp,%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <sigaction@plt>
jmp    118e <redefineSignalHandler+0x5e>
lea    0xe7e(%rip),%rsi
mov    $0x1,%edi
mov    %ebx,%edx
call   1050 <verbose@plt>
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sigaction = type { void (i32)*, i64, i32 }
@SIG_IGN = global i64 0
@.str = [79 x i8] c"[redefineSignalHandler]:: signal %d is already ignored.. redefinition ignored \00"
define void @redefineSignalHandler(i32 %0, void (i32)* %1) {
%3 = alloca i32
%4 = alloca void (i32)*
%5 = alloca %struct.sigaction
%6 = alloca %struct.sigaction
store i32 %0, i32* %3
store void (i32)* %1, void (i32)** %4
%7 = load void (i32)*, void (i32)** %4
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 0
store void (i32)* %7, void (i32)** %8
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 2
%10 = call i32 @sigemptyset(i32* %9)
%11 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 1
store i64 0, i64* %11
%12 = load i32, i32* %3
%13 = call i32 @sigaction(i32 %12, %struct.sigaction* null, %struct.sigaction* %6)
%14 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 0
%15 = load void (i32)*, void (i32)** %14
%16 = load i64, i64* @SIG_IGN
%17 = inttoptr i64 %16 to void (i32)*
%18 = icmp ne void (i32)* %15, %17
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i32, i32* %3
%21 = call i32 @sigaction(i32 %20, %struct.sigaction* %5, %struct.sigaction* null)
br label %25
22: ; preds = %2
%23 = load i32, i32* %3
%24 = call i32 @verbose(i32 1, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %19
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { void (i32)*, i64, i32 }
@SIG_IGN = global i64 0
@.str = [79 x i8] c"[redefineSignalHandler]:: signal %d is already ignored.. redefinition ignored \00"
define void @redefineSignalHandler(i32 %0, void (i32)* %1) {
%3 = alloca %struct.sigaction
%4 = alloca %struct.sigaction
%5 = bitcast %struct.sigaction* %3 to i8*
%6 = bitcast %struct.sigaction* %4 to i8*
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
store void (i32)* %1, void (i32)** %7
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 2
%9 = call i32 @sigemptyset(i32* %8)
%10 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
store i64 0, i64* %10
%11 = call i32 @sigaction(i32 %0, %struct.sigaction* null, %struct.sigaction* %4)
%12 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i64 0, i32 0
%13 = load void (i32)*, void (i32)** %12
%14 = load i64, i64* @SIG_IGN
%15 = inttoptr i64 %14 to void (i32)*
%16 = icmp eq void (i32)* %13, %15
br i1 %16, label %19, label %17
17: ; preds = %2
%18 = call i32 @sigaction(i32 %0, %struct.sigaction* %3, %struct.sigaction* null)
br label %21
19: ; preds = %2
%20 = call i32 @verbose(i32 1, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %21
21: ; preds = %19, %17
ret void
}