// File: /workspace/github_c_makefile_star2_O3/soso7885[P]OPCUA_example/demo_src/server_method.c
// Function: main
int main(int argc, char** argv) {
    signal(SIGINT, stopHandler); /* catches ctrl-c */

    /* initialize the server */
    UA_ServerConfig config = UA_ServerConfig_standard;
    UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
    config.networkLayers = &nl;
    config.networkLayersSize = 1;
    UA_Server *server = UA_Server_new(config);

    //EXAMPLE 1
    /* add the method node with the callback */
    UA_Argument inputArguments;
    UA_Argument_init(&inputArguments);
    inputArguments.arrayDimensionsSize = 0;
    inputArguments.arrayDimensions = NULL;
    inputArguments.dataType = UA_TYPES[UA_TYPES_STRING].typeId;
    inputArguments.description = UA_LOCALIZEDTEXT("en_US", "A String");
    inputArguments.name = UA_STRING("MyInput");
    inputArguments.valueRank = -1;

    UA_Argument outputArguments;
    UA_Argument_init(&outputArguments);
    outputArguments.arrayDimensionsSize = 0;
    outputArguments.arrayDimensions = NULL;
    outputArguments.dataType = UA_TYPES[UA_TYPES_STRING].typeId;
    outputArguments.description = UA_LOCALIZEDTEXT("en_US", "A String");
    outputArguments.name = UA_STRING("MyOutput");
    outputArguments.valueRank = -1;
        
    UA_MethodAttributes helloAttr;
    UA_MethodAttributes_init(&helloAttr);
    helloAttr.description = UA_LOCALIZEDTEXT("en_US","Say `Hello World`");
    helloAttr.displayName = UA_LOCALIZEDTEXT("en_US","Hello World");
    helloAttr.executable = true;
    helloAttr.userExecutable = true;
    UA_Server_addMethodNode(server, UA_NODEID_NUMERIC(1,62541),
                            UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
                            UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
                            UA_QUALIFIEDNAME(1, "hello world"), 
                            helloAttr, &helloWorldMethod, NULL,
                            1, &inputArguments, 1, &outputArguments, NULL);

    //END OF EXAMPLE 1

    //EXAMPLE 2
    /* add another method node: output argument as 1d Int32 array*/
    // define input arguments
    UA_Argument_init(&inputArguments);
    inputArguments.arrayDimensionsSize = 1;
    UA_UInt32 * pInputDimensions = UA_UInt32_new();
    pInputDimensions[0] = 5;
    inputArguments.arrayDimensions = pInputDimensions;
    inputArguments.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
    inputArguments.description = UA_LOCALIZEDTEXT("en_US",
                    "input an array with 5 elements, type int32");
    inputArguments.name = UA_STRING("int32 value");
    inputArguments.valueRank = 1;

    // define output arguments
    UA_Argument_init(&outputArguments);
    outputArguments.arrayDimensionsSize = 1;
    UA_UInt32 * pOutputDimensions = UA_UInt32_new();
    pOutputDimensions[0] = 5;
    outputArguments.arrayDimensions = pOutputDimensions;
    outputArguments.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
    outputArguments.description = UA_LOCALIZEDTEXT("en_US", "increment each array index");
    outputArguments.name = UA_STRING("output is the array, each index is incremented by one");
    outputArguments.valueRank = 1;

    
    UA_MethodAttributes incAttr;
    UA_MethodAttributes_init(&incAttr);
    incAttr.description = UA_LOCALIZEDTEXT("en_US","1dArrayExample");
    incAttr.displayName = UA_LOCALIZEDTEXT("en_US","1dArrayExample");
    incAttr.executable = true;
    incAttr.userExecutable = true;
    UA_Server_addMethodNode(server, UA_NODEID_STRING(1, "IncInt32ArrayValues"),
                            UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
                            UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), 
                            UA_QUALIFIEDNAME(1, "IncInt32ArrayValues"),
                            incAttr, &IncInt32ArrayValuesMethod, NULL,
                            1, &inputArguments, 1, &outputArguments, NULL);
    //END OF EXAMPLE 2

    /* If out methodnode is part of an instantiated object, we never had
       the opportunity to define the callback... we could do that now
    */
    UA_Server_setMethodNode_callback(server, UA_NODEID_NUMERIC(1,62541), &fooBarMethod, NULL);
    
    //END OF EXAMPLE 3
    /* start server */
    UA_StatusCode retval = UA_Server_run(server, &running);

    /* ctrl-c received -> clean up */
    UA_UInt32_delete(pInputDimensions);
    UA_UInt32_delete(pOutputDimensions);
    UA_Server_delete(server);
    nl.deleteMembers(&nl);

    return (int)retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x568, %rsp            # imm = 0x568
