#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 */
typedef scalar_t__ __sighandler_t;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ ENOSYS;
int NSIG;
scalar_t__ SIG_ERR;
int /*<<< orphan*/ __set_errno(int /*<<< orphan*/);
__sighandler_t __sysv_signal(int sig, __sighandler_t handler) {
  if (handler == SIG_ERR || sig < 1 || sig >= NSIG) {
    __set_errno(EINVAL);
    return SIG_ERR;
  }
  __set_errno(ENOSYS);
  return SIG_ERR;
}


x86 assembly (clang, -O0):
<__sysv_signal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2eae(%rip),%rcx
cmp    (%rcx),%rax
je     114f <__sysv_signal+0x3f>
cmpl   $0x1,-0xc(%rbp)
jl     114f <__sysv_signal+0x3f>
mov    -0xc(%rbp),%eax
mov    0x2e81(%rip),%rcx
cmp    (%rcx),%eax
jl     1170 <__sysv_signal+0x60>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
mov    0x2e74(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    118c <__sysv_signal+0x7c>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__sysv_signal>:
push   %r14
push   %rbx
push   %rax
mov    0x2ebd(%rip),%r14
mov    (%r14),%rdx
mov    0x2ea3(%rip),%rbx
mov    0x2ea4(%rip),%rax
mov    %rax,%rcx
cmp    %edi,(%rbx)
jle    113a <__sysv_signal+0x2a>
mov    0x2eae(%rip),%rcx
cmp    %rsi,%rdx
cmove  %rax,%rcx
test   %edi,%edi
cmovle %rax,%rcx
mov    (%rcx),%edi
call   1030 <__set_errno@plt>
mov    (%r14),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@SIG_ERR = global i64 0
@NSIG = global i32 0
@EINVAL = global i32 0
@ENOSYS = global i32 0
define i64 @__sysv_signal(i32 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i64
store i32 %0, i32* %4
store i64 %1, i64* %5
%6 = load i64, i64* %5
%7 = load i64, i64* @SIG_ERR
%8 = icmp eq i64 %6, %7
br i1 %8, label %16, label %9
9: ; preds = %2
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 1
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = load i32, i32* %4
%14 = load i32, i32* @NSIG
%15 = icmp sge i32 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %12, %9, %2
%17 = load i32, i32* @EINVAL
%18 = call i32 @__set_errno(i32 %17)
%19 = load i64, i64* @SIG_ERR
store i64 %19, i64* %3
br label %24
20: ; preds = %12
%21 = load i32, i32* @ENOSYS
%22 = call i32 @__set_errno(i32 %21)
%23 = load i64, i64* @SIG_ERR
store i64 %23, i64* %3
br label %24
24: ; preds = %20, %16
%25 = load i64, i64* %3
ret i64 %25
}

LLVM IR (-O2):
@SIG_ERR = global i64 0
@NSIG = global i32 0
@EINVAL = global i32 0
@ENOSYS = global i32 0
define i64 @__sysv_signal(i32 %0, i64 %1) {
%3 = load i64, i64* @SIG_ERR
%4 = icmp ne i64 %3, %1
%5 = icmp sgt i32 %0, 0
%6 = and i1 %5, %4
%7 = load i32, i32* @NSIG
%8 = icmp sgt i32 %7, %0
%9 = select i1 %6, i1 %8, i1 false
%10 = load i32, i32* @ENOSYS
%11 = load i32, i32* @EINVAL
%12 = select i1 %9, i32 %10, i32 %11
%13 = tail call i32 @__set_errno(i32 %12)
%14 = load i64, i64* @SIG_ERR
ret i64 %14
}