#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*/ F_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int getPid() {
  FILE *pidfp;
  int pid;
  if (access("/tmp/SysDiffLog_pid", F_OK) == -1)
    return -1;
  pidfp = fopen("/tmp/sysdifflog_pid", "r");
  fscanf(pidfp, "%d", &pid);
  fclose(pidfp);
  return pid;
}


x86 assembly (clang, -O0):
<getPid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
jne    1172 <getPid+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <getPid+0x6c>
lea    0xe9b(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPid>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xeab(%rip),%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     1197 <getPid+0x57>
lea    0xeae(%rip),%rdi
lea    0xebb(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xeae(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%eax
jmp    119c <getPid+0x5c>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"/tmp/SysDiffLog_pid\00"
@F_OK = global i32 0
@.str.1 = [20 x i8] c"/tmp/sysdifflog_pid\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @getPid() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = load i32, i32* @F_OK
%5 = call i32 @access(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %8
7: ; preds = %0
store i32 -1, i32* %1
br label %15
8: ; preds = %0
%9 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%12 = load i32*, i32** %2
%13 = call i32 @fclose(i32* %12)
%14 = load i32, i32* %3
store i32 %14, i32* %1
br label %15
15: ; preds = %8, %7
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
@.str = [20 x i8] c"/tmp/SysDiffLog_pid\00"
@F_OK = global i32 0
@.str.1 = [20 x i8] c"/tmp/sysdifflog_pid\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @getPid() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @F_OK
%4 = tail call i32 @access(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %11, label %6
6: ; preds = %0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%9 = call i32 @fclose(i32* %7)
%10 = load i32, i32* %1
br label %11
11: ; preds = %0, %6
%12 = phi i32 [ %10, %6 ], [ -1, %0 ]
ret i32 %12
}