#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*/ BYTE;

/* Variables and functions */
unsigned char CHECKSUM(unsigned char *, int);
unsigned char TouchByte(int);
int /*<<< orphan*/ TouchReset();
int /*<<< orphan*/ delay(int);
int /*<<< orphan*/ global_temp_sample();
float read_temp_sensor(unsigned char *serialnumber) {
  int serialnumber_loop;
  unsigned char BYTE[8], CRC;
  signed char degree;
  float degree_fraction, sensor_temp_reading;
  TouchReset();
  TouchByte(0x55);
  for (serialnumber_loop = 7; serialnumber_loop >= 0; serialnumber_loop--) {
    TouchByte(serialnumber[serialnumber_loop]);
  }
  TouchByte(0xBE);
  BYTE[0] = TouchByte(0xFF);
  BYTE[1] = TouchByte(0xFF);
  BYTE[2] = TouchByte(0xFF);
  BYTE[3] = TouchByte(0xFF);
  BYTE[4] = TouchByte(0xFF);
  BYTE[5] = TouchByte(0xFF);
  BYTE[6] = TouchByte(0xFF);
  BYTE[7] = TouchByte(0xFF);
  CRC = TouchByte(0xFF);
  TouchReset();
  degree = BYTE[0] >> 1;
  if (BYTE[1] != 0) {
    degree = degree | 0x80;
  }
  if (BYTE[7] != 0) {
    degree_fraction = ((float)(BYTE[7] - BYTE[6])) / ((float)BYTE[7]);
  } else {
    degree_fraction = 0.25;
  }
  sensor_temp_reading = ((float)degree) - 0.25 + degree_fraction;
  if (CRC != CHECKSUM(BYTE, sizeof(BYTE))) {
    global_temp_sample();
    delay(600);
    sensor_temp_reading = read_temp_sensor(serialnumber);
  }
  return (sensor_temp_reading);
}


