#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*/ tempBuf;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ O_RDONLY;
scalar_t__ atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, float);
int read(int, char *, int);
int main(void) {
  float temp;
  int i, j;
  int fd;
  int ret;
  char buf[128];
  char tempBuf[5];
  fd = open("/sys/bus/w1/devices/28-00000495db35/w1_slave", O_RDONLY);
  if (-1 == fd) {
    perror("open device file error");
    return 1;
  }
  while (1) {
    ret = read(fd, buf, 128);
    if (0 == ret) {
      break;
    }
    if (-1 == ret) {
      if (errno == EINTR) {
        continue;
      }
      perror("read()");
      close(fd);
      return 1;
    }
  }
  for (i = 0; i < sizeof(buf); i++) {
    if (buf[i] == 't') {
      for (j = 0; j < sizeof(tempBuf); j++) {
        tempBuf[j] = buf[i + 2 + j];
      }
    }
  }
  temp = (float)atoi(tempBuf) / 1000;
  printf("%.3f C\n", temp);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
lea    0xe82(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    11b0 <main+0x50>
lea    0xe92(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f4 <main+0x194>
jmp    11b5 <main+0x55>
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
jne    11dc <main+0x7c>
jmp    122e <main+0xce>
mov    $0xffffffff,%eax
cmp    -0x18(%rbp),%eax
jne    1229 <main+0xc9>
mov    0x2de7(%rip),%rax
mov    (%rax),%rax
mov    0x2dd5(%rip),%rcx
cmp    (%rcx),%rax
jne    1209 <main+0xa9>
jmp    11b5 <main+0x55>
lea    0xe38(%rip),%rdi
call   1070 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f4 <main+0x194>
jmp    11b5 <main+0x55>
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x80,%rax
jae    12b2 <main+0x152>
movslq -0xc(%rbp),%rax
movsbl -0xa0(%rbp,%rax,1),%eax
ff
cmp    $0x74,%eax
jne    129f <main+0x13f>
movl   $0x0,-0x10(%rbp)
movslq -0x10(%rbp),%rax
cmp    $0x5,%rax
jae    129a <main+0x13a>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
add    -0x10(%rbp),%eax
cltq
mov    -0xa0(%rbp,%rax,1),%cl
movslq -0x10(%rbp),%rax
mov    %cl,-0xa5(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1261 <main+0x101>
jmp    129f <main+0x13f>
jmp    12a4 <main+0x144>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1235 <main+0xd5>
lea    -0xa5(%rbp),%rdi
call   1080 <atoi@plt>
cvtsi2ss %rax,%xmm0
movss  0xd35(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
lea    0xd6f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1258 <main+0xf8>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
mov    0x2e3f(%rip),%r14
mov    0x2e30(%rip),%r15
jmp    11bc <main+0x5c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14),%rax
cmp    (%r15),%rax
jne    1266 <main+0x106>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     11b0 <main+0x50>
test   %eax,%eax
jne    11bc <main+0x5c>
lea    0x13(%rsp),%rax
xor    %ecx,%ecx
jmp    11ed <main+0x8d>
nopl   (%rax)
add    $0x2,%rcx
cmp    $0x80,%rcx
je     121e <main+0xbe>
cmpb   $0x74,0x10(%rsp,%rcx,1)
jne    1205 <main+0xa5>
movzbl 0x3(%rax,%rcx,1),%edx
mov    %dl,0xc(%rsp)
mov    -0x1(%rax,%rcx,1),%edx
mov    %edx,0x8(%rsp)
cmpb   $0x74,0x11(%rsp,%rcx,1)
jne    11e0 <main+0x80>
movzbl 0x4(%rax,%rcx,1),%edx
mov    %dl,0xc(%rsp)
mov    (%rax,%rcx,1),%edx
mov    %edx,0x8(%rsp)
jmp    11e0 <main+0x80>
lea    0x8(%rsp),%rdi
call   1080 <atoi@plt>
cvtsi2ss %rax,%xmm0
divss  0xdcb(%rip),%xmm0
lea    0xe13(%rip),%rdi
call   1030 <printf@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd2(%rip),%rdi
call   1070 <perror@plt>
jmp    1279 <main+0x119>
lea    0xddb(%rip),%rdi
call   1070 <perror@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    $0x1,%eax
jmp    124a <main+0xea>

LLVM IR (-O0):
@.str = [45 x i8] c"/sys/bus/w1/devices/28-00000495db35/w1_slave\00"
@O_RDONLY = global i32 0
@.str.1 = [23 x i8] c"open device file error\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.2 = [7 x i8] c"read()\00"
@.str.3 = [8 x i8] c"%.3f C\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [128 x i8]
%8 = alloca [5 x i8]
store i32 0, i32* %1
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp eq i32 -1, %11
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %81
15: ; preds = %0
br label %16
16: ; preds = %15, %30, %35
%17 = load i32, i32* %5
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%19 = call i32 @read(i32 %17, i8* %18, i32 128)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp eq i32 0, %20
br i1 %21, label %22, label %23
22: ; preds = %16
br label %36
23: ; preds = %16
%24 = load i32, i32* %6
%25 = icmp eq i32 -1, %24
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i64, i64* @errno
%28 = load i64, i64* @EINTR
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %26
br label %16
31: ; preds = %26
%32 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* %5
%34 = call i32 @close(i32 %33)
store i32 1, i32* %1
br label %81
35: ; preds = %23
br label %16
36: ; preds = %22
store i32 0, i32* %3
br label %37
37: ; preds = %69, %36
%38 = load i32, i32* %3
%39 = sext i32 %38 to i64
%40 = icmp ult i64 %39, 128
br i1 %40, label %41, label %72
41: ; preds = %37
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 116
br i1 %47, label %48, label %68
48: ; preds = %41
store i32 0, i32* %4
br label %49
49: ; preds = %64, %48
%50 = load i32, i32* %4
%51 = sext i32 %50 to i64
%52 = icmp ult i64 %51, 5
br i1 %52, label %53, label %67
53: ; preds = %49
%54 = load i32, i32* %3
%55 = add nsw i32 %54, 2
%56 = load i32, i32* %4
%57 = add nsw i32 %55, %56
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = load i32, i32* %4
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 %62
store i8 %60, i8* %63
br label %64
64: ; preds = %53
%65 = load i32, i32* %4
%66 = add nsw i32 %65, 1
store i32 %66, i32* %4
br label %49
67: ; preds = %49
br label %68
68: ; preds = %67, %41
br label %69
69: ; preds = %68
%70 = load i32, i32* %3
%71 = add nsw i32 %70, 1
store i32 %71, i32* %3
br label %37
72: ; preds = %37
%73 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%74 = call i64 @atoi(i8* %73)
%75 = sitofp i64 %74 to float
%76 = fdiv float %75, 1.000000e+03
store float %76, float* %2
%77 = load float, float* %2
%78 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), float %77)
%79 = load i32, i32* %5
%80 = call i32 @close(i32 %79)
store i32 0, i32* %1
br label %81
81: ; preds = %72, %31, %13
%82 = load i32, i32* %1
ret i32 %82
}

LLVM IR (-O2):
@.str = [45 x i8] c"/sys/bus/w1/devices/28-00000495db35/w1_slave\00"
@O_RDONLY = global i32 0
@.str.1 = [23 x i8] c"open device file error\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.2 = [7 x i8] c"read()\00"
@.str.3 = [8 x i8] c"%.3f C\0A\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = alloca [5 x i8]
%3 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %46
11: ; preds = %0, %17
%12 = call i32 @read(i32 %7, i8* %4, i32 128)
switch i32 %12, label %17 [
i32 0, label %21
i32 -1, label %13
]
13: ; preds = %11
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %13, %11
br label %11
18: ; preds = %13
%19 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @close(i32 %7)
br label %46
21: ; preds = %11, %37
%22 = phi i64 [ %38, %37 ], [ 0, %11 ]
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 116
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = add nuw nsw i64 %22, 2
%28 = getelementptr [128 x i8], [128 x i8]* %1, i64 0, i64 %27
br label %29
29: ; preds = %26, %21
%30 = or i64 %22, 1
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 116
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = add nuw i64 %22, 3
%36 = getelementptr [128 x i8], [128 x i8]* %1, i64 0, i64 %35
br label %37
37: ; preds = %34, %29
%38 = add nuw nsw i64 %22, 2
%39 = icmp eq i64 %38, 128
br i1 %39, label %40, label %21
40: ; preds = %37
%41 = call i64 @atoi(i8* %5)
%42 = sitofp i64 %41 to float
%43 = fdiv float %42, 1.000000e+03
%44 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), float %43)
%45 = tail call i32 @close(i32 %7)
br label %46
46: ; preds = %40, %18, %9
%47 = phi i32 [ 1, %9 ], [ 0, %40 ], [ 1, %18 ]
ret i32 %47
}