#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void check_pid(const char *pid_file) {
  FILE *file;
  int other;
  file = fopen(pid_file, "r");
  if (file != NULL) {
    if (fscanf(file, "%d", &other) == 1) {
      if (kill(other, 0) == 0) {
        fprintf(stderr, "Another instance is running, please stop it first!\n");
        exit(10);
      } else {
        fprintf(stderr, "Stale lock file, ignoring!\n");
      }
    } else {
      fprintf(stderr, "Can not parse pidfile, ignoring!\n");
    }
    fclose(file);
  }
}


x86 assembly (clang, -O0):
<check_pid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1213 <check_pid+0xb3>
mov    -0x10(%rbp),%rdi
lea    0xe6c(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11f5 <check_pid+0x95>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1060 <kill@plt>
cmp    $0x0,%rax
jne    11db <check_pid+0x7b>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xa,%edi
call   1080 <exit@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
call   1050 <fprintf@plt>
jmp    120a <check_pid+0xaa>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_pid>:
push   %rbx
sub    $0x10,%rsp
lea    0xe94(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d1 <check_pid+0x71>
mov    %rax,%rbx
lea    0xe82(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11b4 <check_pid+0x54>
mov    0xc(%rsp),%edi
xor    %esi,%esi
call   1060 <kill@plt>
mov    0x2e3c(%rip),%rcx
mov    (%rcx),%edi
test   %rax,%rax
je     11d7 <check_pid+0x77>
lea    0xe87(%rip),%rsi
jmp    11c4 <check_pid+0x64>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe27(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xa,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [52 x i8] c"Another instance is running, please stop it first!\0A\00"
@.str.3 = [28 x i8] c"Stale lock file, ignoring!\0A\00"
@.str.4 = [34 x i8] c"Can not parse pidfile, ignoring!\0A\00"
define void @check_pid(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %31
9: ; preds = %1
%10 = load i32*, i32** %3
%11 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %25
13: ; preds = %9
%14 = load i32, i32* %4
%15 = call i64 @kill(i32 %14, i32 0)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @exit(i32 10)
unreachable
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %21
br label %28
25: ; preds = %9
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %28
28: ; preds = %25, %24
%29 = load i32*, i32** %3
%30 = call i32 @fclose(i32* %29)
br label %31
31: ; preds = %28, %1
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [52 x i8] c"Another instance is running, please stop it first!\0A\00"
@.str.3 = [28 x i8] c"Stale lock file, ignoring!\0A\00"
@.str.4 = [34 x i8] c"Can not parse pidfile, ignoring!\0A\00"
define void @check_pid(i8* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %24, label %6
6: ; preds = %1
%7 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %19
9: ; preds = %6
%10 = load i32, i32* %2
%11 = call i64 @kill(i32 %10, i32 0)
%12 = icmp eq i64 %11, 0
%13 = load i32, i32* @stderr
br i1 %12, label %14, label %17
14: ; preds = %9
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 10)
unreachable
17: ; preds = %9
%18 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %22
19: ; preds = %6
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %22
22: ; preds = %19, %17
%23 = call i32 @fclose(i32* %4)
br label %24
24: ; preds = %22, %1
ret void
}