#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int si_signo;
  scalar_t__ si_pid;
  int /*<<< orphan*/ si_code;
};
typedef TYPE_1__ siginfo_t;
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ info;

/* Variables and functions */
int /*<<< orphan*/ ESRCH;
int /*<<< orphan*/ SI_USER;
int /*<<< orphan*/ errno;
scalar_t__ getpid();
int /*<<< orphan*/ memset(TYPE_1__ *, int /*<<< orphan*/, int);
int sigqueue_info(TYPE_1__ *);
int kill(pid_t pid, int sig) {
  int ret;
  pid_t this;
  this = getpid();
  if ((pid != this) && (pid > 0)) {
    errno = ESRCH;
    ret = -1;
  } else if (sig != 0) {
    siginfo_t info;
    memset(&info, 0, sizeof(info));
    info.si_signo = sig;
    info.si_code = SI_USER;
    info.si_pid = this;
    ret = sigqueue_info(&info);
  } else {
    ret = 0;
  }
  return ret;
}


x86 assembly (clang, -O0):
<kill>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1181 <kill+0x51>
cmpq   $0x0,-0x8(%rbp)
jle    1181 <kill+0x51>
mov    0x2e5e(%rip),%rax
mov    (%rax),%ecx
mov    0x2e65(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x10(%rbp)
jmp    11d2 <kill+0xa2>
cmpl   $0x0,-0xc(%rbp)
je     11c6 <kill+0x96>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <sigqueue_info@plt>
mov    %eax,-0x10(%rbp)
jmp    11cd <kill+0x9d>
movl   $0x0,-0x10(%rbp)
jmp    11d2 <kill+0xa2>
mov    -0x10(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kill>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,%r15
test   %rbx,%rbx
jle    116f <kill+0x3f>
cmp    %rbx,%r15
je     116f <kill+0x3f>
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    0x2e72(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebp
jmp    11a6 <kill+0x76>
test   %r14d,%r14d
je     11a6 <kill+0x76>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    %r14d,(%rsp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %r15,0x8(%rsp)
mov    %rbx,%rdi
call   1050 <sigqueue_info@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i64, i32 }
@ESRCH = global i32 0
@errno = global i32 0
@SI_USER = global i32 0
define i32 @kill(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca %struct.TYPE_4__
store i64 %0, i64* %3
store i32 %1, i32* %4
%8 = call i64 (...) @getpid()
store i64 %8, i64* %6
%9 = load i64, i64* %3
%10 = load i64, i64* %6
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i64, i64* %3
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = load i32, i32* @ESRCH
store i32 %16, i32* @errno
store i32 -1, i32* %5
br label %31
17: ; preds = %12, %2
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %17
%21 = call i32 @memset(%struct.TYPE_4__* %7, i32 0, i32 24)
%22 = load i32, i32* %4
%23 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 0
store i32 %22, i32* %23
%24 = load i32, i32* @SI_USER
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 2
store i32 %24, i32* %25
%26 = load i64, i64* %6
%27 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 1
store i64 %26, i64* %27
%28 = call i32 @sigqueue_info(%struct.TYPE_4__* %7)
store i32 %28, i32* %5
br label %30
29: ; preds = %17
store i32 0, i32* %5
br label %30
30: ; preds = %29, %20
br label %31
31: ; preds = %30, %15
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i64, i32 }
@ESRCH = global i32 0
@errno = global i32 0
@SI_USER = global i32 0
define i32 @kill(i64 %0, i32 %1) {
%3 = alloca %struct.TYPE_4__
%4 = tail call i64 (...) @getpid()
%5 = icmp ne i64 %4, %0
%6 = icmp sgt i64 %0, 0
%7 = and i1 %6, %5
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = load i32, i32* @ESRCH
store i32 %9, i32* @errno
br label %20
10: ; preds = %2
%11 = icmp eq i32 %1, 0
br i1 %11, label %20, label %12
12: ; preds = %10
%13 = bitcast %struct.TYPE_4__* %3 to i8*
%14 = call i32 @memset(%struct.TYPE_4__* %3, i32 0, i32 24)
%15 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0
store i32 %1, i32* %15
%16 = load i32, i32* @SI_USER
%17 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 2
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 1
store i64 %4, i64* %18
%19 = call i32 @sigqueue_info(%struct.TYPE_4__* %3)
br label %20
20: ; preds = %10, %12, %8
%21 = phi i32 [ -1, %8 ], [ %19, %12 ], [ 0, %10 ]
ret i32 %21
}