#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*/ zwave_sendClassCommand(unsigned int, int, int,
                                          unsigned char *, int);
void zwavecmd_thermostat_setpoint(unsigned int id, int type, double value) {
  unsigned char buf[256];
  int v = value * 10;
  buf[0] = type;
  if (v < 127) {
    buf[1] = (1 << 5) | (1 << 3) | 1;
    buf[2] = v;
    zwave_sendClassCommand(id, 0x43, 0x01, buf, 3);
  } else if (v < 32768) {
    buf[1] = (1 << 5) | (1 << 3) | 2;
    buf[2] = v >> 8;
    buf[3] = v % 256;
    zwave_sendClassCommand(id, 0x43, 0x01, buf, 4);
  } else {
    buf[1] = (1 << 5) | (1 << 3) | 4;
    buf[2] = v >> 24;
    buf[3] = (v >> 16) % 256;
    buf[4] = (v >> 8) % 256;
    buf[5] = v % 256;
    zwave_sendClassCommand(id, 0x43, 0x01, buf, 6);
  }
}


x86 assembly (clang, -O0):
<zwavecmd_thermostat_setpoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  0xed2(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x114(%rbp)
mov    -0x8(%rbp),%eax
mov    %al,-0x110(%rbp)
cmpl   $0x7f,-0x114(%rbp)
jge    118a <zwavecmd_thermostat_setpoint+0x7a>
movb   $0x29,-0x10f(%rbp)
mov    -0x114(%rbp),%eax
mov    %al,-0x10e(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rcx
mov    $0x43,%esi
mov    $0x1,%edx
mov    $0x3,%r8d
call   1030 <zwave_sendClassCommand@plt>
jmp    126c <zwavecmd_thermostat_setpoint+0x15c>
cmpl   $0x8000,-0x114(%rbp)
jge    11ea <zwavecmd_thermostat_setpoint+0xda>
movb   $0x2a,-0x10f(%rbp)
mov    -0x114(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x10e(%rbp)
mov    -0x114(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x10d(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rcx
mov    $0x43,%esi
mov    $0x1,%edx
mov    $0x4,%r8d
call   1030 <zwave_sendClassCommand@plt>
jmp    1267 <zwavecmd_thermostat_setpoint+0x157>
movb   $0x2c,-0x10f(%rbp)
mov    -0x114(%rbp),%eax
sar    $0x18,%eax
mov    %al,-0x10e(%rbp)
mov    -0x114(%rbp),%eax
sar    $0x10,%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x10d(%rbp)
mov    -0x114(%rbp),%eax
sar    $0x8,%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x10c(%rbp)
mov    -0x114(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x10b(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rcx
mov    $0x43,%esi
mov    $0x1,%edx
mov    $0x6,%r8d
call   1030 <zwave_sendClassCommand@plt>
jmp    126c <zwavecmd_thermostat_setpoint+0x15c>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zwavecmd_thermostat_setpoint>:
sub    $0x108,%rsp
mulsd  0xee1(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    %sil,(%rsp)
cmp    $0x7e,%eax
jg     113d <zwavecmd_thermostat_setpoint+0x2d>
movb   $0x29,0x1(%rsp)
mov    %al,0x2(%rsp)
mov    $0x3,%r8d
jmp    117e <zwavecmd_thermostat_setpoint+0x6e>
cmp    $0x7fff,%eax
ja     1159 <zwavecmd_thermostat_setpoint+0x49>
movb   $0x2a,0x1(%rsp)
mov    %ah,0x2(%rsp)
mov    %al,0x3(%rsp)
mov    $0x4,%r8d
jmp    117e <zwavecmd_thermostat_setpoint+0x6e>
movb   $0x2c,0x1(%rsp)
mov    %eax,%ecx
shr    $0x18,%ecx
mov    %cl,0x2(%rsp)
mov    %eax,%ecx
shr    $0x10,%ecx
mov    %cl,0x3(%rsp)
mov    %ah,0x4(%rsp)
mov    %al,0x5(%rsp)
mov    $0x6,%r8d
mov    %rsp,%rcx
mov    $0x43,%esi
mov    $0x1,%edx
call   1030 <zwave_sendClassCommand@plt>
add    $0x108,%rsp
ret

LLVM IR (-O0):
define void @zwavecmd_thermostat_setpoint(i32 %0, i32 %1, double %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca [256 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store double %2, double* %6
%9 = load double, double* %6
%10 = fmul double %9, 1.000000e+01
%11 = fptosi double %10 to i32
store i32 %11, i32* %8
%12 = load i32, i32* %5
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
store i8 %13, i8* %14
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 127
br i1 %16, label %17, label %25
17: ; preds = %3
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 1
store i8 41, i8* %18
%19 = load i32, i32* %8
%20 = trunc i32 %19 to i8
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 2
store i8 %20, i8* %21
%22 = load i32, i32* %4
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%24 = call i32 @zwave_sendClassCommand(i32 %22, i32 67, i32 1, i8* %23, i32 3)
br label %65
25: ; preds = %3
%26 = load i32, i32* %8
%27 = icmp slt i32 %26, 32768
br i1 %27, label %28, label %41
28: ; preds = %25
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 1
store i8 42, i8* %29
%30 = load i32, i32* %8
%31 = ashr i32 %30, 8
%32 = trunc i32 %31 to i8
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 2
store i8 %32, i8* %33
%34 = load i32, i32* %8
%35 = srem i32 %34, 256
%36 = trunc i32 %35 to i8
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 3
store i8 %36, i8* %37
%38 = load i32, i32* %4
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%40 = call i32 @zwave_sendClassCommand(i32 %38, i32 67, i32 1, i8* %39, i32 4)
br label %64
41: ; preds = %25
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 1
store i8 44, i8* %42
%43 = load i32, i32* %8
%44 = ashr i32 %43, 24
%45 = trunc i32 %44 to i8
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 2
store i8 %45, i8* %46
%47 = load i32, i32* %8
%48 = ashr i32 %47, 16
%49 = srem i32 %48, 256
%50 = trunc i32 %49 to i8
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 3
store i8 %50, i8* %51
%52 = load i32, i32* %8
%53 = ashr i32 %52, 8
%54 = srem i32 %53, 256
%55 = trunc i32 %54 to i8
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 4
store i8 %55, i8* %56
%57 = load i32, i32* %8
%58 = srem i32 %57, 256
%59 = trunc i32 %58 to i8
%60 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 5
store i8 %59, i8* %60
%61 = load i32, i32* %4
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%63 = call i32 @zwave_sendClassCommand(i32 %61, i32 67, i32 1, i8* %62, i32 6)
br label %64
64: ; preds = %41, %28
br label %65
65: ; preds = %64, %17
ret void
}

LLVM IR (-O2):
define void @zwavecmd_thermostat_setpoint(i32 %0, i32 %1, double %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = fmul double %2, 1.000000e+01
%7 = fptosi double %6 to i32
%8 = trunc i32 %1 to i8
store i8 %8, i8* %5
%9 = icmp slt i32 %7, 127
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 1
store i8 41, i8* %11
%12 = trunc i32 %7 to i8
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 2
store i8 %12, i8* %13
br label %35
14: ; preds = %3
%15 = icmp ult i32 %7, 32768
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 1
br i1 %15, label %17, label %23
17: ; preds = %14
store i8 42, i8* %16
%18 = lshr i32 %7, 8
%19 = trunc i32 %18 to i8
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 2
store i8 %19, i8* %20
%21 = trunc i32 %7 to i8
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 3
store i8 %21, i8* %22
br label %35
23: ; preds = %14
store i8 44, i8* %16
%24 = lshr i32 %7, 24
%25 = trunc i32 %24 to i8
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 2
store i8 %25, i8* %26
%27 = lshr i32 %7, 16
%28 = trunc i32 %27 to i8
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 3
store i8 %28, i8* %29
%30 = lshr i32 %7, 8
%31 = trunc i32 %30 to i8
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 4
store i8 %31, i8* %32
%33 = trunc i32 %7 to i8
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 5
store i8 %33, i8* %34
br label %35
35: ; preds = %17, %23, %10
%36 = phi i32 [ 4, %17 ], [ 6, %23 ], [ 3, %10 ]
%37 = call i32 @zwave_sendClassCommand(i32 %0, i32 67, i32 1, i8* %5, i32 %36)
ret void
}