#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 */
double atof(char *);
int /*<<< orphan*/ free(char *);
char *readfile(char *, char *);
char *smprintf(char *, ...);
char *gettemperature(char *base, char *sensor) {
  char *co, *ret;
  co = readfile(base, sensor);
  if (co == NULL) {
    free(co);
    return smprintf("");
  }
  double temp = atof(co);
  free(co);
  ret = smprintf("%02.0f°C", temp / 1000);
  return ret;
}


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    118c <gettemperature+0x4c>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <smprintf@plt>
mov    %rax,-0x8(%rbp)
jmp    11ce <gettemperature+0x8e>
mov    -0x20(%rbp),%rdi
call   1050 <atof@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x30(%rbp),%xmm0
movsd  0xe50(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe4d(%rip),%rdi
mov    $0x1,%al
call   1040 <smprintf@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
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     1189 <gettemperature+0x49>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <atof@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
divsd  0xe8a(%rip),%xmm0
lea    0xe8b(%rip),%rdi
mov    $0x1,%al
add    $0x10,%rsp
pop    %rbx
jmp    1040 <smprintf@plt>
xor    %edi,%edi
call   1030 <free@plt>
lea    0xe7a(%rip),%rdi
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
jmp    1040 <smprintf@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [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 i8*
%8 = alloca double
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i8* @readfile(i8* %9, i8* %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = call i32 @free(i8* %15)
%17 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %3
br label %27
18: ; preds = %2
%19 = load i8*, i8** %6
%20 = call double @atof(i8* %19)
store double %20, double* %8
%21 = load i8*, i8** %6
%22 = call i32 @free(i8* %21)
%23 = load double, double* %8
%24 = fdiv double %23, 1.000000e+03
%25 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %24)
store i8* %25, i8** %7
%26 = load i8*, i8** %7
store i8* %26, i8** %3
br label %27
27: ; preds = %18, %14
%28 = load i8*, i8** %3
ret i8* %28
}

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