#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 int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EPERM;
int /*<<< orphan*/ debug(char *, ...);
int /*<<< orphan*/ errno;
scalar_t__ getenv(char *);
scalar_t__ siginlist(int, char *);
int sys_kill(int /*<<< orphan*/, int);
int kill(pid_t pid, int sig) {
  debug("Sending %d to pid %d\n", sig, pid);
  if (siginlist(sig, "SUDO_SIGLIST") || getenv("SYS_SIGNAL")) {
    return sys_kill(pid, sig);
  }
  debug("kill: ");
  errno = EPERM;
  return -1;
}


x86 assembly (clang, -O0):
<kill>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1040 <debug@plt>
mov    -0xc(%rbp),%edi
lea    0xeaa(%rip),%rsi
call   1060 <siginlist@plt>
cmp    $0x0,%rax
jne    1191 <kill+0x51>
lea    0xea1(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     11a4 <kill+0x64>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <sys_kill@plt>
mov    %eax,-0x4(%rbp)
jmp    11cb <kill+0x8b>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <debug@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%ecx
mov    0x2e1e(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kill>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xeb2(%rip),%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <debug@plt>
lea    0xeb8(%rip),%rsi
mov    %ebx,%edi
call   1060 <siginlist@plt>
test   %rax,%rax
jne    117b <kill+0x3b>
lea    0xeb2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     118a <kill+0x4a>
mov    %ebp,%edi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <sys_kill@plt>
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1040 <debug@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    0x2e38(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Sending %d to pid %d\0A\00"
@.str.1 = [13 x i8] c"SUDO_SIGLIST\00"
@.str.2 = [11 x i8] c"SYS_SIGNAL\00"
@.str.3 = [7 x i8] c"kill: \00"
@EPERM = global i32 0
@errno = global i32 0
define i32 @kill(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = load i32, i32* %4
%8 = call i32 (i8*, ...) @debug(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7)
%9 = load i32, i32* %5
%10 = call i64 @siginlist(i32 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp ne i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = call i64 @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12, %2
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = call i32 @sys_kill(i32 %16, i32 %17)
store i32 %18, i32* %3
br label %22
19: ; preds = %12
%20 = call i32 (i8*, ...) @debug(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* @EPERM
store i32 %21, i32* @errno
store i32 -1, i32* %3
br label %22
22: ; preds = %19, %15
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [22 x i8] c"Sending %d to pid %d\0A\00"
@.str.1 = [13 x i8] c"SUDO_SIGLIST\00"
@.str.2 = [11 x i8] c"SYS_SIGNAL\00"
@.str.3 = [7 x i8] c"kill: \00"
@EPERM = global i32 0
@errno = global i32 0
define i32 @kill(i32 %0, i32 %1) {
%3 = tail call i32 (i8*, ...) @debug(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %0)
%4 = tail call i64 @siginlist(i32 %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i64 @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6, %2
%10 = tail call i32 @sys_kill(i32 %0, i32 %1)
br label %14
11: ; preds = %6
%12 = tail call i32 (i8*, ...) @debug(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%13 = load i32, i32* @EPERM
store i32 %13, i32* @errno
br label %14
14: ; preds = %11, %9
%15 = phi i32 [ %10, %9 ], [ -1, %11 ]
ret i32 %15
}