#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*/ buff;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
double strtol(char *, char **, int);
double temperature_DS18B20(void) {
  char tempChar[6];
  double temperature;
  char *pEnd;
  FILE *fd = NULL;
  char buff[1024];
  memset(buff, 0, sizeof(buff));
  fd = fopen("/sys/bus/w1/devices/28-041591dd2cff/w1_slave", "r");
  if (NULL == fd) {
    printf("\n fopen() Error!!!\n");
    return 1;
  }
  if (1 * 74 != fread(buff, 1, 74, fd)) {
    printf("\n fread() failed\n");
    return 1;
  }
  fclose(fd);
  memcpy(tempChar, &buff[69], 5);
  tempChar[5] = '\0';
  temperature = strtol(tempChar, &pEnd, 10);
  return temperature / 1000;
}


x86 assembly (clang, -O0):
<temperature_DS18B20>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movq   $0x0,-0x28(%rbp)
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    0xe73(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    11d7 <temperature_DS18B20+0x67>
lea    0xe7f(%rip),%rdi
call   1050 <printf@plt>
movsd  0xe3b(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1271 <temperature_DS18B20+0x101>
lea    -0x430(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4a,%edx
call   1030 <fread@plt>
mov    %eax,%ecx
mov    $0x4a,%eax
cmp    %ecx,%eax
je     121e <temperature_DS18B20+0xae>
lea    0xe4c(%rip),%rdi
call   1050 <printf@plt>
movsd  0xdf4(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1271 <temperature_DS18B20+0x101>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0xe(%rbp),%rdi
lea    -0x430(%rbp),%rsi
add    $0x45,%rsi
mov    $0x5,%edx
call   1080 <memcpy@plt>
movb   $0x0,-0x9(%rbp)
lea    -0xe(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xd98(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<temperature_DS18B20>:
push   %rbx
sub    $0x410,%rsp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    0xe80(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1200 <temperature_DS18B20+0x90>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4a,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
cmp    $0x4a,%eax
jne    1209 <temperature_DS18B20+0x99>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0x55(%rsp),%rsi
lea    0x2(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x5,%edx
call   1080 <memcpy@plt>
movb   $0x0,0x7(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1070 <strtol@plt>
divsd  0xe0a(%rip),%xmm0
jmp    121d <temperature_DS18B20+0xad>
lea    0xe49(%rip),%rdi
jmp    1210 <temperature_DS18B20+0xa0>
lea    0xe2f(%rip),%rdi
call   1030 <puts@plt>
movsd  0xde3(%rip),%xmm0
add    $0x410,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [45 x i8] c"/sys/bus/w1/devices/28-041591dd2cff/w1_slave\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"\0A fopen() Error!!!\0A\00"
@.str.3 = [18 x i8] c"\0A fread() failed\0A\00"
define double @temperature_DS18B20() {
%1 = alloca double
%2 = alloca [6 x i8]
%3 = alloca double
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [1024 x i8]
store i32* null, i32** %5
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 1024)
%9 = call i32* @fopen(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp eq i32* null, %10
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store double 1.000000e+00, double* %1
br label %32
14: ; preds = %0
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = load i32*, i32** %5
%17 = call i32 @fread(i8* %15, i32 1, i32 74, i32* %16)
%18 = icmp ne i32 74, %17
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
store double 1.000000e+00, double* %1
br label %32
21: ; preds = %14
%22 = load i32*, i32** %5
%23 = call i32 @fclose(i32* %22)
%24 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 69
%26 = call i32 @memcpy(i8* %24, i8* %25, i32 5)
%27 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 5
store i8 0, i8* %27
%28 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%29 = call double @strtol(i8* %28, i8** %4, i32 10)
store double %29, double* %3
%30 = load double, double* %3
%31 = fdiv double %30, 1.000000e+03
store double %31, double* %1
br label %32
32: ; preds = %21, %19, %12
%33 = load double, double* %1
ret double %33
}

LLVM IR (-O2):
@.str = [45 x i8] c"/sys/bus/w1/devices/28-041591dd2cff/w1_slave\00"
@.str.1 = [2 x i8] c"r\00"
@str = [17 x i8] c"\0A fread() failed\00"
@str.4 = [19 x i8] c"\0A fopen() Error!!!\00"
define double @temperature_DS18B20() {
%1 = alloca [6 x i8]
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%5 = bitcast i8** %2 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 1024)
%8 = call i32* @fopen(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.4, i64 0, i64 0))
br label %24
12: ; preds = %0
%13 = call i32 @fread(i8* %6, i32 1, i32 74, i32* %8)
%14 = icmp eq i32 %13, 74
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %24
17: ; preds = %12
%18 = call i32 @fclose(i32* %8)
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 69
%20 = call i32 @memcpy(i8* %4, i8* %19, i32 5)
%21 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 5
store i8 0, i8* %21
%22 = call double @strtol(i8* %4, i8** %2, i32 10)
%23 = fdiv double %22, 1.000000e+03
br label %24
24: ; preds = %17, %15, %10
%25 = phi double [ 1.000000e+00, %10 ], [ 1.000000e+00, %15 ], [ %23, %17 ]
ret double %25
}