#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 /*<<< orphan*/ sigaction(int, struct sigaction const *, struct sigaction *);
void installSignalHandler(int signo, const struct sigaction *act, int force) {
  struct sigaction sa;
  sigaction(signo, NULL, &sa);
  if (force || sa.sa_handler == SIG_DFL) {
    sigaction(signo, act, NULL);
  }
}


x86 assembly (clang, -O0):
<installSignalHandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x20(%rbp),%rdx
call   1030 <sigaction@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1150 <installSignalHandler+0x40>
mov    -0x20(%rbp),%rax
mov    0x2e99(%rip),%rcx
cmp    (%rcx),%rax
jne    1160 <installSignalHandler+0x50>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<installSignalHandler>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0x8(%rsp),%rdx
xor    %esi,%esi
call   1030 <sigaction@plt>
test   %ebx,%ebx
jne    1140 <installSignalHandler+0x30>
mov    0x8(%rsp),%rax
mov    0x2ea5(%rip),%rcx
cmp    (%rcx),%rax
jne    114c <installSignalHandler+0x3c>
mov    %ebp,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.sigaction = type { i64 }
@SIG_DFL = global i64 0
define void @installSignalHandler(i32 %0, %struct.sigaction* %1, i32 %2) {
%4 = alloca %struct.sigaction
%5 = bitcast %struct.sigaction* %4 to i8*
%6 = call i32 @sigaction(i32 %0, %struct.sigaction* null, %struct.sigaction* %4)
%7 = icmp eq i32 %2, 0
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i64 0, i32 0
%10 = load i64, i64* %9
%11 = load i64, i64* @SIG_DFL
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %8, %3
%14 = call i32 @sigaction(i32 %0, %struct.sigaction* %1, %struct.sigaction* null)
br label %15
15: ; preds = %13, %8
ret void
}