#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 bee_tlv_appender(int, int, ...);
int bee_tlv_creator(int, int, char *, void **);
int /*<<< orphan*/ noly_hexdump(void *, int);
int /*<<< orphan*/ printf(char *, int);
int strlen(char *);
int cloud_agent_command() {
  char *tlv = NULL;
  int total = 0;
  unsigned char sw[2];
  sw[0] = 0x00;
  sw[1] = 0x02;
  total = bee_tlv_appender(0, 2, sw, &tlv, total);
  unsigned char cla[2];
  cla[0] = 0x00;
  cla[1] = 0x08;
  total = bee_tlv_appender(1, 2, cla, &tlv, total);
  char cmd[] = "set_power";
  total = bee_tlv_appender(2, strlen(cmd), cmd, &tlv, total);
  char val[] = "{\"power\":\"on\"}";
  total = bee_tlv_appender(3, strlen(val), val, &tlv, total);
  char pid[] = "112233445566";
  total = bee_tlv_appender(3, strlen(pid), pid, &tlv, total);
  char nonce[] = "fb0e4ebc6e61e21b82ac0faf3ade9dbd";
  total = bee_tlv_appender(7, strlen(nonce), nonce, &tlv, total);
  void *output = NULL;
  total = bee_tlv_creator(0xffff, total, tlv, &output);
  printf("Cloud Aget TLV Length: %d\n Value:\n", total);
  noly_hexdump(output, total);
}


