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


x86 assembly (clang, -O0):
<check_pid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <read_pid@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     116c <check_pid+0x3c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jne    1178 <check_pid+0x48>
movl   $0x0,-0x4(%rbp)
jmp    11c6 <check_pid+0x96>
mov    0x2e61(%rip),%rax
movq   $0x0,(%rax)
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <kill@plt>
cmp    $0x0,%rax
je     11c0 <check_pid+0x90>
mov    0x2e3f(%rip),%rax
mov    (%rax),%rax
mov    0x2e25(%rip),%rcx
cmp    (%rcx),%rax
jne    11c0 <check_pid+0x90>
movl   $0x0,-0x4(%rbp)
jmp    11c6 <check_pid+0x96>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_pid>:
push   %rbp
push   %r14
push   %rbx
call   1040 <read_pid@plt>
test   %eax,%eax
je     117d <check_pid+0x4d>
mov    %eax,%ebx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
cmp    %eax,%ebx
je     117f <check_pid+0x4f>
mov    0x2e8d(%rip),%r14
movq   $0x0,(%r14)
xor    %ebp,%ebp
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <kill@plt>
test   %rax,%rax
je     1179 <check_pid+0x49>
mov    (%r14),%rax
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%rax
je     117f <check_pid+0x4f>
mov    %ebx,%ebp
jmp    117f <check_pid+0x4f>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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