#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__ ESRCH;
scalar_t__ errno;
scalar_t__ kill(int, int /*<<< orphan*/);
int pidfile_read(char const *);
int pidfile_check(const char *pidfile) {
  int pid = pidfile_read(pidfile);
  if (!pid) {
    return 0;
  }
  if (kill(pid, 0) && ESRCH == errno) {
    return (0);
  }
  return pid;
}


x86 assembly (clang, -O0):
<pidfile_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <pidfile_read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    114e <pidfile_check+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    118e <pidfile_check+0x6e>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1040 <kill@plt>
cmp    $0x0,%rax
je     1188 <pidfile_check+0x68>
mov    0x2e67(%rip),%rax
mov    (%rax),%rax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%rax
jne    1188 <pidfile_check+0x68>
movl   $0x0,-0x4(%rbp)
jmp    118e <pidfile_check+0x6e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pidfile_check>:
push   %rbp
push   %rbx
push   %rax
call   1030 <pidfile_read@plt>
test   %eax,%eax
je     1158 <pidfile_check+0x38>
mov    %eax,%ebx
xor    %ebp,%ebp
mov    %eax,%edi
xor    %esi,%esi
call   1040 <kill@plt>
test   %rax,%rax
je     1154 <pidfile_check+0x34>
mov    0x2e8b(%rip),%rax
mov    (%rax),%rax
mov    0x2e91(%rip),%rcx
cmp    (%rcx),%rax
je     115a <pidfile_check+0x3a>
mov    %ebx,%ebp
jmp    115a <pidfile_check+0x3a>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@ESRCH = global i64 0
@errno = global i64 0
define i32 @pidfile_check(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @pidfile_read(i8* %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %1
store i32 0, i32* %2
br label %21
10: ; preds = %1
%11 = load i32, i32* %4
%12 = call i64 @kill(i32 %11, i32 0)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i64, i64* @ESRCH
%16 = load i64, i64* @errno
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 0, i32* %2
br label %21
19: ; preds = %14, %10
%20 = load i32, i32* %4
store i32 %20, i32* %2
br label %21
21: ; preds = %19, %18, %9
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@ESRCH = global i64 0
@errno = global i64 0
define i32 @pidfile_check(i8* %0) {
%2 = tail call i32 @pidfile_read(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i64 @kill(i32 %2, i32 0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = load i64, i64* @ESRCH
%9 = load i64, i64* @errno
%10 = icmp eq i64 %8, %9
br i1 %10, label %12, label %11
11: ; preds = %7, %4
br label %12
12: ; preds = %7, %1, %11
%13 = phi i32 [ %2, %11 ], [ 0, %1 ], [ 0, %7 ]
ret i32 %13
}