x86 assembly (clang, -O0):
<cloud_agent_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x0,-0x16(%rbp)
movb   $0x2,-0x15(%rbp)
lea    -0x16(%rbp),%rdx
mov    -0x14(%rbp),%r8d
xor    %edi,%edi
mov    $0x2,%esi
lea    -0x10(%rbp),%rcx
mov    $0x0,%al
call   1060 <bee_tlv_appender@plt>
mov    %eax,-0x14(%rbp)
movb   $0x0,-0x18(%rbp)
movb   $0x8,-0x17(%rbp)
lea    -0x18(%rbp),%rdx
mov    -0x14(%rbp),%r8d
mov    $0x1,%edi
mov    $0x2,%esi
lea    -0x10(%rbp),%rcx
mov    $0x0,%al
call   1060 <bee_tlv_appender@plt>
mov    %eax,-0x14(%rbp)
mov    0xe35(%rip),%rax
mov    %rax,-0x22(%rbp)
mov    0xe32(%rip),%ax
mov    %ax,-0x1a(%rbp)
lea    -0x22(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    -0x22(%rbp),%rdx
mov    -0x14(%rbp),%r8d
mov    $0x2,%edi
lea    -0x10(%rbp),%rcx
mov    $0x0,%al
call   1060 <bee_tlv_appender@plt>
mov    %eax,-0x14(%rbp)
mov    0xe03(%rip),%rax
mov    %rax,-0x31(%rbp)
mov    0xe01(%rip),%eax
mov    %eax,-0x29(%rbp)
mov    0xdfb(%rip),%ax
mov    %ax,-0x25(%rbp)
mov    0xdf3(%rip),%al
mov    %al,-0x23(%rbp)
lea    -0x31(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    -0x31(%rbp),%rdx
mov    -0x14(%rbp),%r8d
mov    $0x3,%edi
lea    -0x10(%rbp),%rcx
mov    $0x0,%al
call   1060 <bee_tlv_appender@plt>
mov    %eax,-0x14(%rbp)
mov    0xdc4(%rip),%rax
mov    %rax,-0x3e(%rbp)
mov    0xdc2(%rip),%eax
mov    %eax,-0x36(%rbp)
mov    0xdbd(%rip),%al
mov    %al,-0x32(%rbp)
lea    -0x3e(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    -0x3e(%rbp),%rdx
mov    -0x14(%rbp),%r8d
mov    $0x3,%edi
lea    -0x10(%rbp),%rcx
mov    $0x0,%al
call   1060 <bee_tlv_appender@plt>
mov    %eax,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xdb4(%rip),%rsi
mov    $0x21,%edx
call   1070 <memcpy@plt>
lea    -0x60(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    -0x60(%rbp),%rdx
mov    -0x14(%rbp),%r8d
mov    $0x7,%edi
lea    -0x10(%rbp),%rcx
mov    $0x0,%al
call   1060 <bee_tlv_appender@plt>
mov    %eax,-0x14(%rbp)
movq   $0x0,-0x68(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    $0xffff,%edi
lea    -0x68(%rbp),%rcx
call   1040 <bee_tlv_creator@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xd30(%rip),%rdi
call   1050 <printf@plt>
mov    -0x68(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1080 <noly_hexdump@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cloud_agent_command>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
movq   $0x0,0x18(%rsp)
movw   $0x200,0xe(%rsp)
lea    0xe(%rsp),%rdx
lea    0x18(%rsp),%r14
xor    %edi,%edi
mov    $0x2,%esi
mov    %r14,%rcx
xor    %r8d,%r8d
xor    %eax,%eax
call   1060 <bee_tlv_appender@plt>
movw   $0x800,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
mov    %r14,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <bee_tlv_appender@plt>
mov    %eax,%ebp
movabs $0x65776f705f746573,%rax
6f 77 65
mov    %rax,0x20(%rsp)
movw   $0x72,0x28(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    $0x2,%edi
mov    %eax,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %ebp,%r8d
xor    %eax,%eax
call   1060 <bee_tlv_appender@plt>
mov    %eax,%ebx
movabs $0x7d226e6f223a22,%rax
mov    %rax,0x47(%rsp)
movabs $0x227265776f70227b,%rax
mov    %rax,0x40(%rsp)
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    $0x3,%edi
mov    %eax,%esi
mov    %rbp,%rdx
mov    %r14,%rcx
mov    %ebx,%r8d
xor    %eax,%eax
call   1060 <bee_tlv_appender@plt>
mov    %eax,%ebx
movabs $0x36363535343433,%rax
mov    %rax,0x35(%rsp)
movabs $0x3434333332323131,%rax
33 34 34
mov    %rax,0x30(%rsp)
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    $0x3,%edi
mov    %eax,%esi
mov    %rbp,%rdx
mov    %r14,%rcx
mov    %ebx,%r8d
xor    %eax,%eax
call   1060 <bee_tlv_appender@plt>
mov    %eax,%ebx
movaps 0xde7(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xdcb(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movb   $0x0,0x70(%rsp)
lea    0x50(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    $0x7,%edi
mov    %eax,%esi
mov    %rbp,%rdx
mov    %r14,%rcx
mov    %ebx,%r8d
xor    %eax,%eax
call   1060 <bee_tlv_appender@plt>
movq   $0x0,0x10(%rsp)
mov    0x18(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    $0xffff,%edi
mov    %eax,%esi
call   1040 <bee_tlv_creator@plt>
mov    %eax,%ebx
lea    0xd4b(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    0x10(%rsp),%rdi
mov    %ebx,%esi
call   1070 <noly_hexdump@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.cloud_agent_command.cmd = [10 x i8] c"set_power\00"
@__const.cloud_agent_command.val = [15 x i8] c"{\22power\22:\22on\22}\00"
@__const.cloud_agent_command.pid = [13 x i8] c"112233445566\00"
@__const.cloud_agent_command.nonce = [33 x i8] c"fb0e4ebc6e61e21b82ac0faf3ade9dbd\00"
@.str = [35 x i8] c"Cloud Aget TLV Length: %d\0A Value:\0A\00"
define i32 @cloud_agent_command() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [2 x i8]
%5 = alloca [2 x i8]
%6 = alloca [10 x i8]
%7 = alloca [15 x i8]
%8 = alloca [13 x i8]
%9 = alloca [33 x i8]
%10 = alloca i8*
store i8* null, i8** %2
store i32 0, i32* %3
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
store i8 0, i8* %11
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 2, i8* %12
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%14 = load i32, i32* %3
%15 = call i32 (i32, i32, ...) @bee_tlv_appender(i32 0, i32 2, i8* %13, i8** %2, i32 %14)
store i32 %15, i32* %3
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
store i8 0, i8* %16
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
store i8 8, i8* %17
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%19 = load i32, i32* %3
%20 = call i32 (i32, i32, ...) @bee_tlv_appender(i32 1, i32 2, i8* %18, i8** %2, i32 %19)
store i32 %20, i32* %3
%21 = bitcast [10 x i8]* %6 to i8*
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%25 = load i32, i32* %3
%26 = call i32 (i32, i32, ...) @bee_tlv_appender(i32 2, i32 %23, i8* %24, i8** %2, i32 %25)
store i32 %26, i32* %3
%27 = bitcast [15 x i8]* %7 to i8*
%28 = getelementptr inbounds [15 x i8], [15 x i8]* %7, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = getelementptr inbounds [15 x i8], [15 x i8]* %7, i64 0, i64 0
%31 = load i32, i32* %3
%32 = call i32 (i32, i32, ...) @bee_tlv_appender(i32 3, i32 %29, i8* %30, i8** %2, i32 %31)
store i32 %32, i32* %3
%33 = bitcast [13 x i8]* %8 to i8*
%34 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
%36 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 0
%37 = load i32, i32* %3
%38 = call i32 (i32, i32, ...) @bee_tlv_appender(i32 3, i32 %35, i8* %36, i8** %2, i32 %37)
store i32 %38, i32* %3
%39 = bitcast [33 x i8]* %9 to i8*
%40 = getelementptr inbounds [33 x i8], [33 x i8]* %9, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = getelementptr inbounds [33 x i8], [33 x i8]* %9, i64 0, i64 0
%43 = load i32, i32* %3
%44 = call i32 (i32, i32, ...) @bee_tlv_appender(i32 7, i32 %41, i8* %42, i8** %2, i32 %43)
store i32 %44, i32* %3
store i8* null, i8** %10
%45 = load i32, i32* %3
%46 = load i8*, i8** %2
%47 = call i32 @bee_tlv_creator(i32 65535, i32 %45, i8* %46, i8** %10)
store i32 %47, i32* %3
%48 = load i32, i32* %3
%49 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %48)
%50 = load i8*, i8** %10
%51 = load i32, i32* %3
%52 = call i32 @noly_hexdump(i8* %50, i32 %51)
%53 = load i32, i32* %1
ret i32 %53
}

LLVM IR (-O2):
@__const.cloud_agent_command.cmd = [10 x i8] c"set_power\00"
@__const.cloud_agent_command.val = [15 x i8] c"{\22power\22:\22on\22}\00"
@__const.cloud_agent_command.pid = [13 x i8] c"112233445566\00"
@__const.cloud_agent_command.nonce = [33 x i8] c"fb0e4ebc6e61e21b82ac0faf3ade9dbd\00"
@.str = [35 x i8] c"Cloud Aget TLV Length: %d\0A Value:\0A\00"
define i32 @cloud_agent_command() {
%1 = alloca i8*
%2 = alloca [2 x i8]
%3 = alloca [2 x i8]
%4 = alloca [10 x i8]
%5 = alloca [15 x i8]
%6 = alloca [13 x i8]
%7 = alloca [33 x i8]
%8 = alloca i8*
%9 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
store i8 0, i8* %10
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
store i8 2, i8* %11
%12 = call i32 (i32, i32, ...) @bee_tlv_appender(i32 0, i32 2, i8* %10, i8** %1, i32 0)
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
store i8 0, i8* %13
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 8, i8* %14
%15 = call i32 (i32, i32, ...) @bee_tlv_appender(i32 1, i32 2, i8* %13, i8** %1, i32 %12)
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
%18 = call i32 (i32, i32, ...) @bee_tlv_appender(i32 2, i32 %17, i8* %16, i8** %1, i32 %15)
%19 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = call i32 (i32, i32, ...) @bee_tlv_appender(i32 3, i32 %20, i8* %19, i8** %1, i32 %18)
%22 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = call i32 (i32, i32, ...) @bee_tlv_appender(i32 3, i32 %23, i8* %22, i8** %1, i32 %21)
%25 = getelementptr inbounds [33 x i8], [33 x i8]* %7, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = call i32 (i32, i32, ...) @bee_tlv_appender(i32 7, i32 %26, i8* %25, i8** %1, i32 %24)
%28 = bitcast i8** %8 to i8*
store i8* null, i8** %8
%29 = load i8*, i8** %1
%30 = call i32 @bee_tlv_creator(i32 65535, i32 %27, i8* %29, i8** %8)
%31 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = load i8*, i8** %8
%33 = call i32 @noly_hexdump(i8* %32, i32 %30)
ret i32 undef
}