x86 assembly (clang, -O0):
<read_temp_sensor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1080 <TouchReset@plt>
mov    $0x55,%edi
call   1070 <TouchByte@plt>
movl   $0x7,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11ad <read_temp_sensor+0x4d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1070 <TouchByte@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1184 <read_temp_sensor+0x24>
mov    $0xbe,%edi
call   1070 <TouchByte@plt>
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %al,-0x14(%rbp)
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %al,-0x13(%rbp)
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %al,-0x12(%rbp)
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %al,-0x11(%rbp)
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %al,-0x10(%rbp)
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %al,-0xf(%rbp)
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %al,-0xe(%rbp)
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %al,-0xd(%rbp)
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %al,-0x15(%rbp)
mov    $0x0,%al
call   1080 <TouchReset@plt>
movzbl -0x14(%rbp),%eax
sar    $0x1,%eax
mov    %al,-0x16(%rbp)
movzbl -0x13(%rbp),%eax
cmp    $0x0,%eax
je     1256 <read_temp_sensor+0xf6>
movsbl -0x16(%rbp),%eax
or     $0x80,%eax
mov    %al,-0x16(%rbp)
movzbl -0xd(%rbp),%eax
cmp    $0x0,%eax
je     1285 <read_temp_sensor+0x125>
movzbl -0xd(%rbp),%eax
movzbl -0xe(%rbp),%edx
mov    %eax,%ecx
sub    %edx,%ecx
cvtsi2ss %ecx,%xmm0
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    1292 <read_temp_sensor+0x132>
movss  0xd73(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
movsbl -0x16(%rbp),%eax
cvtsi2ss %eax,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd62(%rip),%xmm1
subsd  %xmm1,%xmm0
movss  -0x1c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movzbl -0x15(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x14(%rbp),%rdi
mov    $0x8,%esi
call   1030 <CHECKSUM@plt>
mov    %al,%cl
mov    -0x24(%rbp),%eax
movzbl %cl,%ecx
cmp    %ecx,%eax
je     1304 <read_temp_sensor+0x1a4>
mov    $0x0,%al
call   1060 <global_temp_sample@plt>
mov    $0x258,%edi
call   1050 <delay@plt>
mov    -0x8(%rbp),%rdi
call   1040 <read_temp_sensor@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_temp_sensor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   1080 <TouchReset@plt>
mov    $0x55,%edi
call   1070 <TouchByte@plt>
movzbl 0x7(%r14),%edi
call   1070 <TouchByte@plt>
movzbl 0x6(%r14),%edi
call   1070 <TouchByte@plt>
movzbl 0x5(%r14),%edi
call   1070 <TouchByte@plt>
movzbl 0x4(%r14),%edi
call   1070 <TouchByte@plt>
movzbl 0x3(%r14),%edi
call   1070 <TouchByte@plt>
movzbl 0x2(%r14),%edi
call   1070 <TouchByte@plt>
movzbl 0x1(%r14),%edi
call   1070 <TouchByte@plt>
movzbl (%r14),%edi
call   1070 <TouchByte@plt>
mov    $0xbe,%edi
call   1070 <TouchByte@plt>
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %eax,%ebp
mov    %al,0x8(%rsp)
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %eax,%r13d
mov    %al,0x9(%rsp)
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %al,0xa(%rsp)
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %al,0xb(%rsp)
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %al,0xc(%rsp)
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %al,0xd(%rsp)
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %eax,%r12d
mov    %al,0xe(%rsp)
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %eax,%ebx
mov    %al,0xf(%rsp)
mov    $0xff,%edi
call   1070 <TouchByte@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1080 <TouchReset@plt>
shr    %bpl
lea    -0x80(%rbp),%eax
test   %r13b,%r13b
movzbl %bpl,%ecx
movzbl %al,%ebp
cmove  %ecx,%ebp
test   %bl,%bl
je     129e <read_temp_sensor+0x13e>
movzbl %bl,%eax
movzbl %r12b,%ecx
cvtsi2ss %eax,%xmm0
sub    %ecx,%eax
cvtsi2ss %eax,%xmm1
divss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
jmp    12a6 <read_temp_sensor+0x146>
movsd  0xd5a(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
call   1030 <CHECKSUM@plt>
cmp    %al,%r15b
jne    12df <read_temp_sensor+0x17f>
movsbl %bpl,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0xd35(%rip),%xmm0
addsd  0x10(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
jmp    12f8 <read_temp_sensor+0x198>
xor    %eax,%eax
call   1060 <global_temp_sample@plt>
mov    $0x258,%edi
call   1050 <delay@plt>
mov    %r14,%rdi
call   1040 <read_temp_sensor@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define float @read_temp_sensor(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [8 x i8]
%5 = alloca i8
%6 = alloca i8
%7 = alloca float
%8 = alloca float
store i8* %0, i8** %2
%9 = call i32 (...) @TouchReset()
%10 = call zeroext i8 @TouchByte(i32 85)
store i32 7, i32* %3
br label %11
11: ; preds = %22, %1
%12 = load i32, i32* %3
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %11
%15 = load i8*, i8** %2
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = call zeroext i8 @TouchByte(i32 %20)
br label %22
22: ; preds = %14
%23 = load i32, i32* %3
%24 = add nsw i32 %23, -1
store i32 %24, i32* %3
br label %11
25: ; preds = %11
%26 = call zeroext i8 @TouchByte(i32 190)
%27 = call zeroext i8 @TouchByte(i32 255)
%28 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
store i8 %27, i8* %28
%29 = call zeroext i8 @TouchByte(i32 255)
%30 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 1
store i8 %29, i8* %30
%31 = call zeroext i8 @TouchByte(i32 255)
%32 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 2
store i8 %31, i8* %32
%33 = call zeroext i8 @TouchByte(i32 255)
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 3
store i8 %33, i8* %34
%35 = call zeroext i8 @TouchByte(i32 255)
%36 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 4
store i8 %35, i8* %36
%37 = call zeroext i8 @TouchByte(i32 255)
%38 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 5
store i8 %37, i8* %38
%39 = call zeroext i8 @TouchByte(i32 255)
%40 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 6
store i8 %39, i8* %40
%41 = call zeroext i8 @TouchByte(i32 255)
%42 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 7
store i8 %41, i8* %42
%43 = call zeroext i8 @TouchByte(i32 255)
store i8 %43, i8* %5
%44 = call i32 (...) @TouchReset()
%45 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = ashr i32 %47, 1
%49 = trunc i32 %48 to i8
store i8 %49, i8* %6
%50 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 1
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %25
%55 = load i8, i8* %6
%56 = sext i8 %55 to i32
%57 = or i32 %56, 128
%58 = trunc i32 %57 to i8
store i8 %58, i8* %6
br label %59
59: ; preds = %54, %25
%60 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 7
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %77
64: ; preds = %59
%65 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 7
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 6
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = sub nsw i32 %67, %70
%72 = sitofp i32 %71 to float
%73 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 7
%74 = load i8, i8* %73
%75 = uitofp i8 %74 to float
%76 = fdiv float %72, %75
store float %76, float* %7
br label %78
77: ; preds = %59
store float 2.500000e-01, float* %7
br label %78
78: ; preds = %77, %64
%79 = load i8, i8* %6
%80 = sitofp i8 %79 to float
%81 = fpext float %80 to double
%82 = fsub double %81, 2.500000e-01
%83 = load float, float* %7
%84 = fpext float %83 to double
%85 = fadd double %82, %84
%86 = fptrunc double %85 to float
store float %86, float* %8
%87 = load i8, i8* %5
%88 = zext i8 %87 to i32
%89 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%90 = call zeroext i8 @CHECKSUM(i8* %89, i32 8)
%91 = zext i8 %90 to i32
%92 = icmp ne i32 %88, %91
br i1 %92, label %93, label %98
93: ; preds = %78
%94 = call i32 (...) @global_temp_sample()
%95 = call i32 @delay(i32 600)
%96 = load i8*, i8** %2
%97 = call float @read_temp_sensor(i8* %96)
store float %97, float* %8
br label %98
98: ; preds = %93, %78
%99 = load float, float* %8
ret float %99
}

LLVM IR (-O2):
define float @read_temp_sensor(i8* nocapture %0) {
%2 = alloca [8 x i8]
%3 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (...) @TouchReset()
%5 = tail call zeroext i8 @TouchByte(i32 85)
%6 = getelementptr inbounds i8, i8* %0, i64 7
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
%9 = tail call zeroext i8 @TouchByte(i32 %8)
%10 = getelementptr inbounds i8, i8* %0, i64 6
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = tail call zeroext i8 @TouchByte(i32 %12)
%14 = getelementptr inbounds i8, i8* %0, i64 5
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = tail call zeroext i8 @TouchByte(i32 %16)
%18 = getelementptr inbounds i8, i8* %0, i64 4
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = tail call zeroext i8 @TouchByte(i32 %20)
%22 = getelementptr inbounds i8, i8* %0, i64 3
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = tail call zeroext i8 @TouchByte(i32 %24)
%26 = getelementptr inbounds i8, i8* %0, i64 2
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = tail call zeroext i8 @TouchByte(i32 %28)
%30 = getelementptr inbounds i8, i8* %0, i64 1
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = tail call zeroext i8 @TouchByte(i32 %32)
%34 = load i8, i8* %0
%35 = zext i8 %34 to i32
%36 = tail call zeroext i8 @TouchByte(i32 %35)
%37 = tail call zeroext i8 @TouchByte(i32 190)
%38 = tail call zeroext i8 @TouchByte(i32 255)
store i8 %38, i8* %3
%39 = tail call zeroext i8 @TouchByte(i32 255)
%40 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 1
store i8 %39, i8* %40
%41 = tail call zeroext i8 @TouchByte(i32 255)
%42 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 2
store i8 %41, i8* %42
%43 = tail call zeroext i8 @TouchByte(i32 255)
%44 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 3
store i8 %43, i8* %44
%45 = tail call zeroext i8 @TouchByte(i32 255)
%46 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 4
store i8 %45, i8* %46
%47 = tail call zeroext i8 @TouchByte(i32 255)
%48 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 5
store i8 %47, i8* %48
%49 = tail call zeroext i8 @TouchByte(i32 255)
%50 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 6
store i8 %49, i8* %50
%51 = tail call zeroext i8 @TouchByte(i32 255)
%52 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 7
store i8 %51, i8* %52
%53 = tail call zeroext i8 @TouchByte(i32 255)
%54 = tail call i32 (...) @TouchReset()
%55 = lshr i8 %38, 1
%56 = icmp eq i8 %39, 0
%57 = or i8 %55, -128
%58 = select i1 %56, i8 %55, i8 %57
%59 = icmp eq i8 %51, 0
br i1 %59, label %68, label %60
60: ; preds = %1
%61 = zext i8 %51 to i32
%62 = zext i8 %49 to i32
%63 = sub nsw i32 %61, %62
%64 = sitofp i32 %63 to float
%65 = uitofp i8 %51 to float
%66 = fdiv float %64, %65
%67 = fpext float %66 to double
br label %68
68: ; preds = %1, %60
%69 = phi double [ %67, %60 ], [ 2.500000e-01, %1 ]
%70 = sitofp i8 %58 to double
%71 = fadd double %70, -2.500000e-01
%72 = fadd double %71, %69
%73 = fptrunc double %72 to float
%74 = call zeroext i8 @CHECKSUM(i8* %3, i32 8)
%75 = icmp eq i8 %53, %74
br i1 %75, label %80, label %76
76: ; preds = %68
%77 = call i32 (...) @global_temp_sample()
%78 = call i32 @delay(i32 600)
%79 = call float @read_temp_sensor(i8* %0)
br label %80
80: ; preds = %76, %68
%81 = phi float [ %79, %76 ], [ %73, %68 ]
ret float %81
}