#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 */
struct stat {
  int st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
long fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
char *get_value(char *wdir, char *node, char *param) {
  char buffer[1024], *ret_pt;
  long size;
  struct stat sbuf;
  FILE *infile;
  buffer[0] = 0x0;
  strcat(buffer, wdir);
  strcat(buffer, "/DATA/");
  strcat(buffer, node);
  strcat(buffer, "/");
  strcat(buffer, param);
  if (stat(buffer, &sbuf) == -1) {
    return NULL;
  }
  ret_pt = (char *)malloc(sbuf.st_size + 1);
  infile = fopen(buffer, "r");
  if (infile == NULL) {
    fprintf(stderr, "edit_node: file open error, %s\n", buffer);
    fflush(NULL);
    return NULL;
  }
  size = fread(ret_pt, 1, sbuf.st_size, infile);
  if (size != sbuf.st_size) {
    fprintf(stderr, "edit_node: error reading file %s, returning...\n", buffer);
    fflush(NULL);
    return NULL;
  }
  fclose(infile);
  return ret_pt;
}


x86 assembly (clang, -O0):
<get_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movb   $0x0,-0x420(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <strcat@plt>
lea    -0x420(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <strcat@plt>
lea    -0x420(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10a0 <strcat@plt>
lea    -0x420(%rbp),%rdi
lea    -0x438(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    121d <get_value+0x9d>
movq   $0x0,-0x8(%rbp)
jmp    1311 <get_value+0x191>
mov    -0x438(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
lea    0xdc7(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x440(%rbp)
cmpq   $0x0,-0x440(%rbp)
jne    128c <get_value+0x10c>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xd98(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <fflush@plt>
movq   $0x0,-0x8(%rbp)
jmp    1311 <get_value+0x191>
mov    -0x428(%rbp),%rdi
mov    -0x438(%rbp),%edx
mov    -0x440(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x430(%rbp)
mov    -0x430(%rbp),%rax
movslq -0x438(%rbp),%rcx
cmp    %rcx,%rax
je     12fa <get_value+0x17a>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xd4a(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <fflush@plt>
movq   $0x0,-0x8(%rbp)
jmp    1311 <get_value+0x191>
mov    -0x440(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x428(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_value>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rsi
movb   $0x0,0x10(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <strcat@plt>
lea    0xe52(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10a0 <strcat@plt>
lea    0xe3d(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <strcat@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
je     1239 <get_value+0xb9>
movslq 0x8(%rsp),%r14
lea    0x1(%r14),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
lea    0xe02(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     123e <get_value+0xbe>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
cmp    %r14,%rax
jne    1250 <get_value+0xd0>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    1274 <get_value+0xf4>
xor    %r15d,%r15d
jmp    1274 <get_value+0xf4>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
jmp    1260 <get_value+0xe0>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1050 <fprintf@plt>
xor    %r15d,%r15d
xor    %edi,%edi
call   1080 <fflush@plt>
mov    %r15,%rax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [7 x i8] c"/DATA/\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [32 x i8] c"edit_node: file open error, %s\0A\00"
@.str.4 = [48 x i8] c"edit_node: error reading file %s, returning...\0A\00"
define i8* @get_value(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [1024 x i8]
%9 = alloca i8*
%10 = alloca i64
%11 = alloca %struct.stat
%12 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
store i8 0, i8* %13
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%15 = load i8*, i8** %5
%16 = call i32 @strcat(i8* %14, i8* %15)
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%18 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%20 = load i8*, i8** %6
%21 = call i32 @strcat(i8* %19, i8* %20)
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%23 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%25 = load i8*, i8** %7
%26 = call i32 @strcat(i8* %24, i8* %25)
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%28 = call i32 @stat(i8* %27, %struct.stat* %11)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %31
30: ; preds = %3
store i8* null, i8** %4
br label %66
31: ; preds = %3
%32 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%33 = load i32, i32* %32
%34 = add nsw i32 %33, 1
%35 = call i64 @malloc(i32 %34)
%36 = inttoptr i64 %35 to i8*
store i8* %36, i8** %9
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %38, i32** %12
%39 = load i32*, i32** %12
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %46
41: ; preds = %31
%42 = load i32, i32* @stderr
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%44 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %43)
%45 = call i32 @fflush(i32* null)
store i8* null, i8** %4
br label %66
46: ; preds = %31
%47 = load i8*, i8** %9
%48 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%49 = load i32, i32* %48
%50 = load i32*, i32** %12
%51 = call i64 @fread(i8* %47, i32 1, i32 %49, i32* %50)
store i64 %51, i64* %10
%52 = load i64, i64* %10
%53 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%54 = load i32, i32* %53
%55 = sext i32 %54 to i64
%56 = icmp ne i64 %52, %55
br i1 %56, label %57, label %62
57: ; preds = %46
%58 = load i32, i32* @stderr
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%60 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i8* %59)
%61 = call i32 @fflush(i32* null)
store i8* null, i8** %4
br label %66
62: ; preds = %46
%63 = load i32*, i32** %12
%64 = call i32 @fclose(i32* %63)
%65 = load i8*, i8** %9
store i8* %65, i8** %4
br label %66
66: ; preds = %62, %57, %41, %30
%67 = load i8*, i8** %4
ret i8* %67
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [7 x i8] c"/DATA/\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [32 x i8] c"edit_node: file open error, %s\0A\00"
@.str.4 = [48 x i8] c"edit_node: error reading file %s, returning...\0A\00"
define i8* @get_value(i8* %0, i8* %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = alloca %struct.stat
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = bitcast %struct.stat* %5 to i8*
store i8 0, i8* %6
%8 = call i32 @strcat(i8* %6, i8* %0)
%9 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @strcat(i8* %6, i8* %1)
%11 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @strcat(i8* %6, i8* %2)
%13 = call i32 @stat(i8* %6, %struct.stat* %5)
%14 = icmp eq i32 %13, -1
br i1 %14, label %37, label %15
15: ; preds = %3
%16 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%17 = load i32, i32* %16
%18 = add nsw i32 %17, 1
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
%21 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %15
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%26 = call i32 @fflush(i32* null)
br label %37
27: ; preds = %15
%28 = call i64 @fread(i8* %20, i32 1, i32 %17, i32* %21)
%29 = sext i32 %17 to i64
%30 = icmp eq i64 %28, %29
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%34 = call i32 @fflush(i32* null)
br label %37
35: ; preds = %27
%36 = call i32 @fclose(i32* %21)
br label %37
37: ; preds = %3, %35, %31, %23
%38 = phi i8* [ null, %23 ], [ null, %31 ], [ %20, %35 ], [ null, %3 ]
ret i8* %38
}