// File: /workspace/github_c_makefile_star2_O1/loversmile[P]sugarcrm/sugar_function.c
// Function: setLead
int setLead(struct soap *soap, const char *soap_endpoint, char *session, char *lead_id, SGLeadItem *lead_item, char **return_id)
{
	/* lead_id if NULL, added new , if not NULL, update*/
    char soap_action[128] = {0};
    memset(soap_action, 0, sizeof(soap_action));
    snprintf(soap_action, sizeof(soap_action), "%s/set_entry", soap_endpoint);
	
    struct name_USCOREvalue_USCORElist *setEntry_name_value_list = NULL;
    struct ns1__set_USCOREentryResponse *_param_9 = NULL;
    setEntry_name_value_list = (struct name_USCOREvalue_USCORElist *)malloc(sizeof(struct name_USCOREvalue_USCORElist));
    _param_9 = (struct ns1__set_USCOREentryResponse *)malloc(sizeof(struct ns1__set_USCOREentryResponse));
    int item = 0;
    setEntry_name_value_list->__ptr = (struct ns1__name_USCOREvalue**)malloc(PTR_SIZE);
    setEntry_name_value_list->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
    setEntry_name_value_list->__ptr[item]->name = strdup("title");
    setEntry_name_value_list->__ptr[item++]->value = strdup(lead_item->title ? lead_item->title : "");
    setEntry_name_value_list->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
    setEntry_name_value_list->__ptr[item]->name = strdup("first_name");
    setEntry_name_value_list->__ptr[item++]->value = strdup(lead_item->first_name ? lead_item->first_name : "");
    setEntry_name_value_list->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
    setEntry_name_value_list->__ptr[item]->name = strdup("last_name");
    setEntry_name_value_list->__ptr[item++]->value = strdup(lead_item->last_name ? lead_item->last_name : "");
    setEntry_name_value_list->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
    setEntry_name_value_list->__ptr[item]->name = strdup("phone_home");
    setEntry_name_value_list->__ptr[item++]->value = strdup(lead_item->phone_home ? lead_item->phone_home : "");  
    setEntry_name_value_list->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
    setEntry_name_value_list->__ptr[item]->name = strdup("phone_mobile");
    setEntry_name_value_list->__ptr[item++]->value = strdup(lead_item->phone_mobile ? lead_item->phone_mobile : "");
    setEntry_name_value_list->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
    setEntry_name_value_list->__ptr[item]->name = strdup("phone_work");
    setEntry_name_value_list->__ptr[item++]->value = strdup(lead_item->phone_work ? lead_item->phone_work : "");
    setEntry_name_value_list->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
    setEntry_name_value_list->__ptr[item]->name = strdup("phone_other");
    setEntry_name_value_list->__ptr[item++]->value = strdup(lead_item->phone_other ? lead_item->phone_other : "");
    setEntry_name_value_list->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
    setEntry_name_value_list->__ptr[item]->name = strdup("phone_fax");
    setEntry_name_value_list->__ptr[item++]->value = strdup(lead_item->phone_fax ? lead_item->phone_fax : "");
    setEntry_name_value_list->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
    setEntry_name_value_list->__ptr[item]->name = strdup("description");
    setEntry_name_value_list->__ptr[item++]->value = strdup(lead_item->description ? lead_item->description : "");
    if (lead_id != NULL && strlen(lead_id) > 0) {
        setEntry_name_value_list->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
        setEntry_name_value_list->__ptr[item]->name = strdup("id");
        setEntry_name_value_list->__ptr[item++]->value = strdup(lead_id);
    } 
    setEntry_name_value_list->__size = item;
    
    int ret = setEntry(soap, soap_endpoint, soap_action, session, "Contacts", setEntry_name_value_list, _param_9);
        printf("8*****\n");
    if (ret == SOAP_OK) {
        printf("Success setContact!\n");
        //snprintf(set_entry_res_id, sizeof(set_entry_res_id), "%s\0\n", _param_9->return_->id);
        *return_id = strdup(_param_9->return_->id);
    } else {
        printf("ret = %d\n", ret);
        soap_print_fault(soap, stderr);
        //goto end;
    }
    int j = 0;
	for(j = 0; j < item; j++)
	{
		SAFE_FREE(setEntry_name_value_list->__ptr[j]->name);
		SAFE_FREE(setEntry_name_value_list->__ptr[j]->value);
		SAFE_FREE(setEntry_name_value_list->__ptr[j]);
	}
	SAFE_FREE(setEntry_name_value_list->__ptr);
	SAFE_FREE(setEntry_name_value_list);
    SAFE_FREE(_param_9);
    return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r9, 0x8(%rsp)
movq %r8, %r13
movq %rcx, %r15
movq %rdx, 0x18(%rsp)
movq %rsi, %rcx
movq %rdi, 0x20(%rsp)
xorps %xmm0, %xmm0
leaq 0x30(%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 0x4fcc(%rip), %rdx      # 0x540f7
movl $0x80, %esi
movq %rcx, 0x10(%rsp)
xorl %eax, %eax
callq 0x3150
movl $0x10, %edi
callq 0x3280
movq %rax, %r14
movl $0x8, %edi
callq 0x3280
movq %rax, 0x28(%rsp)
movl $0x40, %edi
callq 0x3280
movq %rax, %r12
movq %rax, (%r14)
movl $0x10, %edi
callq 0x3280
movq %rax, %rbp
movq %rax, (%r12)
leaq 0x5021(%rip), %rdi      # 0x541a1
callq 0x3380
movq %rax, (%rbp)
movq (%r13), %rdi
testq %rdi, %rdi
leaq 0x359b(%rip), %rbx      # 0x52732
cmoveq %rbx, %rdi
callq 0x3380
movq %rax, 0x8(%rbp)
movl $0x10, %edi
callq 0x3280
movq %rax, %rbp
movq %rax, 0x8(%r12)
leaq 0x4fea(%rip), %rdi      # 0x541a7
callq 0x3380
movq %rax, (%rbp)
movq 0x8(%r13), %rdi
testq %rdi, %rdi
cmoveq %rbx, %rdi
callq 0x3380
movq %rax, 0x8(%rbp)
movl $0x10, %edi
callq 0x3280
movq %rax, %rbp
movq %rax, 0x10(%r12)
leaq 0x4fbf(%rip), %rdi      # 0x541b2
callq 0x3380
movq %rax, (%rbp)
movq 0x10(%r13), %rdi
testq %rdi, %rdi
cmoveq %rbx, %rdi
callq 0x3380
movq %rax, 0x8(%rbp)
movl $0x10, %edi
callq 0x3280
movq %rax, %rbp
movq %rax, 0x18(%r12)
leaq 0x4e37(%rip), %rdi      # 0x54060
callq 0x3380
movq %rax, (%rbp)
movq 0x18(%r13), %rdi
testq %rdi, %rdi
cmoveq %rbx, %rdi
callq 0x3380
movq %rax, 0x8(%rbp)
movl $0x10, %edi
callq 0x3280
movq %rax, %rbp
movq %rax, 0x20(%r12)
leaq 0x4e17(%rip), %rdi      # 0x54076
callq 0x3380
movq %rax, (%rbp)
movq 0x20(%r13), %rdi
testq %rdi, %rdi
cmoveq %rbx, %rdi
callq 0x3380
movq %rax, 0x8(%rbp)
movl $0x10, %edi
callq 0x3280
movq %rax, %rbp
movq %rax, 0x28(%r12)
leaq 0x4dd6(%rip), %rdi      # 0x5406b
callq 0x3380
movq %rax, (%rbp)
movq 0x28(%r13), %rdi
testq %rdi, %rdi
cmoveq %rbx, %rdi
callq 0x3380
movq %rax, 0x8(%rbp)
movl $0x10, %edi
callq 0x3280
movq %rax, %rbp
movq %rax, 0x30(%r12)
leaq 0x4ef1(%rip), %rdi      # 0x541bc
callq 0x3380
movq %rax, (%rbp)
movq 0x30(%r13), %rdi
testq %rdi, %rdi
cmoveq %rbx, %rdi
callq 0x3380
movq %rax, 0x8(%rbp)
movl $0x10, %edi
callq 0x3280
movq %rax, %rbp
movq %rax, 0x38(%r12)
leaq 0x4ec7(%rip), %rdi      # 0x541c8
callq 0x3380
movq %rax, (%rbp)
movq 0x38(%r13), %rdi
testq %rdi, %rdi
cmoveq %rbx, %rdi
callq 0x3380
movq %rax, 0x8(%rbp)
movl $0x10, %edi
callq 0x3280
movq %rax, %rbp
movq %rax, 0x40(%r12)
leaq 0x23b9(%rip), %rdi      # 0x516f0
callq 0x3380
movq %rax, (%rbp)
movq 0x40(%r13), %rdi
testq %rdi, %rdi
cmoveq %rbx, %rdi
callq 0x3380
movq %rax, 0x8(%rbp)
movl $0x9, %ebx
testq %r15, %r15
je 0x4f397
cmpb $0x0, (%r15)
je 0x4f397
movl $0x10, %edi
callq 0x3280
movq %rax, %r13
movq %rax, 0x48(%r12)
leaq 0x24cd(%rip), %rdi      # 0x5184a
callq 0x3380
movq %rax, (%r13)
movq %r15, %rdi
callq 0x3380
movq %rax, 0x8(%r13)
movl $0xa, %ebx
movl %ebx, 0x8(%r14)
movq 0x28(%rsp), %r12
movq %r12, (%rsp)
leaq 0x4cac(%rip), %r8       # 0x54057
leaq 0x30(%rsp), %rdx
movq 0x20(%rsp), %r15
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movq %r14, %r9
callq 0x34a66
movl %eax, %ebp
leaq 0x4f3a(%rip), %rdi      # 0x5430d
callq 0x30a0
testl %ebp, %ebp
je 0x4f400
leaq 0x49d5(%rip), %rdi      # 0x53db8
movl %ebp, %esi
xorl %eax, %eax
callq 0x3140
movq 0x22c05(%rip), %rax     # 0x71ff8
movq (%rax), %rsi
movq %r15, %rdi
callq 0x4b1d6
jmp 0x4f420
leaq 0x4f0d(%rip), %rdi      # 0x54314
callq 0x30a0
movq (%r12), %rax
movq (%rax), %rdi
callq 0x3380
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
movl %ebx, %ebx
xorl %r15d, %r15d
movq (%r14), %rax
movq (%rax,%r15,8), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x4f447
callq 0x3030
movq (%r14), %rax
movq (%rax,%r15,8), %rax
movq $0x0, (%rax)
movq (%r14), %rax
movq (%rax,%r15,8), %rax
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0x4f46b
callq 0x3030
movq (%r14), %rax
movq (%rax,%r15,8), %rax
movq $0x0, 0x8(%rax)
movq (%r14), %rax
movq (%rax,%r15,8), %rdi
testq %rdi, %rdi
je 0x4f487
callq 0x3030
movq (%r14), %rax
movq $0x0, (%rax,%r15,8)
incq %r15
cmpq %r15, %rbx
jne 0x4f425
movq (%r14), %rdi
testq %rdi, %rdi
je 0x4f4a3
callq 0x3030
movq $0x0, (%r14)
movq %r14, %rdi
callq 0x3030
testq %r12, %r12
je 0x4f4b8
movq %r12, %rdi
callq 0x3030
movl %ebp, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq