#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 */

/* Variables and functions */
scalar_t__ ENOSYS;
int O_CLOEXEC;
int O_DIRECTORY;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ ksft_exit_fail_msg(char *, char const *);
int /*<<< orphan*/ ksft_exit_skip(char *, char const *);
int /*<<< orphan*/ ksft_test_result_pass(char *, char const *);
int open(char *, int);
int sys_pidfd_send_signal(int, int /*<<< orphan*/, int /*<<< orphan*/ *,
                          int /*<<< orphan*/);
int test_pidfd_send_signal_syscall_support(void) {
  int pidfd, ret;
  const char *test_name = "pidfd_send_signal check for support";
  pidfd = open("/proc/self", O_DIRECTORY | O_CLOEXEC);
  if (pidfd < 0)
    ksft_exit_fail_msg("%s test: Failed to open process file descriptor\n",
                       test_name);
  ret = sys_pidfd_send_signal(pidfd, 0, NULL, 0);
  if (ret < 0) {
    if (errno == ENOSYS)
      ksft_exit_skip("%s test: pidfd_send_signal() syscall not supported "
                     "(Ensure that CONFIG_PROC_FS=y is set)\n",
                     test_name);
    ksft_exit_fail_msg("%s test: Failed to send signal\n", test_name);
  }
  close(pidfd);
  ksft_test_result_pass("%s test: pidfd_send_signal() syscall is supported. "
                        "Tests can be executed\n",
                        test_name);
  return 0;
}


x86 assembly (clang, -O0):
<test_pidfd_send_signal_syscall_support>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    0x2e3d(%rip),%rax
or     (%rax),%esi
lea    0xe98(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11ae <test_pidfd_send_signal_syscall_support+0x4e>
mov    -0x10(%rbp),%rsi
lea    0xe86(%rip),%rdi
call   1040 <ksft_exit_fail_msg@plt>
mov    -0x4(%rbp),%edi
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%edx
mov    %ecx,%esi
call   1070 <sys_pidfd_send_signal@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1205 <test_pidfd_send_signal_syscall_support+0xa5>
mov    0x2dfe(%rip),%rax
mov    (%rax),%rax
mov    0x2e0c(%rip),%rcx
cmp    (%rcx),%rax
jne    11f5 <test_pidfd_send_signal_syscall_support+0x95>
mov    -0x10(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1050 <ksft_exit_skip@plt>
mov    -0x10(%rbp),%rsi
lea    0xeba(%rip),%rdi
call   1040 <ksft_exit_fail_msg@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%rsi
lea    0xec2(%rip),%rdi
call   1030 <ksft_test_result_pass@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_pidfd_send_signal_syscall_support>:
push   %rbx
mov    0x2e70(%rip),%rax
mov    0x2e51(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xeaa(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1198 <test_pidfd_send_signal_syscall_support+0x38>
lea    0xea3(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1040 <ksft_exit_fail_msg@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1070 <sys_pidfd_send_signal@plt>
test   %eax,%eax
jns    11e5 <test_pidfd_send_signal_syscall_support+0x85>
mov    0x2e20(%rip),%rax
mov    (%rax),%rax
mov    0x2e2e(%rip),%rcx
cmp    (%rcx),%rax
jne    11d2 <test_pidfd_send_signal_syscall_support+0x72>
lea    0xe9a(%rip),%rdi
lea    0xe33(%rip),%rsi
call   1050 <ksft_exit_skip@plt>
lea    0xee1(%rip),%rdi
lea    0xe20(%rip),%rsi
call   1040 <ksft_exit_fail_msg@plt>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xee7(%rip),%rdi
lea    0xe06(%rip),%rsi
call   1030 <ksft_test_result_pass@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"pidfd_send_signal check for support\00"
@.str.1 = [11 x i8] c"/proc/self\00"
@O_DIRECTORY = global i32 0
@O_CLOEXEC = global i32 0
@.str.2 = [49 x i8] c"%s test: Failed to open process file descriptor\0A\00"
@errno = global i64 0
@ENOSYS = global i64 0
@.str.3 = [90 x i8] c"%s test: pidfd_send_signal() syscall not supported (Ensure that CONFIG_PROC_FS=y is set)\0A\00"
@.str.4 = [32 x i8] c"%s test: Failed to send signal\0A\00"
@.str.5 = [74 x i8] c"%s test: pidfd_send_signal() syscall is supported. Tests can be executed\0A\00"
define i32 @test_pidfd_send_signal_syscall_support() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8** %3
%4 = load i32, i32* @O_DIRECTORY
%5 = load i32, i32* @O_CLOEXEC
%6 = or i32 %4, %5
%7 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %6)
store i32 %7, i32* %1
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i8*, i8** %3
%12 = call i32 @ksft_exit_fail_msg(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %10, %0
%14 = load i32, i32* %1
%15 = call i32 @sys_pidfd_send_signal(i32 %14, i32 0, i32* null, i32 0)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %13
%19 = load i64, i64* @errno
%20 = load i64, i64* @ENOSYS
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i8*, i8** %3
%24 = call i32 @ksft_exit_skip(i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.3, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22, %18
%26 = load i8*, i8** %3
%27 = call i32 @ksft_exit_fail_msg(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %25, %13
%29 = load i32, i32* %1
%30 = call i32 @close(i32 %29)
%31 = load i8*, i8** %3
%32 = call i32 @ksft_test_result_pass(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.5, i64 0, i64 0), i8* %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [36 x i8] c"pidfd_send_signal check for support\00"
@.str.1 = [11 x i8] c"/proc/self\00"
@O_DIRECTORY = global i32 0
@O_CLOEXEC = global i32 0
@.str.2 = [49 x i8] c"%s test: Failed to open process file descriptor\0A\00"
@errno = global i64 0
@ENOSYS = global i64 0
@.str.3 = [90 x i8] c"%s test: pidfd_send_signal() syscall not supported (Ensure that CONFIG_PROC_FS=y is set)\0A\00"
@.str.4 = [32 x i8] c"%s test: Failed to send signal\0A\00"
@.str.5 = [74 x i8] c"%s test: pidfd_send_signal() syscall is supported. Tests can be executed\0A\00"
define i32 @test_pidfd_send_signal_syscall_support() {
%1 = load i32, i32* @O_DIRECTORY
%2 = load i32, i32* @O_CLOEXEC
%3 = or i32 %2, %1
%4 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @ksft_exit_fail_msg(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = tail call i32 @sys_pidfd_send_signal(i32 %4, i32 0, i32* null, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i64, i64* @errno
%13 = load i64, i64* @ENOSYS
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 @ksft_exit_skip(i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
%18 = tail call i32 @ksft_exit_fail_msg(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %8
%20 = tail call i32 @close(i32 %4)
%21 = tail call i32 @ksft_test_result_pass(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
ret i32 0
}