#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 uint32_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ librpip_sysfs_node_file_open(int, int, int /*<<< orphan*/, int *);
scalar_t__ read(int, char *, int);
uint32_t librpip_sysfs_node_file_get_int(uint32_t sysfsid, uint32_t fileid,
                                         int *value) {
  int fd, result;
  char buf[20];
  result = 0;
  if (librpip_sysfs_node_file_open(sysfsid, fileid, O_RDONLY, &fd)) {
    if (read(fd, buf, sizeof(buf))) {
      *value = atoi(buf);
      result = 1;
    }
    close(fd);
  }
  return result;
}


x86 assembly (clang, -O0):
<librpip_sysfs_node_file_get_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
call   1050 <librpip_sysfs_node_file_open@plt>
cmp    $0x0,%rax
je     11b6 <librpip_sysfs_node_file_get_int+0x76>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x14,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
je     11ae <librpip_sysfs_node_file_get_int+0x6e>
lea    -0x30(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<librpip_sysfs_node_file_get_int>:
push   %rbx
sub    $0x30,%rsp
mov    %rdx,%rbx
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
call   1050 <librpip_sysfs_node_file_open@plt>
test   %rax,%rax
je     118b <librpip_sysfs_node_file_get_int+0x4b>
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x14,%edx
call   1040 <read@plt>
test   %rax,%rax
je     118f <librpip_sysfs_node_file_get_int+0x4f>
lea    0x10(%rsp),%rdi
call   1060 <atoi@plt>
mov    %eax,(%rbx)
mov    $0x1,%ebx
jmp    1191 <librpip_sysfs_node_file_get_int+0x51>
xor    %ebx,%ebx
jmp    119a <librpip_sysfs_node_file_get_int+0x5a>
xor    %ebx,%ebx
mov    0xc(%rsp),%edi
call   1030 <close@plt>
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @librpip_sysfs_node_file_get_int(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [20 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %8
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = load i32, i32* @O_RDONLY
%13 = call i64 @librpip_sysfs_node_file_open(i32 %10, i32 %11, i32 %12, i32* %7)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %27
15: ; preds = %3
%16 = load i32, i32* %7
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%18 = call i64 @read(i32 %16, i8* %17, i32 20)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%22 = call i32 @atoi(i8* %21)
%23 = load i32*, i32** %6
store i32 %22, i32* %23
store i32 1, i32* %8
br label %24
24: ; preds = %20, %15
%25 = load i32, i32* %7
%26 = call i32 @close(i32 %25)
br label %27
27: ; preds = %24, %3
%28 = load i32, i32* %8
ret i32 %28
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @librpip_sysfs_node_file_get_int(i32 %0, i32 %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca [20 x i8]
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%8 = load i32, i32* @O_RDONLY
%9 = call i64 @librpip_sysfs_node_file_open(i32 %0, i32 %1, i32 %8, i32* %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %3
%12 = load i32, i32* %4
%13 = call i64 @read(i32 %12, i8* %7, i32 20)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 @atoi(i8* %7)
store i32 %16, i32* %2
br label %17
17: ; preds = %15, %11
%18 = phi i32 [ 1, %15 ], [ 0, %11 ]
%19 = load i32, i32* %4
%20 = call i32 @close(i32 %19)
br label %21
21: ; preds = %17, %3
%22 = phi i32 [ %18, %17 ], [ 0, %3 ]
ret i32 %22
}