// File: /workspace/github_c_makefile_star2_O2/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 $0x508, %rsp            # imm = 0x508
leaq 0x24f(%rip), %rbx       # 0x1456
pushq $0x2
popq %rdi
movq %rbx, %rsi
callq 0x10a0
pushq $0xf
popq %rdi
movq %rbx, %rsi
callq 0x10a0
movq 0x2dcc(%rip), %rax      # 0x3ff0
movl 0x10(%rax), %ecx
leaq -0x3d0(%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 -0xd8(%rbp), %r14
movq %r14, %rdi
movl $0x4118, %esi           # imm = 0x4118
callq 0x1050
movq 0x2d78(%rip), %rsi      # 0x3fd8
movl $0x160, %edx            # imm = 0x160
movq %rbx, %rdi
callq 0x1090
movq 0x2d6c(%rip), %rax      # 0x3fe0
movq %rax, 0x8(%rbx)
movq %r14, 0xf8(%rbx)
movq $0x1, 0xf0(%rbx)
pushq $0x2c
popq %rcx
movq %rsp, %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x1030
movq %rax, -0x30(%rbp)
leaq 0xd5e(%rip), %rdi       # 0x2004
callq 0x10d0
leaq -0xa0(%rbp), %rbx
movq %rax, (%rbx)
movq %rdx, 0x8(%rbx)
leaq -0x1a0(%rbp), %rdi
movl $0xc8, %edx
xorl %esi, %esi
callq 0x1070
leaq -0x150(%rbp), %r12
movq 0x2cf6(%rip), %rax      # 0x3fd0
leaq 0x1b8(%rax), %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1080
leaq 0xd1e(%rip), %rdi       # 0x2011
callq 0x146f
movq %rax, %rbx
movq %rdx, %r13
leaq 0xd0f(%rip), %rdi       # 0x2014
callq 0x146f
movq %rax, %r14
movq %rdx, %r15
movq %rbx, -0x48(%r12)
movq %r13, -0x40(%r12)
movq %rax, -0x38(%r12)
movq %rdx, -0x30(%r12)
leaq 0xcf4(%rip), %rdi       # 0x201f
callq 0x146f
movq %rax, %r13
movq %rdx, %rbx
leaq -0x268(%rbp), %r12
movl $0xc8, %edx
movq %r12, %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x1090
movw $0x1, %ax
movw %ax, -0x60(%rbp)
movq %r14, -0x58(%rbp)
andw $0x0, -0x90(%rbp)
movq %r15, -0x50(%rbp)
andw $0x0, -0x78(%rbp)
movabsq $0x2300000000, %rcx     # imm = 0x2300000000
movq %rcx, -0x8c(%rbp)
movabsq $0x5500000000, %rcx     # imm = 0x5500000000
movq %rcx, -0x74(%rbp)
movw %ax, -0x48(%rbp)
movl $0x3, -0x44(%rbp)
movq %r13, -0x40(%rbp)
movq %rbx, -0x38(%rbp)
movq 0x2c19(%rip), %rax      # 0x3fc0
movq 0x10(%rax), %rcx
movq %rcx, 0x70(%rsp)
movups (%rax), %xmm0
movups %xmm0, 0x60(%rsp)
movq -0x50(%rbp), %rax
movq %rax, 0x58(%rsp)
movups -0x60(%rbp), %xmm0
movups %xmm0, 0x48(%rsp)
movq -0x80(%rbp), %rax
movq %rax, 0x40(%rsp)
movups -0x90(%rbp), %xmm0
movups %xmm0, 0x30(%rsp)
movq -0x68(%rbp), %rax
movq %rax, 0x28(%rsp)
movups -0x78(%rbp), %xmm0
movups %xmm0, 0x18(%rsp)
movq %rbx, 0x10(%rsp)
movups -0x48(%rbp), %xmm0
movups %xmm0, (%rsp)
movq 0x2bcb(%rip), %rcx      # 0x3fd0
addq $0x528, %rcx            # imm = 0x528
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
pushq $0x2
popq %rsi
movq %r12, %rdx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x10c0
movb $0x1, 0x2c5e(%rip)      # 0x4089
leaq 0x2c57(%rip), %rsi      # 0x4089
movq %rbx, %rdi
callq 0x10b0
movq %rbx, %rdi
callq 0x10e0
xorl %eax, %eax
addq $0x508, %rsp            # imm = 0x508
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq