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

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ getpid();
int sscanf(char *, char *, scalar_t__ *);
void check_pid_file(void) {
  char buf[256];
  pid_t pid;
  FILE *fp;
  fp = fopen("/var/run/rasp4you.pid", "r");
  if (fp == NULL)
    return;
  if (fgets(buf, 128, fp) != NULL && sscanf(buf, "%u", &pid) == 1) {
    if (pid != getpid())
      exit(0);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<check_pid_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    0xe8e(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x110(%rbp)
cmpq   $0x0,-0x110(%rbp)
jne    1198 <check_pid_file+0x38>
jmp    121d <check_pid_file+0xbd>
lea    -0x100(%rbp),%rdi
mov    -0x110(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1211 <check_pid_file+0xb1>
lea    -0x100(%rbp),%rdi
lea    0xe50(%rip),%rsi
lea    -0x108(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1211 <check_pid_file+0xb1>
mov    -0x108(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,%rcx
mov    -0x118(%rbp),%rax
cmp    %rcx,%rax
je     120c <check_pid_file+0xac>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    1211 <check_pid_file+0xb1>
mov    -0x110(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_pid_file>:
push   %r14
push   %rbx
sub    $0x118,%rsp
lea    0xe8f(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d0 <check_pid_file+0x70>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11c8 <check_pid_file+0x68>
lea    0xe75(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11c8 <check_pid_file+0x68>
mov    0x8(%rsp),%r14
xor    %eax,%eax
call   1030 <getpid@plt>
cmp    %rax,%r14
jne    11db <check_pid_file+0x7b>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"/var/run/rasp4you.pid\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%u\00"
define void @check_pid_file() {
%1 = alloca [256 x i8]
%2 = alloca i64
%3 = alloca i32*
%4 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = load i32*, i32** %3
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %8
7: ; preds = %0
br label %27
8: ; preds = %0
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%10 = load i32*, i32** %3
%11 = call i32* @fgets(i8* %9, i32 128, i32* %10)
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %24
13: ; preds = %8
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64* %2)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = load i64, i64* %2
%19 = call i64 (...) @getpid()
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %17
br label %24
24: ; preds = %23, %13, %8
%25 = load i32*, i32** %3
%26 = call i32 @fclose(i32* %25)
br label %27
27: ; preds = %24, %7
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"/var/run/rasp4you.pid\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%u\00"
define void @check_pid_file() {
%1 = alloca [256 x i8]
%2 = alloca i64
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = bitcast i64* %2 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %21, label %7
7: ; preds = %0
%8 = call i32* @fgets(i8* %3, i32 128, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %19, label %10
10: ; preds = %7
%11 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64* %2)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i64, i64* %2
%15 = call i64 (...) @getpid()
%16 = icmp eq i64 %14, %15
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %13, %10, %7
%20 = call i32 @fclose(i32* %5)
br label %21
21: ; preds = %0, %19
ret void
}