#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
int get_property(const char *path, const char *property, void *buf,
                 int buf_sz) {
  FILE *fp;
  int rc;
  char dir[1024];
  if ((path == NULL) || (property == NULL))
    return -1;
  sprintf(dir, "%s/%s", path, property);
  fp = fopen(dir, "r");
  if (fp == NULL)
    return -1;
  rc = fread(buf, buf_sz, 1, fp);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<get_property>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1170 <get_property+0x30>
cmpq   $0x0,-0x18(%rbp)
jne    117c <get_property+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <get_property+0xad>
lea    -0x440(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe6e(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x440(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11c5 <get_property+0x85>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <get_property+0xad>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_property>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     11ae <get_property+0x6e>
mov    %ecx,%r14d
mov    %rsi,%rcx
test   %rsi,%rsi
je     11ae <get_property+0x6e>
mov    %rdx,%r15
mov    %rdi,%rdx
lea    0xe91(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11ae <get_property+0x6e>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r14d,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @get_property(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca [1024 x i8]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %4
%16 = load i8*, i8** %7
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %15, %4
store i32 -1, i32* %5
br label %36
19: ; preds = %15
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%21 = load i8*, i8** %6
%22 = load i8*, i8** %7
%23 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %10
%26 = load i32*, i32** %10
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %29
28: ; preds = %19
store i32 -1, i32* %5
br label %36
29: ; preds = %19
%30 = load i8*, i8** %8
%31 = load i32, i32* %9
%32 = load i32*, i32** %10
%33 = call i32 @fread(i8* %30, i32 %31, i32 1, i32* %32)
store i32 %33, i32* %11
%34 = load i32*, i32** %10
%35 = call i32 @fclose(i32* %34)
store i32 0, i32* %5
br label %36
36: ; preds = %29, %28, %18
%37 = load i32, i32* %5
ret i32 %37
}

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