// File: /workspace/github_c_makefile_star2_O1/soso7885[P]OPCUA_example/server.c
// Function: main
int main(void)
{
	UA_ServerNetworkLayer nl;	//Server interface
	UA_Server *svr;		//server
	UA_ServerConfig conf;	//Server config
	UA_Int32 val;	//the var value
	UA_VariableAttributes attr;	//the var attribues
	UA_NodeId selfNodeId, parentNodeId, parRefNodeId, varType;//the node-ID
	UA_QualifiedName bName;	//browse-name

	signal(SIGINT, stopHandler);
	signal(SIGTERM, stopHandler);

	/*
	 * Step 1.
	 *	init the server
	*/	
	//fill in the `UA_ServerNetworkLayer` structure member
	nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
	//the server config setting
	conf = UA_ServerConfig_standard;
	conf.logger = Logger_Stdout;
	conf.networkLayers = &nl;
	conf.networkLayersSize = 1;
	svr = UA_Server_new(conf);
	/*
	 * Step 2.
	 *  Set the variable and variable attribute
	*/
	val = 5566;
	UA_String str = UA_STRING_ALLOC("Hello, world");
	UA_VariableAttributes_init(&attr);	
//	UA_Variant_setScalar(&attr.value, &val, &UA_TYPES[UA_TYPES_INT32]);	
	UA_Variant_setScalarCopy(&attr.value, &str, &UA_TYPES[UA_TYPES_STRING]);
	attr.displayName = UA_LOCALIZEDTEXT("TW", "the fucker");
	/*
	 * Step 3.
	 *  Define the variable shall be add with which `browsname`
	*/
	selfNodeId = UA_NODEID_STRING(1, "the.fucker");
	parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
	parRefNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
	varType = UA_NODEID_NULL; //no variable type defined
	bName = UA_QUALIFIEDNAME(1, "the fucker");
	/*
	 * Step 4.
	 * Add the node
	*/
	UA_Server_addVariableNode(svr, selfNodeId, parentNodeId, parRefNodeId,
							bName, varType, attr, NULL, NULL);
	/*
	 * Step 5.
	 * Run server
	*/
	isRunning = true;	// the switch
	UA_Server_run(svr, &isRunning);
	UA_Server_delete(svr);
	
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4f8, %rsp            # imm = 0x4F8
leaq 0x233(%rip), %rbx       # 0x142a
movl $0x2, %edi
movq %rbx, %rsi
callq 0x1090
movl $0xf, %edi
movq %rbx, %rsi
callq 0x1090
movq 0x2dd8(%rip), %rax      # 0x3ff0
movl 0x10(%rax), %ecx
leaq -0x3c0(%rbp), %rbx
movl %ecx, 0x10(%rbx)
movups (%rax), %xmm0
movaps %xmm0, (%rbx)
movl 0x10(%rbx), %eax
movl %eax, 0x10(%rsp)
movaps (%rbx), %xmm0
movups %xmm0, (%rsp)
leaq -0xd0(%rbp), %r14
movq %r14, %rdi
movl $0x4118, %esi           # imm = 0x4118
callq 0x1050
movq 0x2d84(%rip), %rsi      # 0x3fd8
movl $0x160, %edx            # imm = 0x160
movq %rbx, %rdi
callq 0x1080
movq 0x2d78(%rip), %rax      # 0x3fe0
movq %rax, 0x8(%rbx)
movq %r14, 0xf8(%rbx)
movq $0x1, 0xf0(%rbx)
movl $0x2c, %ecx
movq %rsp, %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x1030
movq %rax, %rbx
leaq 0xd69(%rip), %rdi       # 0x2004
callq 0x10c0
leaq -0x98(%rbp), %r15
movq %rax, (%r15)
movq %rdx, 0x8(%r15)
leaq -0x198(%rbp), %rdi
movl $0xc8, %edx
xorl %esi, %esi
callq 0x1060
leaq -0x148(%rbp), %r13
movq 0x2d01(%rip), %r14      # 0x3fd0
leaq 0x1b8(%r14), %rdx
movq %r13, %rdi
movq %r15, %rsi
callq 0x1070
movq $0x2, -0x48(%r13)
leaq 0xd21(%rip), %rax       # 0x2011
movq %rax, -0x40(%r13)
movl $0xa, %r15d
movq %r15, -0x38(%r13)
leaq 0xd0f(%rip), %r12       # 0x2014
movq %r12, -0x30(%r13)
leaq -0x260(%rbp), %r13
movl $0xc8, %edx
movq %r13, %rdi
leaq -0x198(%rbp), %rsi
callq 0x1080
movw $0x1, %ax
movw %ax, -0x58(%rbp)
movq %r15, -0x50(%rbp)
movq %r12, -0x48(%rbp)
xorl %edx, %edx
movw %dx, -0x88(%rbp)
movabsq $0x2300000000, %rcx     # imm = 0x2300000000
movq %rcx, -0x84(%rbp)
movw %dx, -0x70(%rbp)
movabsq $0x5500000000, %rcx     # imm = 0x5500000000
movq %rcx, -0x6c(%rbp)
movw %ax, -0x40(%rbp)
movl $0x3, -0x3c(%rbp)
movq %r15, -0x38(%rbp)
leaq 0xca9(%rip), %rax       # 0x201f
movq %rax, -0x30(%rbp)
movq 0x2c3f(%rip), %rcx      # 0x3fc0
movq 0x10(%rcx), %rdx
movq %rdx, 0x70(%rsp)
movups (%rcx), %xmm0
movups %xmm0, 0x60(%rsp)
movq -0x48(%rbp), %rcx
movq %rcx, 0x58(%rsp)
movups -0x58(%rbp), %xmm0
movups %xmm0, 0x48(%rsp)
movq -0x78(%rbp), %rcx
movq %rcx, 0x40(%rsp)
movups -0x88(%rbp), %xmm0
movups %xmm0, 0x30(%rsp)
movq -0x60(%rbp), %rcx
movq %rcx, 0x28(%rsp)
movups -0x70(%rbp), %xmm0
movups %xmm0, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movups -0x40(%rbp), %xmm0
movups %xmm0, (%rsp)
addq $0x528, %r14            # imm = 0x528
movq %rbx, %rdi
movl $0x2, %esi
movq %r13, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x10b0
movb $0x1, 0x2c82(%rip)      # 0x4081
leaq 0x2c7b(%rip), %rsi      # 0x4081
movq %rbx, %rdi
callq 0x10a0
movq %rbx, %rdi
callq 0x10d0
xorl %eax, %eax
addq $0x4f8, %rsp            # imm = 0x4F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq