// File: /workspace/github_c_makefile_star2_O3/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, 0x38(%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 0x6055(%rip), %rdx      # 0x5418c
movl $0x80, %esi
movq %rcx, 0x58(%rsp)
xorl %eax, %eax
callq 0x3150
movl $0x10, %edi
callq 0x3290
movq %rax, %rbx
movl $0x10, %edi
callq 0x3290
movq %rax, %r14
movl $0x10, %edi
callq 0x3290
movq %rax, %r15
movl $0x10, %edi
callq 0x3290
movq %rax, %r12
movl $0x1000, %edi           # imm = 0x1000
callq 0x3290
movq %rbx, 0x48(%rsp)
movq %rax, 0x78(%rsp)
movq %rax, (%rbx)
movl $0x1000, %edi           # imm = 0x1000
callq 0x3290
movq %r14, 0x30(%rsp)
movq %rax, 0x70(%rsp)
movq %rax, (%r14)
movl $0x1000, %edi           # imm = 0x1000
callq 0x3290
movq %r15, 0x40(%rsp)
movq %rax, 0x68(%rsp)
movq %rax, (%r15)
movl $0x8, %edi
callq 0x3290
movq %rax, %rbx
movq %rax, (%r12)
movl 0x140(%rsp), %eax
movl %eax, %r14d
testl %eax, %eax
jle 0x4e2c8
xorl %r15d, %r15d
testq %rbp, %rbp
je 0x4e2ba
cmpq $0x0, (%rbp)
setne %al
testq %r13, %r13
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x4e2bc
cmpq $0x0, (%r13)
je 0x4e2bc
leaq 0x5e3c(%rip), %rdi      # 0x54057
callq 0x3390
movq 0x78(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
movq 0x38(%rsp), %rdi
callq 0x3390
movq 0x68(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
movq (%rbp), %rdi
callq 0x3390
movq 0x70(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
movl $0x10, %edi
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 0x3390
movq (%rbx,%r15,8), %rcx
movq (%rcx), %rcx
movq %rax, (%rcx)
leal 0x1(%r15), %eax
movq 0x48(%rsp), %rcx
movl %eax, 0x8(%rcx)
movq 0x40(%rsp), %rcx
movl %eax, 0x8(%rcx)
movq 0x30(%rsp), %rcx
movl %eax, 0x8(%rcx)
movl %eax, 0x8(%r12)
movq (%rbx,%r15,8), %rax
movl $0x1, 0x8(%rax)
movq 0x8(%rbp), %rbp
movq 0x8(%r13), %r13
jmp 0x4e2bc
xorl %ebp, %ebp
incq %r15
cmpq %r15, %r14
jne 0x4e1e7
movl $0x8, %edi
callq 0x3290
movq %rax, %r13
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movq %r12, 0x8(%rsp)
movq 0x40(%rsp), %rbp
movq %rbp, (%rsp)
leaq 0x80(%rsp), %rdx
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rcx
movq 0x48(%rsp), %r15
movq %r15, %r8
movq 0x30(%rsp), %r9
callq 0x34837
movl %eax, 0x38(%rsp)
testl %eax, %eax
jne 0x4e32d
leaq 0x5fc5(%rip), %rdi      # 0x542ed
callq 0x30a0
cmpl $0x0, 0x140(%rsp)
jle 0x4e416
xorl %ebx, %ebx
movq (%r15), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x4e359
callq 0x3030
movq (%r15), %rax
movq $0x0, (%rax,%rbx,8)
movq (%rbp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x4e377
callq 0x3030
movq (%rbp), %rax
movq $0x0, (%rax,%rbx,8)
movq 0x30(%rsp), %rbp
movq (%rbp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x4e39a
callq 0x3030
movq (%rbp), %rax
movq $0x0, (%rax,%rbx,8)
movq (%r12), %rax
movq (%rax,%rbx,8), %rax
movq (%rax), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x4e3d4
callq 0x3030
movq (%r12), %rax
movq (%rax,%rbx,8), %rax
movq (%rax), %rax
movq $0x0, (%rax)
movq (%r12), %rax
movq (%rax,%rbx,8), %rdi
movq (%rdi), %rax
testq %rax, %rax
je 0x4e3ef
movq %rax, %rdi
callq 0x3030
movq (%r12), %rax
movq (%rax,%rbx,8), %rcx
movq $0x0, (%rcx)
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
movq 0x40(%rsp), %rbp
je 0x4e40a
callq 0x3030
movq (%r12), %rax
movq $0x0, (%rax,%rbx,8)
incq %rbx
cmpq %rbx, %r14
jne 0x4e33d
movq (%r12), %rdi
testq %rdi, %rdi
je 0x4e424
callq 0x3030
movq %r12, %rdi
callq 0x3030
movq (%rbp), %rdi
testq %rdi, %rdi
movq 0x30(%rsp), %rbx
je 0x4e43f
callq 0x3030
movq %rbp, %rdi
callq 0x3030
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x4e454
callq 0x3030
movq %rbx, %rdi
callq 0x3030
movq (%r15), %rdi
testq %rdi, %rdi
je 0x4e469
callq 0x3030
movq %r15, %rdi
callq 0x3030
testq %r13, %r13
je 0x4e47e
movq %r13, %rdi
callq 0x3030
movl 0x38(%rsp), %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq