#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 atof(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *smprintf(char *, ...);
char *gettemperature(char *sensor) {
  FILE *fp;
  char str[6];
  fp = fopen(sensor, "r");
  fgets(str, 6, fp);
  fclose(fp);
  if (str == NULL)
    return smprintf("");
  return smprintf("%02.0f°c", atof(str) / 1000);
}


x86 assembly (clang, -O0):
<gettemperature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x16(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x6,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x16(%rbp),%rdi
call   1040 <atof@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <smprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettemperature>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0x2(%rsp),%r14
mov    %r14,%rdi
mov    $0x6,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1040 <atof@plt>
cltq
imul   $0x10624dd3,%rax,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x26,%rsi
add    %eax,%esi
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1030 <smprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [10 x i8] c"%02.0f\C2\B0c\00"
define i8* @gettemperature(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [6 x i8]
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %3
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%8 = load i32*, i32** %3
%9 = call i32 @fgets(i8* %7, i32 6, i32* %8)
%10 = load i32*, i32** %3
%11 = call i32 @fclose(i32* %10)
%12 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%13 = call i32 @atof(i8* %12)
%14 = sdiv i32 %13, 1000
%15 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %14)
ret i8* %15
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [10 x i8] c"%02.0f\C2\B0c\00"
define i8* @gettemperature(i8* nocapture %0) {
%2 = alloca [6 x i8]
%3 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @fgets(i8* %3, i32 6, i32* %4)
%6 = call i32 @fclose(i32* %4)
%7 = call i32 @atof(i8* %3)
%8 = sdiv i32 %7, 1000
%9 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %8)
ret i8* %9
}