leaq 0x5c1(%rip), %rsi       # 0x17f8
movl $0x2, %edi
callq 0x10b0
movq 0x2d98(%rip), %rsi      # 0x3fe0
leaq -0x430(%rbp), %rbx
movl $0x160, %edx            # imm = 0x160
movq %rbx, %rdi
callq 0x10a0
movq 0x2d8d(%rip), %rax      # 0x3ff0
movl 0x10(%rax), %ecx
leaq -0x2d0(%rbp), %r15
movl %ecx, 0x10(%r15)
movups (%rax), %xmm0
movaps %xmm0, (%r15)
movl 0x10(%r15), %eax
movl %eax, 0x10(%rsp)
movaps (%r15), %xmm0
movups %xmm0, (%rsp)
leaq -0x158(%rbp), %r14
movq %r14, %rdi
movl $0x4118, %esi           # imm = 0x4118
callq 0x1060
movq %r14, 0xf8(%rbx)
movl $0x1, %eax
movq %rax, 0xf0(%rbx)
movl $0x2c, %ecx
movq %rsp, %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x1030
movq %rax, -0x30(%rbp)
xorps %xmm1, %xmm1
movups %xmm1, 0x28(%r15)
xorl %r8d, %r8d
movq %r8, 0x38(%r15)
movq 0x2cfc(%rip), %r13      # 0x3fd8
movups 0x1b8(%r13), %xmm0
movaps %xmm0, 0x10(%r15)
movq 0x1c8(%r13), %rdi
movq %rdi, 0x20(%r15)
movl $0x5, %ecx
movq %rcx, 0x40(%r15)
leaq 0xd00(%rip), %rcx       # 0x2004
movq %rcx, 0x48(%r15)
movq %rcx, %r9
movl $0x8, %ecx
movq %rcx, 0x50(%r15)
leaq 0xcef(%rip), %rdx       # 0x200a
movq %rdx, 0x58(%r15)
movq $0x7, (%r15)
leaq 0xce6(%rip), %rsi       # 0x2013
movq %rsi, 0x8(%r15)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %esi, 0x28(%r15)
leaq -0x270(%rbp), %r14
movups %xmm1, 0x28(%r14)
movq %r8, 0x38(%r14)
movaps %xmm0, 0x10(%r14)
movq %rdi, 0x20(%r14)
movl $0x5, %edi
movq %rdi, 0x40(%r14)
movq %r9, 0x48(%r14)
movq %rcx, 0x50(%r14)
movq %rdx, 0x58(%r14)
movq %rcx, (%r14)
leaq 0xca9(%rip), %rcx       # 0x201b
movq %rcx, 0x8(%r14)
movl %esi, 0x28(%r14)
leaq -0x210(%rbp), %rsi
movaps %xmm1, 0x20(%rsi)
movaps %xmm1, 0x30(%rsi)
movaps %xmm1, 0x40(%rsi)
movaps %xmm1, (%rsi)
movaps %xmm1, 0x10(%rsi)
movq %r8, 0x50(%rsi)
movq %rdi, 0x28(%rsi)
movq %r9, 0x30(%rsi)
movq $0x11, 0x38(%rsi)
leaq 0xc75(%rip), %rcx       # 0x2024
movq %rcx, 0x40(%rsi)
movq %rdi, 0x8(%rsi)
movq %r9, 0x10(%rsi)
movl $0xb, %ecx
movq %rcx, 0x18(%rsi)
movl $0xb, %r9d
leaq 0xc65(%rip), %rcx       # 0x2036
movq %rcx, 0x20(%rsi)
movw $0x101, %cx             # imm = 0x101
movw %cx, 0x50(%rsi)
movw $0x1, %cx
movw %cx, -0x110(%rbp)
movw $0x1, %dx
movabsq $0xf44d00000000, %rcx   # imm = 0xF44D00000000
movq %rcx, -0x10c(%rbp)
movl $0x0, %ecx
movw %cx, -0xf8(%rbp)
movabsq $0x5500000000, %rdi     # imm = 0x5500000000
movq %rdi, -0xf4(%rbp)
movw %cx, -0xe0(%rbp)
xorl %r8d, %r8d
movabsq $0x2f00000000, %rcx     # imm = 0x2F00000000
movq %rcx, -0xdc(%rbp)
movw %dx, -0xc8(%rbp)
movq %r9, -0xc0(%rbp)
leaq 0xbf8(%rip), %rdx       # 0x2042
movq %rdx, -0xb8(%rbp)
leaq 0x60(%rsp), %rdi
movl $0xb, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq %rdx, 0x58(%rsp)
movups -0xc8(%rbp), %xmm0
movups %xmm0, 0x48(%rsp)
movq -0xd0(%rbp), %rcx
movq %rcx, 0x40(%rsp)
movups -0xe0(%rbp), %xmm0
movups %xmm0, 0x30(%rsp)
movq -0xe8(%rbp), %rcx
movq %rcx, 0x28(%rsp)
movups -0xf8(%rbp), %xmm0
movups %xmm0, 0x18(%rsp)
movq -0x100(%rbp), %rcx
movq %rcx, 0x10(%rsp)
movups -0x110(%rbp), %xmm0
movups %xmm0, (%rsp)
movq %r8, 0xc0(%rsp)
movq %r14, 0xb8(%rsp)
leaq 0x359(%rip), %rsi       # 0x1826
movl $0x1, %ecx
movl $0x1, %r9d
movq %rax, %rdi
xorl %edx, %edx
movq %r15, %r8
callq 0x1040
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%r15)
movaps %xmm0, (%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x40(%r15)
movaps %xmm0, 0x50(%r15)
movl $0x1, %ebx
movq %rbx, 0x30(%r15)
leaq 0xf0(%r13), %r12
movq %r12, %rdi
callq 0x1080
movq %rax, -0x38(%rbp)
movl $0x5, %ecx
movl %ecx, (%rax)
movq %rax, 0x38(%r15)
movups 0xc8(%r13), %xmm0
movaps %xmm0, -0x120(%rbp)
movaps %xmm0, 0x10(%r15)
movq 0xd8(%r13), %r13
movq %r13, 0x20(%r15)
movl $0x5, %eax
movq %rax, 0x40(%r15)
leaq 0xaa9(%rip), %rax       # 0x2004
movq %rax, 0x48(%r15)
movq $0x2a, 0x50(%r15)
leaq 0xae0(%rip), %rax       # 0x204e
movq %rax, 0x58(%r15)
movl $0xb, %eax
movq %rax, (%r15)
leaq 0xaf8(%rip), %rax       # 0x2079
movq %rax, 0x8(%r15)
movl $0x1, %eax
movl %eax, 0x28(%r15)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%r14)
movaps %xmm0, (%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, 0x40(%r14)
movaps %xmm0, 0x50(%r14)
movaps %xmm0, 0x20(%r14)
movq %rbx, 0x30(%r14)
movq %r12, %rdi
callq 0x1080
movq %rax, %rbx
movl $0x5, %eax
movl %eax, (%rbx)
movq %rbx, 0x38(%r14)
movaps -0x120(%rbp), %xmm0
movaps %xmm0, 0x10(%r14)
movq %r13, 0x20(%r14)
movl $0x5, %edx
movq %rdx, 0x40(%r14)
leaq 0xa1c(%rip), %rcx       # 0x2004
movq %rcx, 0x48(%r14)
movq $0x1a, 0x50(%r14)
leaq 0xa8a(%rip), %rax       # 0x2085
movq %rax, 0x58(%r14)
movq $0x35, (%r14)
leaq 0xa93(%rip), %rax       # 0x20a0
movq %rax, 0x8(%r14)
movl $0x1, %eax
movl %eax, 0x28(%r14)
leaq -0x1b0(%rbp), %rsi
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsi)
movaps %xmm0, 0x30(%rsi)
movaps %xmm0, 0x40(%rsi)
movaps %xmm0, (%rsi)
movaps %xmm0, 0x10(%rsi)
movl $0x0, %edi
movq %rdi, 0x50(%rsi)
movq %rdx, 0x28(%rsi)
movl $0x5, %r8d
movq %rcx, 0x30(%rsi)
movq %rcx, %rdx
movl $0xe, %eax
movq %rax, 0x38(%rsi)
leaq 0xa75(%rip), %rcx       # 0x20d6
movq %rcx, 0x40(%rsi)
movq %r8, 0x8(%rsi)
movq %rdx, 0x10(%rsi)
movq %rax, 0x18(%rsi)
movq %rcx, 0x20(%rsi)
movw $0x101, %ax             # imm = 0x101
movw %ax, 0x50(%rsi)
movw $0x1, %cx
movw %cx, -0x50(%rbp)
movl $0x3, -0x4c(%rbp)
movl $0x13, %eax
movq %rax, -0x48(%rbp)
leaq 0xa49(%rip), %rdx       # 0x20e5
movq %rdx, -0x40(%rbp)
movw %di, -0xb0(%rbp)
movabsq $0x5500000000, %r8      # imm = 0x5500000000
movq %r8, -0xac(%rbp)
movw %di, -0x98(%rbp)
xorl %r8d, %r8d
movabsq $0x2f00000000, %rdi     # imm = 0x2F00000000
movq %rdi, -0x94(%rbp)
movw %cx, -0x80(%rbp)
movw $0x1, %r13w
movq %rax, -0x78(%rbp)
movq %rdx, -0x70(%rbp)
leaq 0x60(%rsp), %rdi
movl $0xb, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq %rdx, 0x58(%rsp)
movups -0x80(%rbp), %xmm0
movups %xmm0, 0x48(%rsp)
movq -0x88(%rbp), %rax
movq %rax, 0x40(%rsp)
movups -0x98(%rbp), %xmm0
movups %xmm0, 0x30(%rsp)
movq -0xa0(%rbp), %rax
movq %rax, 0x28(%rsp)
movups -0xb0(%rbp), %xmm0
movups %xmm0, 0x18(%rsp)
movq -0x40(%rbp), %rax
movq %rax, 0x10(%rsp)
movups -0x50(%rbp), %xmm0
movups %xmm0, (%rsp)
movq %r8, 0xc0(%rsp)
movq %r14, 0xb8(%rsp)
leaq 0x18a(%rip), %rsi       # 0x18e1
movl $0x1, %ecx
movl $0x1, %r9d
movq -0x30(%rbp), %r14
movq %r14, %rdi
xorl %edx, %edx
movq %r15, %r8
callq 0x1040
movw %r13w, -0x68(%rbp)
movabsq $0xf44d00000000, %rax   # imm = 0xF44D00000000
movq %rax, -0x64(%rbp)
movq -0x58(%rbp), %rax
movq %rax, 0x10(%rsp)
movups -0x68(%rbp), %xmm0
movups %xmm0, (%rsp)
leaq 0x197(%rip), %rsi       # 0x1935
movq %r14, %rdi
xorl %edx, %edx
callq 0x10f0
leaq 0x28f1(%rip), %rsi      # 0x40a0
movq %r14, %rdi
callq 0x10c0
movl %eax, %r15d
movq -0x38(%rbp), %rdi
movq %r12, %rsi
callq 0x1100
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1100
movq %r14, %rdi
callq 0x1110
leaq -0x158(%rbp), %rdi
callq *0x30(%rdi)
movl %r15d, %eax
addq $0x568, %rsp            # imm = 0x568
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq