#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*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ zwave_sendClassCommand(unsigned int, int, int,
                                          unsigned char *, int);
void zwavecmd_configuration_bulk_set_buf(unsigned int id, unsigned int offset,
                                         unsigned char *data, int len) {
  unsigned char buf[255];
  buf[0] = offset / 256;
  buf[1] = offset % 256;
  if ((len % 4) == 0) {
    buf[2] = len / 4;
    buf[3] = 4;
  } else if ((len % 2) == 0) {
    buf[2] = len / 2;
    buf[3] = 2;
  } else {
    buf[2] = len;
    buf[3] = 1;
  }
  memcpy(buf + 4, data, len);
  zwave_sendClassCommand(id, 0x70, 0x07, buf, len + 4);
}


x86 assembly (clang, -O0):
<zwavecmd_configuration_bulk_set_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x8(%rbp),%eax
shr    $0x8,%eax
mov    %al,-0x120(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x11f(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1183 <zwavecmd_configuration_bulk_set_buf+0x63>
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %al,-0x11e(%rbp)
movb   $0x4,-0x11d(%rbp)
jmp    11c9 <zwavecmd_configuration_bulk_set_buf+0xa9>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11b4 <zwavecmd_configuration_bulk_set_buf+0x94>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %al,-0x11e(%rbp)
movb   $0x2,-0x11d(%rbp)
jmp    11c4 <zwavecmd_configuration_bulk_set_buf+0xa4>
mov    -0x14(%rbp),%eax
mov    %al,-0x11e(%rbp)
movb   $0x1,-0x11d(%rbp)
jmp    11c9 <zwavecmd_configuration_bulk_set_buf+0xa9>
lea    -0x120(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rcx
mov    -0x14(%rbp),%r8d
add    $0x4,%r8d
mov    $0x70,%esi
mov    $0x7,%edx
call   1030 <zwave_sendClassCommand@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zwavecmd_configuration_bulk_set_buf>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    %ecx,%ebx
mov    %edi,%ebp
rol    $0x8,%si
mov    %si,(%rsp)
test   $0x3,%bl
je     1150 <zwavecmd_configuration_bulk_set_buf+0x30>
mov    $0x1,%cl
mov    %ebx,%eax
test   $0x1,%bl
jne    115d <zwavecmd_configuration_bulk_set_buf+0x3d>
mov    %ebx,%eax
shr    $0x1f,%eax
add    %ebx,%eax
sar    %eax
mov    $0x2,%cl
jmp    115d <zwavecmd_configuration_bulk_set_buf+0x3d>
lea    0x3(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
sar    $0x2,%eax
mov    $0x4,%cl
mov    %al,0x2(%rsp)
mov    %cl,0x3(%rsp)
lea    0x4(%rsp),%rdi
mov    %rdx,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
add    $0x4,%ebx
mov    %rsp,%rcx
mov    %ebp,%edi
mov    $0x70,%esi
mov    $0x7,%edx
mov    %ebx,%r8d
call   1030 <zwave_sendClassCommand@plt>
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @zwavecmd_configuration_bulk_set_buf(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [255 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i32, i32* %6
%11 = udiv i32 %10, 256
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
store i8 %12, i8* %13
%14 = load i32, i32* %6
%15 = urem i32 %14, 256
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 1
store i8 %16, i8* %17
%18 = load i32, i32* %8
%19 = srem i32 %18, 4
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %4
%22 = load i32, i32* %8
%23 = sdiv i32 %22, 4
%24 = trunc i32 %23 to i8
%25 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 2
store i8 %24, i8* %25
%26 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 3
store i8 4, i8* %26
br label %43
27: ; preds = %4
%28 = load i32, i32* %8
%29 = srem i32 %28, 2
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %27
%32 = load i32, i32* %8
%33 = sdiv i32 %32, 2
%34 = trunc i32 %33 to i8
%35 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 2
store i8 %34, i8* %35
%36 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 3
store i8 2, i8* %36
br label %42
37: ; preds = %27
%38 = load i32, i32* %8
%39 = trunc i32 %38 to i8
%40 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 2
store i8 %39, i8* %40
%41 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 3
store i8 1, i8* %41
br label %42
42: ; preds = %37, %31
br label %43
43: ; preds = %42, %21
%44 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%45 = getelementptr inbounds i8, i8* %44, i64 4
%46 = load i8*, i8** %7
%47 = load i32, i32* %8
%48 = call i32 @memcpy(i8* %45, i8* %46, i32 %47)
%49 = load i32, i32* %5
%50 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 4
%53 = call i32 @zwave_sendClassCommand(i32 %49, i32 112, i32 7, i8* %50, i32 %52)
ret void
}

LLVM IR (-O2):
define void @zwavecmd_configuration_bulk_set_buf(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [255 x i8]
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%7 = lshr i32 %1, 8
%8 = trunc i32 %7 to i8
store i8 %8, i8* %6
%9 = trunc i32 %1 to i8
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 1
store i8 %9, i8* %10
%11 = and i32 %3, 3
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = sdiv i32 %3, 4
br label %20
15: ; preds = %4
%16 = and i32 %3, 1
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = sdiv i32 %3, 2
br label %20
20: ; preds = %15, %18, %13
%21 = phi i32 [ %19, %18 ], [ %14, %13 ], [ %3, %15 ]
%22 = phi i8 [ 2, %18 ], [ 4, %13 ], [ 1, %15 ]
%23 = trunc i32 %21 to i8
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 2
store i8 %23, i8* %24
%25 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 3
store i8 %22, i8* %25
%26 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 4
%27 = call i32 @memcpy(i8* %26, i8* %2, i32 %3)
%28 = add nsw i32 %3, 4
%29 = call i32 @zwave_sendClassCommand(i32 %0, i32 112, i32 7, i8* %6, i32 %28)
ret void
}