// File: /workspace/github_c_makefile_star2_O2/loversmile[P]sugarcrm/sugar_function.c
// Function: setContactRelations
int setContactRelations(struct soap * soap,const char * soap_endpoint,char * session, SGContactsID *contacts_id, 
								char *link_name, SGLinksID *links_id, int num, SGLinkReturn *link_return)
{
	char soap_action[128] = {0};
    memset(soap_action, 0, sizeof(soap_action));
    snprintf(soap_action, sizeof(soap_action), "%s/set_relationships", soap_endpoint);
	struct select_USCOREfields *module_USCOREnames = NULL;
	struct select_USCOREfields *module_USCOREids = NULL;
	struct select_USCOREfields *link_USCOREfield_USCOREnames = NULL;
	struct new_USCOREset_USCORErelationhip_USCOREids *related_USCOREids = NULL;
	struct deleted_USCOREarray *delete_USCOREarray = NULL;
	SGContactsID *tmp_contacts_id = contacts_id;
	SGLinksID *tmp_links_id = links_id;
	module_USCOREnames = (struct select_USCOREfields *)malloc(sizeof(struct select_USCOREfields));
	module_USCOREids = (struct select_USCOREfields *)malloc(sizeof(struct select_USCOREfields));
	link_USCOREfield_USCOREnames = (struct select_USCOREfields *)malloc(sizeof(struct select_USCOREfields));
	related_USCOREids = (struct new_USCOREset_USCORErelationhip_USCOREids *)malloc(sizeof(struct new_USCOREset_USCORErelationhip_USCOREids));
	module_USCOREnames->__ptr =  (char **)malloc(PTR_SIZE * PTR_SIZE);
	module_USCOREids->__ptr = (char **)malloc(PTR_SIZE * PTR_SIZE);
	link_USCOREfield_USCOREnames->__ptr = (char **)malloc(PTR_SIZE * PTR_SIZE);
	related_USCOREids->__ptr = (struct select_USCOREfields **)malloc(sizeof(struct select_USCOREfields*));

	//related_USCOREids->__size = 1;
	
	int i = 0;

	for (i = 0; i < num; i++)
	{
		if (tmp_contacts_id && tmp_contacts_id->id &&
			tmp_links_id && tmp_links_id->id)
		{
			module_USCOREnames->__ptr[i] = strdup("Contacts");

			link_USCOREfield_USCOREnames->__ptr[i] = strdup(link_name);

			module_USCOREids->__ptr[i] = strdup(tmp_contacts_id->id);

			related_USCOREids->__ptr[i] = (struct select_USCOREfields *)malloc(sizeof(struct select_USCOREfields));
			related_USCOREids->__ptr[i]->__ptr = (char **)malloc(PTR_SIZE * PTR_SIZE);
			related_USCOREids->__ptr[i]->__ptr[0] = strdup(tmp_links_id->id);

			module_USCOREnames->__size = i + 1;
			link_USCOREfield_USCOREnames->__size = i + 1;
			module_USCOREids->__size = i + 1;
			related_USCOREids->__size = i + 1;
			related_USCOREids->__ptr[i]->__size = 1;
			tmp_contacts_id = tmp_contacts_id->next;
			tmp_links_id = tmp_links_id->next;
		}
	}

	struct ns1__set_USCORErelationshipsResponse *_param_7 = NULL;
	_param_7 = (struct ns1__set_USCORErelationshipsResponse *)malloc(sizeof(struct ns1__set_USCORErelationshipsResponse));
	int ret = setRelationships(soap, soap_endpoint, soap_action, session, module_USCOREnames,
				module_USCOREids, link_USCOREfield_USCOREnames, related_USCOREids,  NULL, 
				delete_USCOREarray, _param_7);
	if (ret == SOAP_OK)
	{
        printf("setContactRelations Success!!!!\n");
	}
	int j = 0;
	for (j = 0; j < num; j++)
	{
		SAFE_FREE(module_USCOREnames->__ptr[j]);
		SAFE_FREE(link_USCOREfield_USCOREnames->__ptr[j]);
		SAFE_FREE(module_USCOREids->__ptr[j]);
		SAFE_FREE(related_USCOREids->__ptr[j]->__ptr[0]);
		SAFE_FREE(related_USCOREids->__ptr[j]->__ptr);
		SAFE_FREE(related_USCOREids->__ptr[j]);
	}
	SAFE_FREE(related_USCOREids->__ptr);
	SAFE_FREE(related_USCOREids);
	SAFE_FREE(link_USCOREfield_USCOREnames->__ptr);
	SAFE_FREE(link_USCOREfield_USCOREnames);
	SAFE_FREE(module_USCOREids->__ptr);
	SAFE_FREE(module_USCOREids);
	SAFE_FREE(module_USCOREnames->__ptr);
	SAFE_FREE(module_USCOREnames);
	SAFE_FREE(_param_7);
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %r9, %r13
movq %r8, 0x30(%rsp)
movq %rcx, %rbp
movq %rdx, 0x60(%rsp)
movq %rsi, %rcx
movq %rdi, 0x50(%rsp)
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %rdi
movaps %xmm0, 0x70(%rdi)
movaps %xmm0, 0x60(%rdi)
movaps %xmm0, 0x50(%rdi)
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
leaq 0x605b(%rip), %rdx      # 0x4f18c
xorl %r15d, %r15d
movl $0x80, %esi
movq %rcx, 0x58(%rsp)
xorl %eax, %eax
callq 0x3150
pushq $0x10
popq %r14
movq %r14, %rdi
callq 0x3290
movq %rax, %rbx
movq %r14, %rdi
callq 0x3290
movq %rax, 0x48(%rsp)
movq %r14, %rdi
callq 0x3290
movq %rax, 0x28(%rsp)
movq %r14, %rdi
callq 0x3290
movq %rax, %r12
movl $0x1000, %edi           # imm = 0x1000
callq 0x3290
movq %rbx, 0x38(%rsp)
movq %rax, 0x78(%rsp)
movq %rax, (%rbx)
movl $0x1000, %edi           # imm = 0x1000
callq 0x3290
movq 0x48(%rsp), %rcx
movq %rcx, %r14
movq %rax, 0x70(%rsp)
movq %rax, (%rcx)
movl $0x1000, %edi           # imm = 0x1000
callq 0x3290
movq %rax, 0x68(%rsp)
movq 0x28(%rsp), %rcx
movq %rax, (%rcx)
pushq $0x8
popq %rdi
callq 0x3290
movq %rax, %rbx
movq %rax, (%r12)
movl 0x140(%rsp), %eax
testl %eax, %eax
cmovlel %r15d, %eax
movq %rax, 0x40(%rsp)
cmpq %r15, 0x40(%rsp)
je 0x492c4
testq %rbp, %rbp
je 0x492ba
cmpq $0x0, (%rbp)
setne %al
testq %r13, %r13
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x492bc
cmpq $0x0, (%r13)
je 0x492bc
leaq 0x5e36(%rip), %rdi      # 0x4f057
callq 0x33a0
movq 0x78(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
movq 0x30(%rsp), %rdi
callq 0x33a0
movq 0x68(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
movq (%rbp), %rdi
callq 0x33a0
movq 0x70(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
pushq $0x10
popq %rdi
callq 0x3290
movq %rax, (%rbx,%r15,8)
movl $0x1000, %edi           # imm = 0x1000
callq 0x3290
movq (%r12), %rbx
movq (%rbx,%r15,8), %rcx
movq %rax, (%rcx)
movq (%r13), %rdi
callq 0x33a0
movq (%rbx,%r15,8), %rcx
movq (%rcx), %rcx
movq %rax, (%rcx)
leal 0x1(%r15), %eax
movq 0x38(%rsp), %rcx
movl %eax, 0x8(%rcx)
movq 0x28(%rsp), %rcx
movl %eax, 0x8(%rcx)
movl %eax, 0x8(%r14)
movl %eax, 0x8(%r12)
movq (%rbx,%r15,8), %rax
movl $0x1, 0x8(%rax)
movq 0x8(%rbp), %rbp
movq 0x8(%r13), %r13
jmp 0x492bc
xorl %ebp, %ebp
incq %r15
jmp 0x491e2
pushq $0x8
popq %rdi
callq 0x3290
movq %rax, 0x30(%rsp)
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movq %r12, 0x8(%rsp)
movq 0x28(%rsp), %r13
movq %r13, (%rsp)
leaq 0x80(%rsp), %rdx
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rcx
movq 0x38(%rsp), %r15
movq %r15, %r8
movq %r14, %r9
callq 0x31663
movl %eax, %ebp
testl %eax, %eax
jne 0x49325
leaq 0x5fcd(%rip), %rdi      # 0x4f2ed
callq 0x30a0
xorl %ebx, %ebx
cmpq %rbx, 0x40(%rsp)
movq %r14, %rcx
je 0x493fb
movq (%r15), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x49351
callq 0x3030
movq %r14, %rcx
movq (%r15), %rax
andq $0x0, (%rax,%rbx,8)
movq (%r13), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x4936f
callq 0x3030
movq %r14, %rcx
movq (%r13), %rax
andq $0x0, (%rax,%rbx,8)
movq (%rcx), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x4938c
movq %rcx, %r13
callq 0x3030
movq (%r13), %rax
andq $0x0, (%rax,%rbx,8)
movq (%r12), %rax
movq (%rax,%rbx,8), %rax
movq (%rax), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x493c3
callq 0x3030
movq (%r12), %rax
movq (%rax,%rbx,8), %rax
movq (%rax), %rax
andq $0x0, (%rax)
movq (%r12), %rax
movq (%rax,%rbx,8), %rdi
movq (%rdi), %rax
testq %rax, %rax
je 0x493db
movq %rax, %rdi
callq 0x3030
movq (%r12), %rax
movq (%rax,%rbx,8), %rcx
andq $0x0, (%rcx)
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
movq 0x28(%rsp), %r13
je 0x493f3
callq 0x3030
movq (%r12), %rax
andq $0x0, (%rax,%rbx,8)
incq %rbx
jmp 0x49327
movq (%r12), %rdi
movq %rcx, %rbx
callq 0x3030
movq %r12, %rdi
callq 0x3030
movq (%r13), %rdi
callq 0x3030
movq %r13, %rdi
callq 0x3030
movq (%rbx), %rdi
callq 0x3030
movq %rbx, %rdi
callq 0x3030
movq (%r15), %rdi
callq 0x3030
movq %r15, %rdi
callq 0x3030
movq 0x30(%rsp), %rdi
callq 0x3030
movl %ebp, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq