// File: /workspace/github_c_makefile_star2_O2/loversmile[P]sugarcrm/sugar_function.c
// Function: setCalls
int setCalls(struct soap *soap, const char *soap_endpoint, char *session, SGCallsItem *calls_item, SGReturnCallsID *return_calls_id)
{
    char soap_action[128] = {0};
    memset(soap_action, 0, sizeof(soap_action));
    snprintf(soap_action, sizeof(soap_action), "%s/set_entries", soap_endpoint);
    
    //struct name_USCOREvalue_USCORElist *setEntry_name_value_list = NULL;
    struct name_USCOREvalue_USCORElists *setEntries_name_value_lists = NULL;
    //struct ns1__set_USCOREentryResponse *_param_9 = NULL;
    struct ns1__set_USCOREentriesResponse *_param_10 = NULL;
    setEntries_name_value_lists = (struct name_USCOREvalue_USCORElists *)malloc(sizeof(struct name_USCOREvalue_USCORElists));
    //setEntry_name_value_list = (struct name_USCOREvalue_USCORElist *)soap_malloc(soap, sizeof(struct name_USCOREvalue_USCORElist));
    _param_10 = (struct ns1__set_USCOREentriesResponse *)malloc(sizeof(struct ns1__set_USCOREentriesResponse));
	setEntries_name_value_lists->__ptr = (struct name_USCOREvalue_USCORElist **)malloc(PTR_SIZE * PTR_SIZE);
    SGCallsItem *calls_tmp = calls_item;
    //struct call_item *tmp = NULL;
    //for (calls_tmp = NULL; tmp = calls_tmp->call_item; tmp = calls_tmp)
    int items = 0;
	int item = 0;
    while(calls_tmp) {
        calls_tmp = calls_tmp->next;
        item = 0;
        setEntries_name_value_lists->__ptr[items]->__ptr = (struct ns1__name_USCOREvalue**)malloc(PTR_SIZE);
        setEntries_name_value_lists->__ptr[items]->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
        setEntries_name_value_lists->__ptr[items]->__ptr[item]->name = strdup("name");
        setEntries_name_value_lists->__ptr[items]->__ptr[item++]->value = strdup(calls_tmp->call_item->name ? calls_tmp->call_item->name : "");
        setEntries_name_value_lists->__ptr[items]->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
        setEntries_name_value_lists->__ptr[items]->__ptr[item]->name = strdup("parent_type");
        setEntries_name_value_lists->__ptr[items]->__ptr[item++]->value = strdup(calls_tmp->call_item->parent_type ? calls_tmp->call_item->parent_type : "");
        setEntries_name_value_lists->__ptr[items]->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
        setEntries_name_value_lists->__ptr[items]->__ptr[item]->name = strdup("parent_id");
        setEntries_name_value_lists->__ptr[items]->__ptr[item++]->value = strdup(calls_tmp->call_item->parent_id ? calls_tmp->call_item->parent_id : "");
        setEntries_name_value_lists->__ptr[items]->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
        setEntries_name_value_lists->__ptr[items]->__ptr[item]->name = strdup("direction");
        setEntries_name_value_lists->__ptr[items]->__ptr[item++]->value = strdup(calls_tmp->call_item->direction ? calls_tmp->call_item->direction : "");  
        setEntries_name_value_lists->__ptr[items]->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
        setEntries_name_value_lists->__ptr[items]->__ptr[item]->name = strdup("description");
        setEntries_name_value_lists->__ptr[items]->__ptr[item++]->value = strdup(calls_tmp->call_item->description ? calls_tmp->call_item->description : "");
        setEntries_name_value_lists->__ptr[items]->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
        setEntries_name_value_lists->__ptr[items]->__ptr[item]->name = strdup("duration_minutes");
        setEntries_name_value_lists->__ptr[items]->__ptr[item++]->value = strdup(calls_tmp->call_item->duration_minutes ? calls_tmp->call_item->duration_minutes : "");
        setEntries_name_value_lists->__ptr[items]->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
        setEntries_name_value_lists->__ptr[items]->__ptr[item]->name = strdup("duration_hours");
        setEntries_name_value_lists->__ptr[items]->__ptr[item++]->value = strdup(calls_tmp->call_item->duration_hours ? calls_tmp->call_item->duration_hours : "");
        setEntries_name_value_lists->__ptr[items]->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
        setEntries_name_value_lists->__ptr[items]->__ptr[item]->name = strdup("date_start");
        setEntries_name_value_lists->__ptr[items]->__ptr[item++]->value = strdup(calls_tmp->call_item->date_start ? calls_tmp->call_item->date_start : "");
        setEntries_name_value_lists->__ptr[items]->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
        setEntries_name_value_lists->__ptr[items]->__ptr[item]->name = strdup("assigned_user_id");
        setEntries_name_value_lists->__ptr[items]->__ptr[item++]->value = strdup(calls_tmp->call_item->assigned_user_id ? calls_tmp->call_item->assigned_user_id : "");
        if (calls_tmp->call_id != NULL && strlen(calls_tmp->call_id) > 0) {
            setEntries_name_value_lists->__ptr[items]->__ptr[item] = (struct ns1__name_USCOREvalue*)malloc(sizeof(struct ns1__name_USCOREvalue));
            setEntries_name_value_lists->__ptr[items]->__ptr[item]->name = strdup("id");
            setEntries_name_value_lists->__ptr[items]->__ptr[item++]->value = strdup(calls_tmp->call_id);
        } 
        setEntries_name_value_lists->__ptr[items]->__size = item;
        items++;
    }
    
    
    int ret = setEntries(soap, soap_endpoint, soap_action, session, "Calls", setEntries_name_value_lists, _param_10);
    if (ret == SOAP_OK) {
        printf("Success setEntry!\n");
        //snprintf(set_entry_res_id, sizeof(set_entry_res_id), "%s\0\n", _param_9->return_->id);
        //*return_id = strdup(_param_10->return_->ids->__ptr);
        SGReturnCallsID *tmp_return_calls_id = return_calls_id;
        for (int i = 0; i < _param_10->return_->ids->__size; i++) {
            printf("_param_10->return_->ids->__ptr = %s\n", _param_10->return_->ids->__ptr[i]);
			tmp_return_calls_id = initSGReturnCallsID(tmp_return_calls_id);
			tmp_return_calls_id->return_call_id = strdup(_param_10->return_->ids->__ptr[i]);
			tmp_return_calls_id = tmp_return_calls_id->next;
        }
    } else {
        printf("ret = %d\n", ret);
        soap_print_fault(soap, stderr);
        //goto end;
    }
    int j = 0, k = 0;
	for (j = 0; j < items; j++)
	{
		for(k = 0; k < item; k++)
		{
			SAFE_FREE(setEntries_name_value_lists->__ptr[j]->__ptr[k]->name);
			SAFE_FREE(setEntries_name_value_lists->__ptr[j]->__ptr[k]->value);
			SAFE_FREE(setEntries_name_value_lists->__ptr[j]->__ptr[k]);
		}
		SAFE_FREE(setEntries_name_value_lists->__ptr[j]->__ptr);
		SAFE_FREE(setEntries_name_value_lists->__ptr[j]);
	}
	SAFE_FREE(setEntries_name_value_lists->__ptr);
	SAFE_FREE(setEntries_name_value_lists);
	SAFE_FREE(_param_10);
    return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rcx, %rbp
movq %rdx, 0x10(%rsp)
movq %rsi, %rcx
movq %rdi, 0x28(%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 0x68fc(%rip), %rdx      # 0x4f144
xorl %r14d, %r14d
movl $0x80, %esi
movq %rcx, 0x20(%rsp)
xorl %eax, %eax
callq 0x3150
pushq $0x10
popq %rdi
callq 0x3290
movq %rax, %rbx
pushq $0x8
popq %rdi
callq 0x3290
movq %rax, 0x18(%rsp)
movl $0x1000, %edi           # imm = 0x1000
callq 0x3290
movq %rax, %r13
movq %rax, (%rbx)
xorl %r12d, %r12d
pushq $0x10
popq %r15
testq %rbp, %rbp
je 0x48c09
movq 0x10(%rbp), %rbp
pushq $0x40
popq %rdi
callq 0x3290
movq (%r13,%r14,8), %rcx
movq %rax, (%rcx)
movq %r15, %rdi
callq 0x3290
movq (%r13,%r14,8), %rcx
movq (%rcx), %rcx
movq %rax, (%rcx)
leaq 0x3d41(%rip), %rdi      # 0x4c603
callq 0x33a0
movq (%r13,%r14,8), %rcx
movq (%rcx), %rcx
movq (%rcx), %rcx
movq %rax, (%rcx)
movq 0x8(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
leaq 0x4e4c(%rip), %rax      # 0x4d732
cmoveq %rax, %rdi
movq %rax, %r12
callq 0x33a0
movq (%r13,%r14,8), %rcx
movq (%rcx), %rcx
movq (%rcx), %rcx
movq %rax, 0x8(%rcx)
movq %r15, %rdi
callq 0x3290
movq (%r13,%r14,8), %rcx
movq (%rcx), %rcx
movq %rax, 0x8(%rcx)
leaq 0x67e8(%rip), %rdi      # 0x4f104
callq 0x33a0
movq (%r13,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x8(%rcx), %rcx
movq %rax, (%rcx)
movq 0x8(%rbp), %rax
movq 0x8(%rax), %rdi
testq %rdi, %rdi
cmoveq %r12, %rdi
callq 0x33a0
movq (%r13,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x8(%rcx), %rcx
movq %rax, 0x8(%rcx)
movq %r15, %rdi
callq 0x3290
movq (%r13,%r14,8), %rcx
movq (%rcx), %rcx
movq %rax, 0x10(%rcx)
leaq 0x67a1(%rip), %rdi      # 0x4f110
callq 0x33a0
movq (%r13,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x10(%rcx), %rcx
movq %rax, (%rcx)
movq 0x8(%rbp), %rax
movq 0x10(%rax), %rdi
testq %rdi, %rdi
cmoveq %r12, %rdi
callq 0x33a0
movq (%r13,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x10(%rcx), %rcx
movq %rax, 0x8(%rcx)
movq %r15, %rdi
callq 0x3290
movq (%r13,%r14,8), %rcx
movq (%rcx), %rcx
movq %rax, 0x18(%rcx)
leaq 0x6758(%rip), %rdi      # 0x4f11a
callq 0x33a0
movq (%r13,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x18(%rcx), %rcx
movq %rax, (%rcx)
movq 0x8(%rbp), %rax
movq 0x18(%rax), %rdi
testq %rdi, %rdi
cmoveq %r12, %rdi
callq 0x33a0
movq (%r13,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x18(%rcx), %rcx
movq %rax, 0x8(%rcx)
movq %r15, %rdi
callq 0x3290
movq (%r13,%r14,8), %rcx
movq (%rcx), %rcx
movq %rax, 0x20(%rcx)
leaq 0x3cdb(%rip), %rdi      # 0x4c6f0
callq 0x33a0
movq (%rbx), %r12
movq (%r12,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x20(%rcx), %rcx
movq %rax, (%rcx)
movq 0x8(%rbp), %rax
movq 0x20(%rax), %rdi
testq %rdi, %rdi
leaq 0x4cf5(%rip), %r13      # 0x4d732
cmoveq %r13, %rdi
callq 0x33a0
movq (%r12,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x20(%rcx), %rcx
movq %rax, 0x8(%rcx)
movq %r15, %rdi
callq 0x3290
movq (%r12,%r14,8), %rcx
movq (%rcx), %rcx
movq %rax, 0x28(%rcx)
leaq 0x66b5(%rip), %rdi      # 0x4f124
callq 0x33a0
movq (%r12,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x28(%rcx), %rcx
movq %rax, (%rcx)
movq 0x8(%rbp), %rax
movq 0x28(%rax), %rdi
testq %rdi, %rdi
cmoveq %r13, %rdi
callq 0x33a0
movq (%r12,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x28(%rcx), %rcx
movq %rax, 0x8(%rcx)
movq %r15, %rdi
callq 0x3290
movq (%r12,%r14,8), %rcx
movq (%rcx), %rcx
movq %rax, 0x30(%rcx)
leaq 0x6676(%rip), %rdi      # 0x4f135
callq 0x33a0
movq (%r12,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x30(%rcx), %rcx
movq %rax, (%rcx)
movq 0x8(%rbp), %rax
movq 0x30(%rax), %rdi
testq %rdi, %rdi
cmoveq %r13, %rdi
callq 0x33a0
movq (%r12,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x30(%rcx), %rcx
movq %rax, 0x8(%rcx)
movq %r15, %rdi
callq 0x3290
movq (%r12,%r14,8), %rcx
movq (%rcx), %rcx
movq %rax, 0x38(%rcx)
leaq 0x6580(%rip), %rdi      # 0x4f08f
callq 0x33a0
movq (%r12,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x38(%rcx), %rcx
movq %rax, (%rcx)
movq 0x8(%rbp), %rax
movq 0x38(%rax), %rdi
testq %rdi, %rdi
cmoveq %r13, %rdi
callq 0x33a0
movq (%r12,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x38(%rcx), %rcx
movq %rax, 0x8(%rcx)
movq %r15, %rdi
callq 0x3290
movq (%r12,%r14,8), %rcx
movq (%rcx), %rcx
movq %rax, 0x40(%rcx)
leaq 0x3a44(%rip), %rdi      # 0x4c5a3
callq 0x33a0
movq (%r12,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x40(%rcx), %rcx
movq %rax, (%rcx)
movq 0x8(%rbp), %rax
movq 0x40(%rax), %rdi
testq %rdi, %rdi
cmoveq %r13, %rdi
callq 0x33a0
movq (%r12,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x40(%rcx), %rcx
movq %rax, 0x8(%rcx)
movq (%rbp), %rax
testq %rax, %rax
je 0x48bf1
cmpb $0x0, (%rax)
movq (%rbx), %r13
je 0x48bf4
pushq $0x10
popq %rdi
callq 0x3290
movq (%r12,%r14,8), %rcx
movq (%rcx), %rcx
movq %rax, 0x48(%rcx)
leaq 0x3c8a(%rip), %rdi      # 0x4c84a
callq 0x33a0
movq (%r13,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x48(%rcx), %rcx
movq %rax, (%rcx)
movq (%rbp), %rdi
callq 0x33a0
movq (%r13,%r14,8), %rcx
movq (%rcx), %rcx
movq 0x48(%rcx), %rcx
movq %rax, 0x8(%rcx)
pushq $0xa
jmp 0x48bf6
movq (%rbx), %r13
pushq $0x9
popq %r12
movq (%r13,%r14,8), %rax
movl %r12d, 0x8(%rax)
incq %r14
jmp 0x4888b
movq 0x18(%rsp), %r15
movq %r15, (%rsp)
leaq 0x6470(%rip), %r8       # 0x4f089
leaq 0x30(%rsp), %rdx
movq 0x28(%rsp), %r13
movq %r13, %rdi
movq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rcx
movq %rbx, %r9
callq 0x31db8
testl %eax, %eax
movl %eax, 0x10(%rsp)
je 0x48d72
leaq 0x616d(%rip), %rdi      # 0x4edb8
movl %eax, %esi
xorl %eax, %eax
callq 0x3140
movq 0x2739d(%rip), %rax     # 0x6fff8
movq (%rax), %rsi
movq %r13, %rdi
callq 0x460f9
movl %r12d, %r15d
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x48d42
xorl %r13d, %r13d
movq (%rbx), %rax
movq (%rax,%r12,8), %rdi
movq (%rdi), %rax
cmpq %r13, %r15
je 0x48d0c
movq (%rax,%r13,8), %rdi
movq (%rdi), %rax
testq %rax, %rax
je 0x48cbc
movq %rax, %rdi
callq 0x3030
movq (%rbx), %rax
movq (%rax,%r12,8), %rcx
movq (%rcx), %rcx
movq (%rcx,%r13,8), %rcx
andq $0x0, (%rcx)
movq (%rax,%r12,8), %rax
movq (%rax), %rax
movq (%rax,%r13,8), %rdi
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x48cf0
movq %rax, %rdi
callq 0x3030
movq (%rbx), %rax
movq (%rax,%r12,8), %rcx
movq (%rcx), %rcx
movq (%rcx,%r13,8), %rcx
andq $0x0, 0x8(%rcx)
movq (%rax,%r12,8), %rax
movq (%rax), %rax
movq (%rax,%r13,8), %rdi
testq %rdi, %rdi
je 0x48d04
callq 0x3030
movq (%rbx), %rax
movq (%rax,%r12,8), %rax
movq (%rax), %rax
andq $0x0, (%rax,%r13,8)
incq %r13
jmp 0x48c78
testq %rax, %rax
je 0x48d2d
movq %rax, %rdi
callq 0x3030
movq (%rbx), %rax
movq (%rax,%r12,8), %rcx
andq $0x0, (%rcx)
movq (%rax,%r12,8), %rdi
testq %rdi, %rdi
je 0x48d3a
callq 0x3030
movq (%rbx), %rax
andq $0x0, (%rax,%r12,8)
incq %r12
jmp 0x48c6c
movq (%rbx), %rdi
callq 0x3030
movq %rbx, %rdi
callq 0x3030
movq 0x18(%rsp), %rdi
callq 0x3030
movl 0x10(%rsp), %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x652d(%rip), %rdi      # 0x4f2a6
callq 0x30a0
movq (%r15), %rax
movq (%rax), %r13
xorl %ebp, %ebp
movslq 0x8(%r13), %rax
cmpq %rax, %rbp
jge 0x48c66
movq (%r13), %rax
movq (%rax,%rbp,8), %rsi
leaq 0x63b1(%rip), %rdi      # 0x4f153
xorl %eax, %eax
callq 0x3140
callq 0x478c1
movq %rax, %r15
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq (%rax), %r13
movq (%r13), %rax
movq (%rax,%rbp,8), %rdi
callq 0x33a0
movq %rax, (%r15)
incq %rbp
jmp 0x48d86