// File: /workspace/github_cpp_makefile_star2_O1/bummelbaerchen[P]e3dc/RscpExampleMain.cpp
// Function: ControlLoadData2(SRscpFrameBuffer*, int)
int ControlLoadData2(SRscpFrameBuffer * frameBuffer,int32_t iPower) {
    RscpProtocol protocol;
    SRscpValue rootValue;
    uint32_t uPower;
    if (iPower < 0) uPower = 0; else if (iPower>e3dc_config.maximumLadeleistung) uPower = e3dc_config.maximumLadeleistung; else uPower = iPower;
    // The root container is create with the TAG ID 0 which is not used by any device.
    protocol.createContainerValue(&rootValue, 0);
    
    // request Power Meter information
    SRscpValue PMContainer;
    protocol.createContainerValue(&PMContainer, TAG_EMS_REQ_SET_POWER_SETTINGS);
    protocol.appendValue(&PMContainer, TAG_EMS_POWER_LIMITS_USED,true);
   protocol.appendValue(&PMContainer, TAG_EMS_MAX_CHARGE_POWER,uPower);
//    protocol.appendValue(&PMContainer, TAG_EMS_MAX_DISCHARGE_POWER,300);
//    protocol.appendValue(&PMContainer, TAG_EMS_DISCHARGE_START_POWER,70);
    // append sub-container to root container
    protocol.appendValue(&rootValue, PMContainer);
    // free memory of sub-container as it is now copied to rootValue
    protocol.destroyValueData(PMContainer);
    
    
    
    
    // create buffer frame to send data to the S10
    protocol.createFrameAsBuffer(frameBuffer, rootValue.data, rootValue.length, true); // true to calculate CRC on for transfer
    // the root value object should be destroyed after the data is copied into the frameBuffer and is not needed anymore
    protocol.destroyValueData(rootValue);
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %rbx
subq $0x48, %rsp
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x10(%rsp), %rdi
callq 0x76c4
testl %ebp, %ebp
js 0x25ff
movl 0x15187(%rip), %eax     # 0x1777c
cmpl %ebp, %eax
jge 0x2609
movl %eax, 0x20(%rsp)
jmp 0x260d
movl $0x0, 0x20(%rsp)
jmp 0x260d
movl %ebp, 0x20(%rsp)
leaq 0x28(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0xe(%rsp), %r9
movb $0xe, (%r9)
leaq 0x1c(%rsp), %r8
movw $0x0, (%r8)
leaq 0x10(%rsp), %rdi
leaq 0x39(%rsp), %rsi
xorl %ecx, %ecx
callq 0x80f0
leaq 0x1c(%rsp), %rdx
movl $0x100008c, (%rdx)      # imm = 0x100008C
leaq 0xd(%rsp), %r9
movb $0xe, (%r9)
leaq 0xe(%rsp), %r8
movw $0x0, (%r8)
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
xorl %ecx, %ecx
callq 0x80f0
leaq 0x1c(%rsp), %rdx
movl $0x1000100, (%rdx)      # imm = 0x1000100
movb $0x1, %al
leaq 0x27(%rsp), %rcx
movb %al, (%rcx)
leaq 0xe(%rsp), %r8
movw $0x1, (%r8)
leaq 0xd(%rsp), %r9
movb %al, (%r9)
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x82b2
leaq 0x1c(%rsp), %rdx
movl $0x1000101, (%rdx)      # imm = 0x1000101
leaq 0xe(%rsp), %r8
movw $0x4, (%r8)
leaq 0xd(%rsp), %r9
movb $0x7, (%r9)
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x20(%rsp), %rcx
callq 0x82b2
leaq 0x10(%rsp), %rdi
leaq 0x39(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x7464
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x85d0
movq 0x40(%rsp), %rdx
movzwl 0x3e(%rsp), %ecx
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
movl $0x1, %r8d
callq 0x77ac
leaq 0x10(%rsp), %rdi
leaq 0x39(%rsp), %rsi
callq 0x85d0
leaq 0x10(%rsp), %rdi
callq 0x76d0
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %rbp
retq
jmp 0x2740
jmp 0x2740
jmp 0x2740
jmp 0x2740
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x76d0
movq %rbx, %rdi
callq 0x2290