#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 *pid_file) {
  int pid = read_pid(pid_file);
  if ((!pid) || (pid == getpid()))
    return 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    11b8 <check_pid+0x88>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <kill@plt>
cmp    $0x0,%rax
je     11b2 <check_pid+0x82>
mov    0x2e4d(%rip),%rax
mov    (%rax),%rax
mov    0x2e33(%rip),%rcx
cmp    (%rcx),%rax
jne    11b2 <check_pid+0x82>
movl   $0x0,-0x4(%rbp)
jmp    11b8 <check_pid+0x88>
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   %rbx
push   %rax
call   1040 <read_pid@plt>
test   %eax,%eax
je     1175 <check_pid+0x45>
mov    %eax,%ebx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
cmp    %eax,%ebx
je     1177 <check_pid+0x47>
xor    %ebp,%ebp
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <kill@plt>
test   %rax,%rax
je     1171 <check_pid+0x41>
mov    0x2e7e(%rip),%rax
mov    (%rax),%rax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
je     1177 <check_pid+0x47>
mov    %ebx,%ebp
jmp    1177 <check_pid+0x47>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
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
%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
%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
}