#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 */
scalar_t__ EPERM;
scalar_t__ ESRCH;
scalar_t__ errno;
int /*<<< orphan*/ fatal(char *, int /*<<< orphan*/);
scalar_t__ kill(int /*<<< orphan*/, int /*<<< orphan*/);
bool pid_is_running(pid_t pid) {
  if (kill(pid, 0) == 0 || errno == EPERM)
    return true;
  else if (errno == ESRCH)
    return false;
  else
    fatal("error checking pid %u status", pid);
}


x86 assembly (clang, -O0):
<pid_is_running>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1030 <kill@plt>
cmp    $0x0,%rax
je     1159 <pid_is_running+0x39>
mov    0x2e9a(%rip),%rax
mov    (%rax),%rax
mov    0x2e80(%rip),%rcx
cmp    (%rcx),%rax
jne    1165 <pid_is_running+0x45>
movl   $0x1,-0x4(%rbp)
jmp    119f <pid_is_running+0x7f>
mov    0x2e74(%rip),%rax
mov    (%rax),%rax
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%rax
jne    118b <pid_is_running+0x6b>
movl   $0x0,-0x4(%rbp)
jmp    119f <pid_is_running+0x7f>
mov    -0x8(%rbp),%esi
lea    0xe6b(%rip),%rdi
call   1040 <fatal@plt>
jmp    119f <pid_is_running+0x7f>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pid_is_running>:
push   %rbx
mov    %edi,%ebx
xor    %esi,%esi
call   1030 <kill@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
je     1169 <pid_is_running+0x49>
mov    0x2ea2(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e88(%rip),%rdx
cmp    (%rdx),%rcx
je     1169 <pid_is_running+0x49>
mov    0x2e74(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
je     1169 <pid_is_running+0x49>
lea    0xe9e(%rip),%rdi
mov    %ebx,%esi
call   1040 <fatal@plt>
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i64 0
@EPERM = global i64 0
@ESRCH = global i64 0
@.str = [29 x i8] c"error checking pid %u status\00"
define i32 @pid_is_running(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = call i64 @kill(i32 %4, i32 0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i64, i64* @errno
%9 = load i64, i64* @EPERM
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %12
11: ; preds = %7, %1
store i32 1, i32* %2
br label %21
12: ; preds = %7
%13 = load i64, i64* @errno
%14 = load i64, i64* @ESRCH
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 0, i32* %2
br label %21
17: ; preds = %12
%18 = load i32, i32* %3
%19 = call i32 @fatal(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %17
br label %21
21: ; preds = %11, %16, %20
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@errno = global i64 0
@EPERM = global i64 0
@ESRCH = global i64 0
@.str = [29 x i8] c"error checking pid %u status\00"
define i32 @pid_is_running(i32 %0) {
%2 = tail call i64 @kill(i32 %0, i32 0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = load i64, i64* @errno
%6 = load i64, i64* @EPERM
%7 = icmp eq i64 %5, %6
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = load i64, i64* @ESRCH
%10 = icmp eq i64 %5, %9
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @fatal(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %13
13: ; preds = %8, %1, %4, %11
%14 = phi i32 [ undef, %11 ], [ 1, %4 ], [ 1, %1 ], [ 0, %8 ]
ret i32 %14
}