#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 */
unsigned int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int);
void get_hwmon_temp(unsigned int *value, unsigned int *sensor) {
  char buffer[1024];
  FILE *fp;
  snprintf(buffer, 1024, "/sys/class/hwmon/hwmon0/device/temp%i_input",
           *sensor);
  fp = fopen(buffer, "r");
  if (fp != NULL) {
    if (fgets(buffer, 1024, fp) != NULL)
      *value = atoi(buffer);
    fclose(fp);
  }
}


x86 assembly (clang, -O0):
<get_hwmon_temp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    $0x400,%esi
lea    0xe84(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x410(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     11eb <get_hwmon_temp+0x9b>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11df <get_hwmon_temp+0x8f>
lea    -0x410(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x418(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_hwmon_temp>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r14
mov    (%rsi),%ecx
lea    0xe9a(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1040 <snprintf@plt>
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b5 <get_hwmon_temp+0x65>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11ad <get_hwmon_temp+0x5d>
mov    %rsp,%rdi
call   1070 <atoi@plt>
mov    %eax,(%r14)
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [44 x i8] c"/sys/class/hwmon/hwmon0/device/temp%i_input\00"
@.str.1 = [2 x i8] c"r\00"
define void @get_hwmon_temp(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca i32*
store i32* %0, i32** %3
store i32* %1, i32** %4
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = load i32*, i32** %4
%9 = load i32, i32* %8
%10 = call i32 @snprintf(i8* %7, i32 1024, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %27
15: ; preds = %2
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%17 = load i32*, i32** %6
%18 = call i32* @fgets(i8* %16, i32 1024, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%22 = call i32 @atoi(i8* %21)
%23 = load i32*, i32** %3
store i32 %22, i32* %23
br label %24
24: ; preds = %20, %15
%25 = load i32*, i32** %6
%26 = call i32 @fclose(i32* %25)
br label %27
27: ; preds = %24, %2
ret void
}

LLVM IR (-O2):
@.str = [44 x i8] c"/sys/class/hwmon/hwmon0/device/temp%i_input\00"
@.str.1 = [2 x i8] c"r\00"
define void @get_hwmon_temp(i32* nocapture writeonly %0, i32* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* %1
%6 = call i32 @snprintf(i8* %4, i32 1024, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %16, label %9
9: ; preds = %2
%10 = call i32* @fgets(i8* %4, i32 1024, i32* %7)
%11 = icmp eq i32* %10, null
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32 @atoi(i8* %4)
store i32 %13, i32* %0
br label %14
14: ; preds = %12, %9
%15 = call i32 @fclose(i32* %7)
br label %16
16: ; preds = %14, %2
ret void
}