#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 unsigned char offset;

/* Variables and functions */
int strtol(char *, char **, int);
int /*<<< orphan*/ zwave_sendClassCommand(unsigned int, int, int,
                                          unsigned char *, int);
void zwavecmd_proprietary_set(unsigned int id, int offset, char *argv[]) {
  unsigned char buf[256];
  int l;
  buf[0] = 0x22;
  buf[1] = (offset >> 8) & 0xff;
  buf[2] = (offset)&0xff;
  buf[3] = 1;
  buf[4] = 4;
  l = 5;
  while (*argv) {
    char *endptr;
    int value = strtol(*argv, &endptr, 16);
    buf[l] = (value >> 24) & 0xff;
    buf[l + 1] = (value >> 16) & 0xff;
    buf[l + 2] = (value >> 8) & 0xff;
    buf[l + 3] = value & 0xff;
    l += 4;
    argv++;
  }
  zwave_sendClassCommand(id, 0x88, 0x01, buf, l);
}


x86 assembly (clang, -O0):
<zwavecmd_proprietary_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movb   $0x22,-0x110(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x10f(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x10e(%rbp)
movb   $0x1,-0x10d(%rbp)
movb   $0x4,-0x10c(%rbp)
movl   $0x5,-0x114(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1240 <zwavecmd_proprietary_set+0x120>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x120(%rbp),%rsi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,-0x124(%rbp)
mov    -0x124(%rbp),%eax
sar    $0x18,%eax
and    $0xff,%eax
mov    %al,%cl
movslq -0x114(%rbp),%rax
mov    %cl,-0x110(%rbp,%rax,1)
mov    -0x124(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x114(%rbp),%eax
add    $0x1,%eax
cltq
mov    %cl,-0x110(%rbp,%rax,1)
mov    -0x124(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x114(%rbp),%eax
add    $0x2,%eax
cltq
mov    %cl,-0x110(%rbp,%rax,1)
mov    -0x124(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x114(%rbp),%eax
add    $0x3,%eax
cltq
mov    %cl,-0x110(%rbp,%rax,1)
mov    -0x114(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x114(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1173 <zwavecmd_proprietary_set+0x53>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rcx
mov    -0x114(%rbp),%r8d
mov    $0x88,%esi
mov    $0x1,%edx
call   1030 <zwave_sendClassCommand@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zwavecmd_proprietary_set>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %esi,%eax
mov    %edi,%r14d
movb   $0x22,0x10(%rsp)
mov    %ah,0x11(%rsp)
mov    %al,0x12(%rsp)
movw   $0x401,0x13(%rsp)
mov    (%rdx),%rdi
test   %rdi,%rdi
je     1186 <zwavecmd_proprietary_set+0x66>
mov    %rdx,%rbp
xor    %ebx,%ebx
lea    0x8(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %r15,%rsi
mov    $0x10,%edx
call   1040 <strtol@plt>
bswap  %eax
mov    %eax,0x15(%rsp,%rbx,1)
mov    0x8(%rbp,%rbx,2),%rdi
add    $0x4,%rbx
test   %rdi,%rdi
jne    1160 <zwavecmd_proprietary_set+0x40>
add    $0x5,%ebx
jmp    118b <zwavecmd_proprietary_set+0x6b>
mov    $0x5,%ebx
lea    0x10(%rsp),%rcx
mov    %r14d,%edi
mov    $0x88,%esi
mov    $0x1,%edx
mov    %ebx,%r8d
call   1030 <zwave_sendClassCommand@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @zwavecmd_proprietary_set(i32 %0, i32 %1, i8** nocapture %2) {
%4 = alloca [256 x i8]
%5 = alloca i8*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
store i8 34, i8* %6
%7 = lshr i32 %1, 8
%8 = trunc i32 %7 to i8
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 1
store i8 %8, i8* %9
%10 = trunc i32 %1 to i8
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 2
store i8 %10, i8* %11
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 3
store i8 1, i8* %12
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 4
store i8 4, i8* %13
%14 = load i8*, i8** %2
%15 = icmp eq i8* %14, null
br i1 %15, label %43, label %16
16: ; preds = %3
%17 = bitcast i8** %5 to i8*
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 5, %16 ], [ %37, %18 ]
%20 = phi i8* [ %14, %16 ], [ %39, %18 ]
%21 = phi i8** [ %2, %16 ], [ %38, %18 ]
%22 = call i32 @strtol(i8* %20, i8** %5, i32 16)
%23 = lshr i32 %22, 24
%24 = trunc i32 %23 to i8
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %19
store i8 %24, i8* %25
%26 = lshr i32 %22, 16
%27 = trunc i32 %26 to i8
%28 = add nuw nsw i64 %19, 1
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %28
store i8 %27, i8* %29
%30 = lshr i32 %22, 8
%31 = trunc i32 %30 to i8
%32 = add nuw nsw i64 %19, 2
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %32
store i8 %31, i8* %33
%34 = trunc i32 %22 to i8
%35 = add nuw nsw i64 %19, 3
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %35
store i8 %34, i8* %36
%37 = add nuw nsw i64 %19, 4
%38 = getelementptr inbounds i8*, i8** %21, i64 1
%39 = load i8*, i8** %38
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %18
41: ; preds = %18
%42 = trunc i64 %37 to i32
br label %43
43: ; preds = %41, %3
%44 = phi i32 [ 5, %3 ], [ %42, %41 ]
%45 = call i32 @zwave_sendClassCommand(i32 %0, i32 136, i32 1, i8* %6, i32 %44)
ret void
}