#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 pid_t;

/* Variables and functions */
scalar_t__ file_exists(char const *);
int /*<<< orphan*/ free(char *);
char *load_textfile_to_memory(char const *);
int /*<<< orphan*/ sscanf(char *, char *, long long *);
pid_t dpid_retrieve(const char *dpid_file) {
  char *dpid_data;
  long long int retrieved_dpid = 0;
  if ((dpid_data = load_textfile_to_memory(dpid_file)) == NULL) {
    if (file_exists(dpid_file)) {
      return (0);
    } else {
      return (-1);
    }
  }
  sscanf(dpid_data, "%lld", &retrieved_dpid);
  free(dpid_data);
  return (retrieved_dpid);
}


x86 assembly (clang, -O0):
<dpid_retrieve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <load_textfile_to_memory@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1196 <dpid_retrieve+0x56>
mov    -0x10(%rbp),%rdi
call   1040 <file_exists@plt>
cmp    $0x0,%rax
je     118a <dpid_retrieve+0x4a>
movl   $0x0,-0x4(%rbp)
jmp    11ba <dpid_retrieve+0x7a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ba <dpid_retrieve+0x7a>
mov    -0x18(%rbp),%rdi
lea    0xe5f(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dpid_retrieve>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movq   $0x0,(%rsp)
call   1050 <load_textfile_to_memory@plt>
test   %rax,%rax
je     117b <dpid_retrieve+0x3b>
mov    %rax,%rbx
lea    0xe9d(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1060 <sscanf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    (%rsp),%eax
jmp    1189 <dpid_retrieve+0x49>
mov    %r14,%rdi
call   1040 <file_exists@plt>
cmp    $0x1,%rax
sbb    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%lld\00"
define i32 @dpid_retrieve(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
store i64 0, i64* %5
%6 = load i8*, i8** %3
%7 = call i8* @load_textfile_to_memory(i8* %6)
store i8* %7, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i64 @file_exists(i8* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 0, i32* %2
br label %22
14: ; preds = %9
store i32 -1, i32* %2
br label %22
15: ; preds = %1
%16 = load i8*, i8** %4
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %5)
%18 = load i8*, i8** %4
%19 = call i32 @free(i8* %18)
%20 = load i64, i64* %5
%21 = trunc i64 %20 to i32
store i32 %21, i32* %2
br label %22
22: ; preds = %15, %14, %13
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lld\00"
define i32 @dpid_retrieve(i8* %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%4 = tail call i8* @load_textfile_to_memory(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = tail call i64 @file_exists(i8* %0)
%8 = icmp eq i64 %7, 0
%9 = sext i1 %8 to i32
br label %15
10: ; preds = %1
%11 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %2)
%12 = call i32 @free(i8* %4)
%13 = load i64, i64* %2
%14 = trunc i64 %13 to i32
br label %15
15: ; preds = %6, %10
%16 = phi i32 [ %14, %10 ], [ %9, %6 ]
ret i32 %16
}