#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 {
  scalar_t__ sa_handler;
};

/* Variables and functions */
scalar_t__ SIG_DFL;
int sigaction(int, struct sigaction const *, struct sigaction *);
int /*<<< orphan*/ strsignal(int);
int /*<<< orphan*/ warnx(char *, int, int /*<<< orphan*/);
int set_sigaction(int sig, const struct sigaction *act) {
  struct sigaction oact;
  int r = sigaction(sig, act, &oact);
  if (r == 0 && oact.sa_handler != SIG_DFL) {
    warnx("overriden non-default signal handler (%d: %s)", sig, strsignal(sig));
  }
  return r;
}


x86 assembly (clang, -O0):
<set_sigaction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <sigaction@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    118f <set_sigaction+0x5f>
mov    -0x18(%rbp),%rax
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%rax
je     118f <set_sigaction+0x5f>
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <strsignal@plt>
mov    -0x20(%rbp),%esi
mov    %eax,%edx
lea    0xe76(%rip),%rdi
call   1040 <warnx@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_sigaction>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %rsp,%rdx
call   1030 <sigaction@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    116a <set_sigaction+0x3a>
mov    (%rsp),%rax
mov    0x2e92(%rip),%rcx
cmp    (%rcx),%rax
je     116a <set_sigaction+0x3a>
mov    %ebx,%edi
call   1050 <strsignal@plt>
lea    0xe9f(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <warnx@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sigaction = type { i64 }
@SIG_DFL = global i64 0
@.str = [46 x i8] c"overriden non-default signal handler (%d: %s)\00"
define i32 @set_sigaction(i32 %0, %struct.sigaction* %1) {
%3 = alloca i32
%4 = alloca %struct.sigaction*
%5 = alloca %struct.sigaction
%6 = alloca i32
store i32 %0, i32* %3
store %struct.sigaction* %1, %struct.sigaction** %4
%7 = load i32, i32* %3
%8 = load %struct.sigaction*, %struct.sigaction** %4
%9 = call i32 @sigaction(i32 %7, %struct.sigaction* %8, %struct.sigaction* %5)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %2
%13 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 0
%14 = load i64, i64* %13
%15 = load i64, i64* @SIG_DFL
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i32, i32* %3
%19 = load i32, i32* %3
%20 = call i32 @strsignal(i32 %19)
%21 = call i32 @warnx(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %20)
br label %22
22: ; preds = %17, %12, %2
%23 = load i32, i32* %6
ret i32 %23
}

LLVM IR (-O2):
%struct.sigaction = type { i64 }
@SIG_DFL = global i64 0
@.str = [46 x i8] c"overriden non-default signal handler (%d: %s)\00"
define i32 @set_sigaction(i32 %0, %struct.sigaction* %1) {
%3 = alloca %struct.sigaction
%4 = bitcast %struct.sigaction* %3 to i8*
%5 = call i32 @sigaction(i32 %0, %struct.sigaction* %1, %struct.sigaction* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %2
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
%9 = load i64, i64* %8
%10 = load i64, i64* @SIG_DFL
%11 = icmp eq i64 %9, %10
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = call i32 @strsignal(i32 %0)
%14 = call i32 @warnx(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %13)
br label %15
15: ; preds = %12, %7, %2
ret i32 %5
}