#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
char *smprintf(char *, int);
char *getcputemp(void) {
  int temperature;
  FILE *fp;
  fp = fopen("/sys/devices/platform/coretemp.0/hwmon/hwmon0/temp1_input", "r");
  fscanf(fp, "%d", &temperature);
  fclose(fp);
  return smprintf("%d", temperature / 1000);
}


x86 assembly (clang, -O0):
<getcputemp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
lea    0xee4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xed2(%rip),%rsi
lea    -0x4(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xeac(%rip),%rdi
call   1030 <smprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getcputemp>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
lea    0xee8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xedb(%rip),%r14
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
movslq 0x4(%rsp),%rax
imul   $0x10624dd3,%rax,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x26,%rsi
add    %eax,%esi
mov    %r14,%rdi
call   1030 <smprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [58 x i8] c"/sys/devices/platform/coretemp.0/hwmon/hwmon0/temp1_input\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
define i8* @getcputemp() {
%1 = alloca i32
%2 = alloca i32*
%3 = call i32* @fopen(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = load i32*, i32** %2
%7 = call i32 @fclose(i32* %6)
%8 = load i32, i32* %1
%9 = sdiv i32 %8, 1000
%10 = call i8* @smprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %9)
ret i8* %10
}

LLVM IR (-O2):
@.str = [58 x i8] c"/sys/devices/platform/coretemp.0/hwmon/hwmon0/temp1_input\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
define i8* @getcputemp() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%5 = call i32 @fclose(i32* %3)
%6 = load i32, i32* %1
%7 = sdiv i32 %6, 1000
%8 = call i8* @smprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %7)
ret i8* %8
}