#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*/ EPROTO;
double NAN;
scalar_t__ asprintf(char **, char *, char const *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ stderr;
double w1_therm_get(const char *addr) {
  char *path = NULL;
  FILE *f = NULL;
  double val, ret = NAN;
  int crc;
  if (asprintf(&path, "/sys/bus/w1/devices/%s/w1_slave", addr) < 0) {
    fprintf(stderr, "Out of memory\n");
    exit(1);
  }
  if (!(f = fopen(path, "r")))
    goto done;
  if (fscanf(f, "%*x %*x %*x %*x %*x %*x %*x %*x %*x : crc=%x YES", &crc) !=
      1) {
    errno = EPROTO;
    goto done;
  }
  if (fscanf(f, "%*x %*x %*x %*x %*x %*x %*x %*x %*x t=%lf", &val) != 1 ||
      val == 85000) {
    errno = EPROTO;
    goto done;
  }
  ret = val / 1000;
done:
  if (f)
    fclose(f);
  if (path)
    free(path);
  return ret;
}


x86 assembly (clang, -O0):
<w1_therm_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e65(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1070 <asprintf@plt>
cmp    $0x0,%rax
jge    11d9 <w1_therm_get+0x69>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11fc <w1_therm_get+0x8c>
jmp    129b <w1_therm_get+0x12b>
mov    -0x18(%rbp),%rdi
lea    0xe3a(%rip),%rsi
lea    -0x2c(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
cmp    $0x1,%eax
je     1232 <w1_therm_get+0xc2>
mov    0x2db6(%rip),%rax
mov    (%rax),%ecx
mov    0x2d9d(%rip),%rax
mov    %ecx,(%rax)
jmp    129b <w1_therm_get+0x12b>
mov    -0x18(%rbp),%rdi
lea    0xe35(%rip),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    126e <w1_therm_get+0xfe>
movsd  -0x20(%rbp),%xmm0
movsd  0xda2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1285 <w1_therm_get+0x115>
jp     1285 <w1_therm_get+0x115>
mov    0x2d63(%rip),%rax
mov    (%rax),%ecx
mov    0x2d4a(%rip),%rax
mov    %ecx,(%rax)
jmp    129b <w1_therm_get+0x12b>
movsd  -0x20(%rbp),%xmm0
movsd  0xd76(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12af <w1_therm_get+0x13f>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x10(%rbp)
je     12c3 <w1_therm_get+0x153>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<w1_therm_get>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rdx
movq   $0x0,(%rsp)
mov    0x2e71(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xe78(%rip),%rsi
mov    %rsp,%rdi
call   1070 <asprintf@plt>
test   %rax,%rax
js     124d <w1_therm_get+0xdd>
mov    (%rsp),%rdi
lea    0xe8b(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1233 <w1_therm_get+0xc3>
mov    %rax,%rbx
lea    0xe79(%rip),%rsi
lea    0x1c(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    1219 <w1_therm_get+0xa9>
lea    0xe8f(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    1219 <w1_therm_get+0xa9>
movsd  0x10(%rsp),%xmm0
ucomisd 0xdfb(%rip),%xmm0
jne    1209 <w1_therm_get+0x99>
jnp    1219 <w1_therm_get+0xa9>
divsd  0xdf7(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
jmp    122b <w1_therm_get+0xbb>
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
mov    0x2d9f(%rip),%rcx
mov    %eax,(%rcx)
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     1241 <w1_therm_get+0xd1>
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
ret
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
lea    0xdd3(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@NAN = global double 0.000000e+00
@.str = [32 x i8] c"/sys/bus/w1/devices/%s/w1_slave\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"Out of memory\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [49 x i8] c"%*x %*x %*x %*x %*x %*x %*x %*x %*x : crc=%x YES\00"
@EPROTO = global i32 0
@errno = global i32 0
@.str.4 = [42 x i8] c"%*x %*x %*x %*x %*x %*x %*x %*x %*x t=%lf\00"
define double @w1_therm_get(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store i8* %0, i8** %2
store i8* null, i8** %3
store i32* null, i32** %4
%8 = load double, double* @NAN
store double %8, double* %6
%9 = load i8*, i8** %2
%10 = call i64 @asprintf(i8** %3, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %4
%19 = icmp ne i32* %18, null
br i1 %19, label %21, label %20
20: ; preds = %16
br label %39
21: ; preds = %16
%22 = load i32*, i32** %4
%23 = call i32 (i32*, i8*, ...) @fscanf(i32* %22, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%24 = icmp ne i32 %23, 1
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = load i32, i32* @EPROTO
store i32 %26, i32* @errno
br label %39
27: ; preds = %21
%28 = load i32*, i32** %4
%29 = call i32 (i32*, i8*, ...) @fscanf(i32* %28, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), double* %5)
%30 = icmp ne i32 %29, 1
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = load double, double* %5
%33 = fcmp oeq double %32, 8.500000e+04
br i1 %33, label %34, label %36
34: ; preds = %31, %27
%35 = load i32, i32* @EPROTO
store i32 %35, i32* @errno
br label %39
36: ; preds = %31
%37 = load double, double* %5
%38 = fdiv double %37, 1.000000e+03
store double %38, double* %6
br label %39
39: ; preds = %36, %34, %25, %20
%40 = load i32*, i32** %4
%41 = icmp ne i32* %40, null
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32*, i32** %4
%44 = call i32 @fclose(i32* %43)
br label %45
45: ; preds = %42, %39
%46 = load i8*, i8** %3
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i8*, i8** %3
%50 = call i32 @free(i8* %49)
br label %51
51: ; preds = %48, %45
%52 = load double, double* %6
ret double %52
}

LLVM IR (-O2):
@NAN = global double 0.000000e+00
@.str = [32 x i8] c"/sys/bus/w1/devices/%s/w1_slave\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"Out of memory\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [49 x i8] c"%*x %*x %*x %*x %*x %*x %*x %*x %*x : crc=%x YES\00"
@EPROTO = global i32 0
@errno = global i32 0
@.str.4 = [42 x i8] c"%*x %*x %*x %*x %*x %*x %*x %*x %*x t=%lf\00"
define double @w1_therm_get(i8* %0) {
%2 = alloca i8*
%3 = alloca double
%4 = alloca i32
%5 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%6 = bitcast double* %3 to i8*
%7 = load double, double* @NAN
%8 = bitcast i32* %4 to i8*
%9 = call i64 @asprintf(i8** %2, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %37, label %19
19: ; preds = %15
%20 = call i32 (i32*, i8*, ...) @fscanf(i32* %17, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%21 = icmp eq i32 %20, 1
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = load i32, i32* @EPROTO
store i32 %23, i32* @errno
br label %34
24: ; preds = %19
%25 = call i32 (i32*, i8*, ...) @fscanf(i32* %17, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), double* %3)
%26 = icmp ne i32 %25, 1
%27 = load double, double* %3
%28 = fcmp oeq double %27, 8.500000e+04
%29 = select i1 %26, i1 true, i1 %28
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = load i32, i32* @EPROTO
store i32 %31, i32* @errno
br label %34
32: ; preds = %24
%33 = fdiv double %27, 1.000000e+03
br label %34
34: ; preds = %32, %30, %22
%35 = phi double [ %33, %32 ], [ %7, %30 ], [ %7, %22 ]
%36 = call i32 @fclose(i32* %17)
br label %37
37: ; preds = %15, %34
%38 = phi double [ %35, %34 ], [ %7, %15 ]
%39 = load i8*, i8** %2
%40 = icmp eq i8* %39, null
br i1 %40, label %43, label %41
41: ; preds = %37
%42 = call i32 @free(i8* %39)
br label %43
43: ; preds = %41, %37
ret double %38
}