#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*/ EIO;
int /*<<< orphan*/ ReadValueFromFp(int /*<<< orphan*/ *, unsigned int *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
void ReadValueFromSysfsFile(char *fname, unsigned int *value) {
  FILE *fp;
  fp = fopen(fname, "r");
  if (!fp) {
    printf("ERROR: failed to open %s for reading value\n", fname);
    exit(EIO);
  }
  ReadValueFromFp(fp, value);
  fclose(fp);
  return;
}


x86 assembly (clang, -O0):
<ReadValueFromSysfsFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119d <ReadValueFromSysfsFile+0x4d>
mov    -0x8(%rbp),%rsi
lea    0xe78(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <ReadValueFromFp@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadValueFromSysfsFile>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1187 <ReadValueFromSysfsFile+0x37>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <ReadValueFromFp@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>
lea    0xe74(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [44 x i8] c"ERROR: failed to open %s for reading value\0A\00"
@EIO = global i32 0
define void @ReadValueFromSysfsFile(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
store i8* %0, i8** %3
store i32* %1, i32** %4
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp ne i32* %8, null
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EIO
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = load i32*, i32** %5
%17 = load i32*, i32** %4
%18 = call i32 @ReadValueFromFp(i32* %16, i32* %17)
%19 = load i32*, i32** %5
%20 = call i32 @fclose(i32* %19)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [44 x i8] c"ERROR: failed to open %s for reading value\0A\00"
@EIO = global i32 0
define void @ReadValueFromSysfsFile(i8* %0, i32* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%7 = load i32, i32* @EIO
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = tail call i32 @ReadValueFromFp(i32* %3, i32* %1)
%11 = tail call i32 @fclose(i32* %3)
ret void
}