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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *);
scalar_t__ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int check_pid(const char *file) {
  FILE *fp;
  fp = fopen(file, "r");
  if (fp) {
    pid_t pid;
    int n;
    n = fscanf(fp, "%d", &pid);
    fclose(fp);
    if (n != 1 || kill(pid, 0) == 0)
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_pid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ba <check_pid+0x7a>
mov    -0x18(%rbp),%rdi
lea    0xe8c(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <fscanf@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x1,-0x20(%rbp)
jne    11a9 <check_pid+0x69>
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   1050 <kill@plt>
cmp    $0x0,%rax
jne    11b5 <check_pid+0x75>
movl   $0x1,-0x4(%rbp)
jmp    11c1 <check_pid+0x81>
jmp    11ba <check_pid+0x7a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_pid>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1193 <check_pid+0x53>
mov    %rax,%rbx
lea    0xea4(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    $0x1,%ebp
jne    118c <check_pid+0x4c>
mov    0x4(%rsp),%edi
xor    %ebx,%ebx
xor    %esi,%esi
call   1050 <kill@plt>
test   %rax,%rax
jne    1195 <check_pid+0x55>
mov    $0x1,%ebx
jmp    1195 <check_pid+0x55>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @check_pid(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %4
%9 = load i32*, i32** %4
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %24
11: ; preds = %1
%12 = load i32*, i32** %4
%13 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
store i32 %13, i32* %6
%14 = load i32*, i32** %4
%15 = call i32 @fclose(i32* %14)
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 1
br i1 %17, label %22, label %18
18: ; preds = %11
%19 = load i32, i32* %5
%20 = call i64 @kill(i32 %19, i32 0)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18, %11
store i32 1, i32* %2
br label %25
23: ; preds = %18
br label %24
24: ; preds = %23, %1
store i32 0, i32* %2
br label %25
25: ; preds = %24, %22
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @check_pid(i8* nocapture %0) {
%2 = alloca i32
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %16, label %5
5: ; preds = %1
%6 = bitcast i32* %2 to i8*
%7 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = call i32 @fclose(i32* %3)
%9 = icmp eq i32 %7, 1
br i1 %9, label %10, label %14
10: ; preds = %5
%11 = load i32, i32* %2
%12 = call i64 @kill(i32 %11, i32 0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %5, %10
br label %16
15: ; preds = %10
br label %16
16: ; preds = %1, %15, %14
%17 = phi i32 [ 1, %14 ], [ 0, %15 ], [ 0, %1 ]
ret i32 %17
}