#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 fscanf(int /*<<< orphan*/ *, char *, unsigned int *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
void put_cpu_temp(char *out, void *arg) {
  static unsigned int prev_temp = 0;
  unsigned int cur_temp, avg_temp;
  FILE *stat = fopen((char *)arg, "r");
  if (fscanf(stat, "%u", &cur_temp) != 1) {
    sprintf(out, "??°C");
    fclose(stat);
    return;
  }
  fclose(stat);
  avg_temp = (cur_temp + prev_temp) / 2000;
  prev_temp = cur_temp;
  sprintf(out, "%d°C", avg_temp);
}


x86 assembly (clang, -O0):
<put_cpu_temp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe93(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     11a1 <put_cpu_temp+0x61>
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11dd <put_cpu_temp+0x9d>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    0x2e91(%rip),%eax
mov    $0x7d0,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,0x2e7c(%rip)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_cpu_temp>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xeaf(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xe9f(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11ad <put_cpu_temp+0x6d>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x4(%rsp),%eax
mov    0x2ebd(%rip),%ecx
add    %eax,%ecx
imul   $0x10624dd3,%rcx,%rdx
shr    $0x27,%rdx
mov    %eax,0x2eaa(%rip)
lea    0xe6a(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
jmp    11c3 <put_cpu_temp+0x83>
movw   $0x43,0x4(%r14)
movl   $0xb0c23f3f,(%r14)
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@put_cpu_temp.prev_temp = internal global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [6 x i8] c"??\C2\B0C\00"
@.str.3 = [6 x i8] c"%d\C2\B0C\00"
define void @put_cpu_temp(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32*, i32** %7
%17 = call i32 @fclose(i32* %16)
br label %29
18: ; preds = %2
%19 = load i32*, i32** %7
%20 = call i32 @fclose(i32* %19)
%21 = load i32, i32* %5
%22 = load i32, i32* @put_cpu_temp.prev_temp
%23 = add i32 %21, %22
%24 = udiv i32 %23, 2000
store i32 %24, i32* %6
%25 = load i32, i32* %5
store i32 %25, i32* @put_cpu_temp.prev_temp
%26 = load i8*, i8** %3
%27 = load i32, i32* %6
%28 = call i32 (i8*, i8*, ...) @sprintf(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %18, %13
ret void
}

LLVM IR (-O2):
@put_cpu_temp.prev_temp = internal unnamed_addr global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [6 x i8] c"??\C2\B0C\00"
@.str.3 = [6 x i8] c"%d\C2\B0C\00"
define void @put_cpu_temp(i8* nocapture writeonly %0, i8* nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = icmp eq i32 %6, 1
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = call i32 @fclose(i32* %5)
br label %17
10: ; preds = %2
%11 = call i32 @fclose(i32* %5)
%12 = load i32, i32* %3
%13 = load i32, i32* @put_cpu_temp.prev_temp
%14 = add i32 %13, %12
%15 = udiv i32 %14, 2000
store i32 %12, i32* @put_cpu_temp.prev_temp
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %10, %8
ret void
}