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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, unsigned char, ...);
void thermostat_setpoint_dump(void *data, void *payload, int len) {
  unsigned char *pp = (unsigned char *)payload;
  int size, scale, precision, i;
  double val;
  if (pp[0] != 0x03) {
    printf("Impossible command %x\n", pp[0]);
    return;
  }
  size = pp[2] & 7;
  scale = (pp[2] >> 3) & 3;
  precision = (pp[2] >> 5) & 3;
  val = 0;
  for (i = 0; i < size; i++)
    val = val * 256 + pp[3 + i];
  for (i = 0; i < precision; i++)
    val = val / 10;
  printf("type %d value %g\n", pp[1], val);
}


x86 assembly (clang, -O0):
<thermostat_setpoint_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x3,%eax
je     1155 <thermostat_setpoint_dump+0x45>
mov    -0x20(%rbp),%rax
lea    0xeca(%rip),%rdi
movzbl (%rax),%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1231 <thermostat_setpoint_dump+0x121>
mov    -0x20(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0x7,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
movzbl 0x2(%rax),%eax
sar    $0x3,%eax
and    $0x3,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movzbl 0x2(%rax),%eax
sar    $0x5,%eax
and    $0x3,%eax
mov    %eax,-0x2c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11dd <thermostat_setpoint_dump+0xcd>
movsd  -0x38(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
cvtsi2sd %eax,%xmm1
movsd  0xe46(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1194 <thermostat_setpoint_dump+0x84>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1214 <thermostat_setpoint_dump+0x104>
movsd  -0x38(%rbp),%xmm0
movsd  0xe03(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11e4 <thermostat_setpoint_dump+0xd4>
mov    -0x20(%rbp),%rax
mov    0x1(%rax),%al
movsd  -0x38(%rbp),%xmm0
lea    0xe00(%rip),%rdi
movzbl %al,%esi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thermostat_setpoint_dump>:
mov    (%rsi),%al
cmp    $0x3,%al
jne    11ea <thermostat_setpoint_dump+0xda>
movzbl 0x2(%rsi),%ecx
mov    %ecx,%eax
shr    $0x5,%eax
and    $0x3,%eax
and    $0x7,%ecx
je     11fb <thermostat_setpoint_dump+0xeb>
movzbl 0x3(%rsi),%edx
cvtsi2sd %edx,%xmm0
cmp    $0x1,%ecx
je     11ff <thermostat_setpoint_dump+0xef>
movzbl 0x4(%rsi),%edx
cvtsi2sd %edx,%xmm1
mulsd  0xeb0(%rip),%xmm0
addsd  %xmm1,%xmm0
cmp    $0x2,%ecx
je     11ff <thermostat_setpoint_dump+0xef>
movzbl 0x5(%rsi),%edx
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
mulsd  0xe90(%rip),%xmm0
addsd  %xmm1,%xmm0
cmp    $0x3,%ecx
je     11ff <thermostat_setpoint_dump+0xef>
movzbl 0x6(%rsi),%edx
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
mulsd  0xe70(%rip),%xmm0
addsd  %xmm1,%xmm0
cmp    $0x4,%ecx
je     11ff <thermostat_setpoint_dump+0xef>
movzbl 0x7(%rsi),%edx
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
mulsd  0xe54(%rip),%xmm0
addsd  %xmm1,%xmm0
cmp    $0x5,%ecx
je     11ff <thermostat_setpoint_dump+0xef>
movzbl 0x8(%rsi),%edx
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
mulsd  0xe38(%rip),%xmm0
addsd  %xmm1,%xmm0
cmp    $0x6,%ecx
je     11ff <thermostat_setpoint_dump+0xef>
movzbl 0x9(%rsi),%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
mulsd  0xe1c(%rip),%xmm0
addsd  %xmm1,%xmm0
jmp    11ff <thermostat_setpoint_dump+0xef>
movzbl %al,%esi
lea    0xe1c(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
xorpd  %xmm0,%xmm0
test   %eax,%eax
je     1225 <thermostat_setpoint_dump+0x115>
divsd  0xdfd(%rip),%xmm0
cmp    $0x1,%eax
je     1225 <thermostat_setpoint_dump+0x115>
divsd  0xdf0(%rip),%xmm0
cmp    $0x2,%eax
je     1225 <thermostat_setpoint_dump+0x115>
divsd  0xde3(%rip),%xmm0
movzbl 0x1(%rsi),%esi
lea    0xdf7(%rip),%rdi
mov    $0x1,%al
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Impossible command %x\0A\00"
@.str.1 = [18 x i8] c"type %d value %g\0A\00"
define void @thermostat_setpoint_dump(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%13 = load i8*, i8** %5
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = icmp ne i32 %17, 3
br i1 %18, label %19, label %24
19: ; preds = %3
%20 = load i8*, i8** %7
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8 zeroext %22)
br label %77
24: ; preds = %3
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i64 2
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = and i32 %28, 7
store i32 %29, i32* %8
%30 = load i8*, i8** %7
%31 = getelementptr inbounds i8, i8* %30, i64 2
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = ashr i32 %33, 3
%35 = and i32 %34, 3
store i32 %35, i32* %9
%36 = load i8*, i8** %7
%37 = getelementptr inbounds i8, i8* %36, i64 2
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = ashr i32 %39, 5
%41 = and i32 %40, 3
store i32 %41, i32* %10
store double 0.000000e+00, double* %12
store i32 0, i32* %11
br label %42
42: ; preds = %57, %24
%43 = load i32, i32* %11
%44 = load i32, i32* %8
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %60
46: ; preds = %42
%47 = load double, double* %12
%48 = load i8*, i8** %7
%49 = load i32, i32* %11
%50 = add nsw i32 3, %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = sitofp i32 %54 to double
%56 = call double @llvm.fmuladd.f64(double %47, double 2.560000e+02, double %55)
store double %56, double* %12
br label %57
57: ; preds = %46
%58 = load i32, i32* %11
%59 = add nsw i32 %58, 1
store i32 %59, i32* %11
br label %42
60: ; preds = %42
store i32 0, i32* %11
br label %61
61: ; preds = %68, %60
%62 = load i32, i32* %11
%63 = load i32, i32* %10
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %71
65: ; preds = %61
%66 = load double, double* %12
%67 = fdiv double %66, 1.000000e+01
store double %67, double* %12
br label %68
68: ; preds = %65
%69 = load i32, i32* %11
%70 = add nsw i32 %69, 1
store i32 %70, i32* %11
br label %61
71: ; preds = %61
%72 = load i8*, i8** %7
%73 = getelementptr inbounds i8, i8* %72, i64 1
%74 = load i8, i8* %73
%75 = load double, double* %12
%76 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %74, double %75)
br label %77
77: ; preds = %71, %19
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"Impossible command %x\0A\00"
@.str.1 = [18 x i8] c"type %d value %g\0A\00"
define void @thermostat_setpoint_dump(i8* nocapture readnone %0, i8* nocapture %1, i32 %2) {
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 3
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8 zeroext %4)
br label %72
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %1, i64 2
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = and i32 %11, 7
%13 = lshr i32 %11, 5
%14 = and i32 %13, 3
%15 = icmp eq i32 %12, 0
br i1 %15, label %16, label %19
16: ; preds = %19, %24, %30, %36, %42, %48, %54, %8
%17 = phi double [ 0.000000e+00, %8 ], [ %22, %19 ], [ %28, %24 ], [ %34, %30 ], [ %40, %36 ], [ %46, %42 ], [ %52, %48 ], [ %58, %54 ]
%18 = icmp eq i32 %14, 0
br i1 %18, label %67, label %59
19: ; preds = %8
%20 = getelementptr inbounds i8, i8* %1, i64 3
%21 = load i8, i8* %20
%22 = uitofp i8 %21 to double
%23 = icmp eq i32 %12, 1
br i1 %23, label %16, label %24
24: ; preds = %19
%25 = getelementptr inbounds i8, i8* %1, i64 4
%26 = load i8, i8* %25
%27 = uitofp i8 %26 to double
%28 = tail call double @llvm.fmuladd.f64(double %22, double 2.560000e+02, double %27)
%29 = icmp eq i32 %12, 2
br i1 %29, label %16, label %30
30: ; preds = %24
%31 = getelementptr inbounds i8, i8* %1, i64 5
%32 = load i8, i8* %31
%33 = uitofp i8 %32 to double
%34 = tail call double @llvm.fmuladd.f64(double %28, double 2.560000e+02, double %33)
%35 = icmp eq i32 %12, 3
br i1 %35, label %16, label %36
36: ; preds = %30
%37 = getelementptr inbounds i8, i8* %1, i64 6
%38 = load i8, i8* %37
%39 = uitofp i8 %38 to double
%40 = tail call double @llvm.fmuladd.f64(double %34, double 2.560000e+02, double %39)
%41 = icmp eq i32 %12, 4
br i1 %41, label %16, label %42
42: ; preds = %36
%43 = getelementptr inbounds i8, i8* %1, i64 7
%44 = load i8, i8* %43
%45 = uitofp i8 %44 to double
%46 = tail call double @llvm.fmuladd.f64(double %40, double 2.560000e+02, double %45)
%47 = icmp eq i32 %12, 5
br i1 %47, label %16, label %48
48: ; preds = %42
%49 = getelementptr inbounds i8, i8* %1, i64 8
%50 = load i8, i8* %49
%51 = uitofp i8 %50 to double
%52 = tail call double @llvm.fmuladd.f64(double %46, double 2.560000e+02, double %51)
%53 = icmp eq i32 %12, 6
br i1 %53, label %16, label %54
54: ; preds = %48
%55 = getelementptr inbounds i8, i8* %1, i64 9
%56 = load i8, i8* %55
%57 = uitofp i8 %56 to double
%58 = tail call double @llvm.fmuladd.f64(double %52, double 2.560000e+02, double %57)
br label %16
59: ; preds = %16
%60 = fdiv double %17, 1.000000e+01
%61 = icmp eq i32 %14, 1
br i1 %61, label %67, label %62
62: ; preds = %59
%63 = fdiv double %60, 1.000000e+01
%64 = icmp eq i32 %14, 2
br i1 %64, label %67, label %65
65: ; preds = %62
%66 = fdiv double %63, 1.000000e+01
br label %67
67: ; preds = %59, %62, %65, %16
%68 = phi double [ %17, %16 ], [ %60, %59 ], [ %63, %62 ], [ %66, %65 ]
%69 = getelementptr inbounds i8, i8* %1, i64 1
%70 = load i8, i8* %69
%71 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %70, double %68)
br label %72
72: ; preds = %67, %6
ret void
}