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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *readfile(char *, char *);
char *smprintf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *);
char *gettemperature(char *base, char *sensor) {
  char *co;
  int temp;
  co = readfile(base, sensor);
  if (co == NULL)
    return smprintf("");
  sscanf(co, "%d", &temp);
  free(co);
  return smprintf("%02.0f°C", (double)temp / 1000);
}


x86 assembly (clang, -O0):
<gettemperature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <readfile@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1183 <gettemperature+0x43>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1040 <smprintf@plt>
mov    %rax,-0x8(%rbp)
jmp    11c3 <gettemperature+0x83>
mov    -0x20(%rbp),%rdi
lea    0xe7a(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  0xe53(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe53(%rip),%rdi
mov    $0x1,%al
call   1040 <smprintf@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettemperature>:
push   %rbx
sub    $0x10,%rsp
call   1060 <readfile@plt>
test   %rax,%rax
je     1190 <gettemperature+0x50>
mov    %rax,%rbx
lea    0xeaf(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <sscanf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
cvtsi2sdl 0xc(%rsp),%xmm0
divsd  0xe84(%rip),%xmm0
lea    0xe88(%rip),%rdi
mov    $0x1,%al
call   1040 <smprintf@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
jmp    1040 <smprintf@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [10 x i8] c"%02.0f\C2\B0C\00"
define i8* @gettemperature(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = call i8* @readfile(i8* %8, i8* %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %3
br label %24
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%18 = load i8*, i8** %6
%19 = call i32 @free(i8* %18)
%20 = load i32, i32* %7
%21 = sitofp i32 %20 to double
%22 = fdiv double %21, 1.000000e+03
%23 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %22)
store i8* %23, i8** %3
br label %24
24: ; preds = %15, %13
%25 = load i8*, i8** %3
ret i8* %25
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [10 x i8] c"%02.0f\C2\B0C\00"
define i8* @gettemperature(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i8* @readfile(i8* %0, i8* %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %16
9: ; preds = %2
%10 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%11 = call i32 @free(i8* %5)
%12 = load i32, i32* %3
%13 = sitofp i32 %12 to double
%14 = fdiv double %13, 1.000000e+03
%15 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %14)
br label %16
16: ; preds = %9, %7
%17 = phi i8* [ %8, %7 ], [ %15, %9 ]
ret i8* %17
}