#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 asprintf(char **, char *, char const *, char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int fscanf(int /*<<< orphan*/ *, char const *, void *);
int file_read_value(const char *path, const char *name, const char *format,
                    void *value) {
  FILE *file;
  char *rpath;
  int ret;
  ret = asprintf(&rpath, "%s/%s", path, name);
  if (ret < 0)
    return ret;
  file = fopen(rpath, "r");
  if (!file) {
    ret = -1;
    goto out_free;
  }
  ret = fscanf(file, format, value) != 1 ? -1 : 0;
  fclose(file);
out_free:
  free(rpath);
  return ret;
}


x86 assembly (clang, -O0):
<file_read_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x38(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1060 <asprintf@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    1198 <file_read_value+0x48>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fe <file_read_value+0xae>
mov    -0x38(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11c3 <file_read_value+0x73>
movl   $0xffffffff,-0x3c(%rbp)
jmp    11ef <file_read_value+0x9f>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <fscanf@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    $0x1,%edx
cmovne %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_read_value>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rcx
mov    %rdi,%rdx
lea    0xe96(%rip),%rsi
mov    %rsp,%rdi
call   1060 <asprintf@plt>
test   %eax,%eax
js     11b1 <file_read_value+0x61>
mov    (%rsp),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11b5 <file_read_value+0x65>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <fscanf@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
setne  %bpl
neg    %ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11ba <file_read_value+0x6a>
mov    %eax,%ebp
jmp    11c3 <file_read_value+0x73>
mov    $0xffffffff,%ebp
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%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 @file_read_value(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%13 = load i8*, i8** %6
%14 = load i8*, i8** %7
%15 = call i32 @asprintf(i8** %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %14)
store i32 %15, i32* %12
%16 = load i32, i32* %12
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = load i32, i32* %12
store i32 %19, i32* %5
br label %40
20: ; preds = %4
%21 = load i8*, i8** %11
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %10
%23 = load i32*, i32** %10
%24 = icmp ne i32* %23, null
br i1 %24, label %26, label %25
25: ; preds = %20
store i32 -1, i32* %12
br label %36
26: ; preds = %20
%27 = load i32*, i32** %10
%28 = load i8*, i8** %8
%29 = load i8*, i8** %9
%30 = call i32 @fscanf(i32* %27, i8* %28, i8* %29)
%31 = icmp ne i32 %30, 1
%32 = zext i1 %31 to i64
%33 = select i1 %31, i32 -1, i32 0
store i32 %33, i32* %12
%34 = load i32*, i32** %10
%35 = call i32 @fclose(i32* %34)
br label %36
36: ; preds = %26, %25
%37 = load i8*, i8** %11
%38 = call i32 @free(i8* %37)
%39 = load i32, i32* %12
store i32 %39, i32* %5
br label %40
40: ; preds = %36, %18
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @file_read_value(i8* %0, i8* %1, i8* nocapture %2, i8* %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
%7 = call i32 @asprintf(i8** %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%8 = icmp slt i32 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %4
%10 = load i8*, i8** %5
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %18, label %13
13: ; preds = %9
%14 = call i32 @fscanf(i32* %11, i8* %2, i8* %3)
%15 = icmp ne i32 %14, 1
%16 = sext i1 %15 to i32
%17 = call i32 @fclose(i32* %11)
br label %18
18: ; preds = %9, %13
%19 = phi i32 [ %16, %13 ], [ -1, %9 ]
%20 = load i8*, i8** %5
%21 = call i32 @free(i8* %20)
br label %22
22: ; preds = %4, %18
%23 = phi i32 [ %19, %18 ], [ %7, %4 ]
ret i32 %23
}