#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 int, int);
int /*<<< orphan*/ zwave_sendClassCommand(unsigned int, int, int,
                                          unsigned char *, char);
void zwavecmd_configuration_set(unsigned int id, unsigned int no, int v) {
  char buf[255];
  printf("Set parameter %d to be %d\n", no, v);
  buf[0] = no;
  if (v < 128 && v >= -128) {
    buf[1] = 1;
    buf[2] = v;
  } else if (v >= -32768 && v < 32768) {
    buf[1] = 2;
    buf[2] = v / 256;
    buf[3] = v & 0xff;
  } else {
    buf[1] = 4;
    buf[2] = v / (1 << 24);
    buf[3] = (v >> 16) & 0xff;
    buf[4] = (v >> 8) & 0xff;
    buf[5] = v & 0xff;
  }
  zwave_sendClassCommand(id, 0x70, 0x04, (unsigned char *)buf, buf[1] + 2);
}


x86 assembly (clang, -O0):
<zwavecmd_configuration_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xebf(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %al,-0x110(%rbp)
cmpl   $0x80,-0xc(%rbp)
jge    117b <zwavecmd_configuration_set+0x5b>
cmpl   $0xffffff80,-0xc(%rbp)
jl     117b <zwavecmd_configuration_set+0x5b>
movb   $0x1,-0x10f(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,-0x10e(%rbp)
jmp    120d <zwavecmd_configuration_set+0xed>
cmpl   $0xffff8000,-0xc(%rbp)
jl     11c0 <zwavecmd_configuration_set+0xa0>
cmpl   $0x8000,-0xc(%rbp)
jge    11c0 <zwavecmd_configuration_set+0xa0>
movb   $0x2,-0x10f(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %al,-0x10e(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x10d(%rbp)
jmp    1208 <zwavecmd_configuration_set+0xe8>
movb   $0x4,-0x10f(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x1000000,%ecx
cltd
idiv   %ecx
mov    %al,-0x10e(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,-0x10d(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x10c(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x10b(%rbp)
jmp    120d <zwavecmd_configuration_set+0xed>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rcx
movsbl -0x10f(%rbp),%eax
add    $0x2,%eax
mov    $0x70,%esi
mov    $0x4,%edx
movsbl %al,%r8d
call   1040 <zwave_sendClassCommand@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zwavecmd_configuration_set>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %edx,%ebx
mov    %esi,%ebp
mov    %edi,%r14d
lea    0xec7(%rip),%rdi
call   1030 <printf@plt>
mov    %bpl,(%rsp)
movsbl %bl,%eax
cmp    %ebx,%eax
jne    1156 <zwavecmd_configuration_set+0x36>
movb   $0x1,0x1(%rsp)
mov    %bl,0x2(%rsp)
mov    $0x3,%al
jmp    11a4 <zwavecmd_configuration_set+0x84>
movswl %bx,%eax
cmp    %ebx,%eax
jne    117a <zwavecmd_configuration_set+0x5a>
lea    0xff(%rbx),%eax
test   %bx,%bx
cmovns %ebx,%eax
movb   $0x2,0x1(%rsp)
mov    %ah,0x2(%rsp)
mov    %bl,0x3(%rsp)
mov    $0x4,%al
jmp    11a4 <zwavecmd_configuration_set+0x84>
lea    0xffffff(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
movb   $0x4,0x1(%rsp)
shr    $0x18,%eax
mov    %al,0x2(%rsp)
mov    %ebx,%eax
shr    $0x10,%eax
mov    %al,0x3(%rsp)
mov    %bh,0x4(%rsp)
mov    %bl,0x5(%rsp)
mov    $0x6,%al
movzbl %al,%r8d
mov    %rsp,%rcx
mov    %r14d,%edi
mov    $0x70,%esi
mov    $0x4,%edx
call   1040 <zwave_sendClassCommand@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Set parameter %d to be %d\0A\00"
define void @zwavecmd_configuration_set(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [255 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = load i32, i32* %6
%10 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9)
%11 = load i32, i32* %5
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
store i8 %12, i8* %13
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 128
br i1 %15, label %16, label %24
16: ; preds = %3
%17 = load i32, i32* %6
%18 = icmp sge i32 %17, -128
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 1
store i8 1, i8* %20
%21 = load i32, i32* %6
%22 = trunc i32 %21 to i8
%23 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 2
store i8 %22, i8* %23
br label %61
24: ; preds = %16, %3
%25 = load i32, i32* %6
%26 = icmp sge i32 %25, -32768
br i1 %26, label %27, label %40
27: ; preds = %24
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 32768
br i1 %29, label %30, label %40
30: ; preds = %27
%31 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 1
store i8 2, i8* %31
%32 = load i32, i32* %6
%33 = sdiv i32 %32, 256
%34 = trunc i32 %33 to i8
%35 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 2
store i8 %34, i8* %35
%36 = load i32, i32* %6
%37 = and i32 %36, 255
%38 = trunc i32 %37 to i8
%39 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 3
store i8 %38, i8* %39
br label %60
40: ; preds = %27, %24
%41 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 1
store i8 4, i8* %41
%42 = load i32, i32* %6
%43 = sdiv i32 %42, 16777216
%44 = trunc i32 %43 to i8
%45 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 2
store i8 %44, i8* %45
%46 = load i32, i32* %6
%47 = ashr i32 %46, 16
%48 = and i32 %47, 255
%49 = trunc i32 %48 to i8
%50 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 3
store i8 %49, i8* %50
%51 = load i32, i32* %6
%52 = ashr i32 %51, 8
%53 = and i32 %52, 255
%54 = trunc i32 %53 to i8
%55 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 4
store i8 %54, i8* %55
%56 = load i32, i32* %6
%57 = and i32 %56, 255
%58 = trunc i32 %57 to i8
%59 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 5
store i8 %58, i8* %59
br label %60
60: ; preds = %40, %30
br label %61
61: ; preds = %60, %19
%62 = load i32, i32* %4
%63 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%64 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 1
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = add nsw i32 %66, 2
%68 = trunc i32 %67 to i8
%69 = call i32 @zwave_sendClassCommand(i32 %62, i32 112, i32 4, i8* %63, i8 signext %68)
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"Set parameter %d to be %d\0A\00"
define void @zwavecmd_configuration_set(i32 %0, i32 %1, i32 %2) {
%4 = alloca [255 x i8]
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%7 = trunc i32 %1 to i8
store i8 %7, i8* %5
%8 = add i32 %2, 128
%9 = icmp ult i32 %8, 256
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 1
store i8 1, i8* %11
%12 = trunc i32 %2 to i8
%13 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 2
store i8 %12, i8* %13
br label %37
14: ; preds = %3
%15 = add i32 %2, 32768
%16 = icmp ult i32 %15, 65536
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 1
br i1 %16, label %18, label %25
18: ; preds = %14
store i8 2, i8* %17
%19 = trunc i32 %2 to i16
%20 = sdiv i16 %19, 256
%21 = trunc i16 %20 to i8
%22 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 2
store i8 %21, i8* %22
%23 = trunc i32 %2 to i8
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 3
store i8 %23, i8* %24
br label %37
25: ; preds = %14
store i8 4, i8* %17
%26 = sdiv i32 %2, 16777216
%27 = trunc i32 %26 to i8
%28 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 2
store i8 %27, i8* %28
%29 = lshr i32 %2, 16
%30 = trunc i32 %29 to i8
%31 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 3
store i8 %30, i8* %31
%32 = lshr i32 %2, 8
%33 = trunc i32 %32 to i8
%34 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 4
store i8 %33, i8* %34
%35 = trunc i32 %2 to i8
%36 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 5
store i8 %35, i8* %36
br label %37
37: ; preds = %18, %25, %10
%38 = phi i8 [ 4, %18 ], [ 6, %25 ], [ 3, %10 ]
%39 = call i32 @zwave_sendClassCommand(i32 %0, i32 112, i32 4, i8* %5, i8 signext %38)
ret void
}