#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
scalar_t__ pread(int, char *, int, int /*<<< orphan*/);
unsigned long long strtoull(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
long long rapl_read_value(int fd) {
  unsigned long long val;
  char buf[30];
  if (pread(fd, buf, sizeof(buf), 0) <= 0) {
    perror("rapl_read_value");
    return -1;
  }
  val = strtoull(buf, NULL, 0);
  return val;
}


x86 assembly (clang, -O0):
<rapl_read_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x1e,%edx
xor    %ecx,%ecx
call   1050 <pread@plt>
cmp    $0x0,%rax
jg     1171 <rapl_read_value+0x41>
lea    0xea1(%rip),%rdi
call   1040 <perror@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    118c <rapl_read_value+0x5c>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1030 <strtoull@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rapl_read_value>:
sub    $0x28,%rsp
mov    %rsp,%rsi
mov    $0x1e,%edx
xor    %ecx,%ecx
call   1050 <pread@plt>
test   %rax,%rax
jle    1159 <rapl_read_value+0x29>
mov    %rsp,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <strtoull@plt>
add    $0x28,%rsp
ret
lea    0xea0(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffffffffffff,%rax
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"rapl_read_value\00"
define i64 @rapl_read_value(i32 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i64
%5 = alloca [30 x i8]
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%8 = call i64 @pread(i32 %6, i8* %7, i32 30, i32 0)
%9 = icmp sle i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i64 -1, i64* %2
br label %16
12: ; preds = %1
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%14 = call i64 @strtoull(i8* %13, i32* null, i32 0)
store i64 %14, i64* %4
%15 = load i64, i64* %4
store i64 %15, i64* %2
br label %16
16: ; preds = %12, %10
%17 = load i64, i64* %2
ret i64 %17
}

LLVM IR (-O2):
@.str = [16 x i8] c"rapl_read_value\00"
define i64 @rapl_read_value(i32 %0) {
%2 = alloca [30 x i8]
%3 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%4 = call i64 @pread(i32 %0, i8* %3, i32 30, i32 0)
%5 = icmp slt i64 %4, 1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %10
8: ; preds = %1
%9 = call i64 @strtoull(i8* nocapture %3, i32* null, i32 0)
br label %10
10: ; preds = %8, %6
%11 = phi i64 [ -1, %6 ], [ %9, %8 ]
ret i64 %11
}