// File: /workspace/github_c_makefile_star2_O3/soso7885[P]OPCUA_example/client.c
// Function: main
int main(void)
{
	UA_Client *clt;	//client
	UA_StatusCode retval;
	UA_ReadRequest req;	//read request
	UA_ReadResponse resp; //response
	/*
	 * Step 1.
	 *	create & init the client
	*/
	clt = UA_Client_new(UA_ClientConfig_standard);
	retval = UA_Client_connect(clt, URL);
	if(retval != UA_STATUSCODE_GOOD){
		UA_Client_delete(clt);
		return retval;
	}
	/*
	 * Step 2.
	 *	Create read request
	*/
	UA_ReadRequest_init(&req);	// memset 0 in req
	req.nodesToRead = UA_Array_new(1, &UA_TYPES[UA_TYPES_READVALUEID]);
	req.nodesToReadSize = 1;
	/*
	 * Step 3.
	 *	define which node and attribute to be read
	*/
	req.nodesToRead[0].nodeId = UA_NODEID_STRING_ALLOC(1, "the.fucker");
	req.nodesToRead[0].attributeId = UA_ATTRIBUTEID_VALUE;
	/*
	 * Step 4.
	 *	call the `UA_Client_Service_read` to read
	*/
	UA_ReadResponse_init(&resp);
	resp = UA_Client_Service_read(clt, req);
/*	if(resp.responseHeader.serviceResult == UA_STATUSCODE_GOOD &&
		resp.resultsSize > 0 &&
		resp.results[0].hasValue &&
		UA_Variant_isScalar(&resp.results[0].value) &&
		resp.results[0].value.type == &UA_TYPES[UA_TYPES_INT32])
	{*/
	if(resp.responseHeader.serviceResult == UA_STATUSCODE_GOOD &&
		resp.resultsSize > 0 &&
		resp.results[0].hasValue &&
		UA_Variant_isScalar(&resp.results[0].value) &&
		resp.results[0].value.type == &UA_TYPES[UA_TYPES_STRING])
	{
		UA_String *str = (UA_String *)resp.results[0].value.data;
		printf("The string : %s\n", str->data);
		/*
		UA_Int32 *val = (UA_Int32 *)resp.results[0].value.data;
		printf("The value is: %d\n", *val);*/
	}
	/*
	 * Step 5.
	 *	free resource
	*/
	UA_ReadRequest_deleteMembers(&req);
	UA_ReadResponse_deleteMembers(&resp);
	UA_Client_disconnect(clt);
	UA_Client_delete(clt);
	
	return UA_STATUSCODE_GOOD;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq 0x2df1(%rip), %rax      # 0x3fe8
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x1050
movq %rax, %rbx
leaq 0xde5(%rip), %rsi       # 0x2004
movq %rax, %rdi
callq 0x1030
movl %eax, %r14d
testl %eax, %eax
jne 0x138a
xorps %xmm0, %xmm0
leaq -0x160(%rbp), %r12
movaps %xmm0, 0x70(%r12)
movaps %xmm0, 0x60(%r12)
movaps %xmm0, 0x50(%r12)
movaps %xmm0, 0x40(%r12)
movaps %xmm0, 0x30(%r12)
movaps %xmm0, 0x20(%r12)
movaps %xmm0, 0x10(%r12)
movaps %xmm0, (%r12)
movq 0x2d6e(%rip), %r15      # 0x3fe0
leaq 0xa78(%r15), %rsi
movl $0x1, %edi
callq 0x1040
movq %rax, %r13
movq %rax, 0x88(%r12)
movq $0x1, 0x80(%r12)
leaq 0xd7d(%rip), %rdi       # 0x201e
callq 0x10c0
movw $0x1, (%r13)
movl $0x3, 0x4(%r13)
movq %rax, 0x8(%r13)
movq %rdx, 0x10(%r13)
movl $0xd, 0x18(%r13)
leaq -0xd0(%rbp), %rdi
movl $0xa8, %edx
xorl %esi, %esi
callq 0x1080
leaq -0x1f0(%rbp), %r13
movl $0x90, %edx
movq %r13, %rdi
movq %r12, %rsi
callq 0x10a0
leaq 0x1400(%r15), %r12
addq $0x13b0, %r15           # imm = 0x13B0
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
leaq -0xd0(%rbp), %r13
movq %r13, %rcx
movq %r15, %r8
callq 0x10d0
cmpl $0x0, 0xc(%r13)
jne 0x1364
cmpq $0x0, -0x48(%rbp)
je 0x1364
movq -0x40(%rbp), %rax
testb $0x1, (%rax)
je 0x1364
cmpq $0x0, 0x18(%rax)
jne 0x1364
movq 0x20(%rax), %rcx
cmpq $0x2, %rcx
jb 0x1364
movl $0x1b8, %edx            # imm = 0x1B8
addq 0x2c94(%rip), %rdx      # 0x3fe0
cmpq %rdx, 0x8(%rax)
jne 0x1364
movq 0x8(%rcx), %rsi
leaq 0xccc(%rip), %rdi       # 0x2029
xorl %eax, %eax
callq 0x1070
leaq -0x160(%rbp), %rdi
movq %r12, %rsi
callq 0x1060
leaq -0xd0(%rbp), %rdi
movq %r15, %rsi
callq 0x1060
movq %rbx, %rdi
callq 0x1090
movq %rbx, %rdi
callq 0x10b0
movl %r14d, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq