#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
double strtod(char *, int /*<<< orphan*/ *);
int os_sysfs_cqm_llc_scale(const char *path, double *scale) {
  FILE *fp;
  char buf[512];
  *scale = 0.0;
  if ((fp = fopen(path, "r")) == NULL) {
    return (-1);
  }
  if (fgets(buf, 512, fp) == NULL) {
    fclose(fp);
    return (-1);
  }
  fclose(fp);
  *scale = strtod(buf, NULL);
  return 0;
}


x86 assembly (clang, -O0):
<os_sysfs_cqm_llc_scale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe97(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1188 <os_sysfs_cqm_llc_scale+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <os_sysfs_cqm_llc_scale+0xa4>
lea    -0x220(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    11bc <os_sysfs_cqm_llc_scale+0x7c>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <os_sysfs_cqm_llc_scale+0xa4>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x220(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_sysfs_cqm_llc_scale>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%r14
movq   $0x0,(%rsi)
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
je     11a4 <os_sysfs_cqm_llc_scale+0x64>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %r12,%r12
je     11a4 <os_sysfs_cqm_llc_scale+0x64>
xor    %r15d,%r15d
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
movsd  %xmm0,(%r14)
mov    %r15d,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @os_sysfs_cqm_llc_scale(i8* %0, double* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca double*
%6 = alloca i32*
%7 = alloca [512 x i8]
store i8* %0, i8** %4
store double* %1, double** %5
%8 = load double*, double** %5
store double 0.000000e+00, double* %8
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %27
13: ; preds = %2
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%15 = load i32*, i32** %6
%16 = call i32* @fgets(i8* %14, i32 512, i32* %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32*, i32** %6
%20 = call i32 @fclose(i32* %19)
store i32 -1, i32* %3
br label %27
21: ; preds = %13
%22 = load i32*, i32** %6
%23 = call i32 @fclose(i32* %22)
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%25 = call double @strtod(i8* %24, i32* null)
%26 = load double*, double** %5
store double %25, double* %26
store i32 0, i32* %3
br label %27
27: ; preds = %21, %18, %12
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @os_sysfs_cqm_llc_scale(i8* nocapture %0, double* nocapture writeonly %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
store double 0.000000e+00, double* %1
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = call i32* @fgets(i8* %4, i32 512, i32* %5)
%9 = icmp eq i32* %8, null
%10 = call i32 @fclose(i32* %5)
br i1 %9, label %13, label %11
11: ; preds = %7
%12 = call double @strtod(i8* nocapture %4, i32* null)
store double %12, double* %1
br label %13
13: ; preds = %7, %2, %11
%14 = phi i32 [ 0, %11 ], [ -1, %2 ], [ -1, %7 ]
ret i32 %14
}