// File: /workspace/github_c_makefile_star2_O2/xiaowenhuyuehu[P]remote_access/src/core/config_manager.c
// Function: init_cfg
CFG_STARTUP *init_cfg(char *pk, char *dn, char *ds)
{
	char *working_dir = NULL, *tmp = NULL;
	char *cfg_json = NULL;
	int len_val = 0;
	int type_val = 0;
    if(g_cfg != NULL){
        log_warning("configure is already exist."); 
        return g_cfg;
    }

    g_cfg = malloc(sizeof(CFG_STARTUP));
    if(g_cfg == NULL){
        log_error("failed to alloc memory for store configure info."); 
        return NULL;
    }

	working_dir = _get_current_work_dir();

	cfg_json = _load_cfg_from_json(working_dir, CFG_FILE_NAME);
	
	GET_STRING_VAL("cloud_ip", &g_cfg->cloud_ip);
	GET_STRING_VAL("cloud_port", &g_cfg->cloud_port);
	GET_STRING_VAL("cert_path", &g_cfg->cert_path);
	GET_STRING_VAL("listen_ip", &g_cfg->listen_ip);
	GET_INT_VAL("is_tls_on", &g_cfg->is_tls_on);
	GET_INT_VAL("listen_port", &g_cfg->listen_port);
	GET_INT_VAL("is_debug_on", &g_cfg->is_debug_on);

    if(pk == NULL)
        GET_STRING_VAL("product_key", &g_cfg->pk);
    else
        g_cfg->pk = strdup(pk);

    if(dn == NULL)
        GET_STRING_VAL("device_name", &g_cfg->dn);
    else
        g_cfg->dn = strdup(dn);

    if(ds == NULL)
        GET_STRING_VAL("device_secret", &g_cfg->ds);
    else
        g_cfg->ds = strdup(ds);
    free(working_dir);
	free(cfg_json);

	_dump_cfg();
	return g_cfg;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
andl $0x0, 0xc(%rsp)
andl $0x0, 0x8(%rsp)
cmpq $0x0, 0x6a00(%rip)      # 0xd7b0
je 0x6def
leaq 0x2150(%rip), %rsi      # 0x8f09
leaq 0x214f(%rip), %rdx      # 0x8f0f
leaq 0x2162(%rip), %r8       # 0x8f29
pushq $0x2
popq %rdi
movl $0xa1, %ecx
xorl %eax, %eax
callq 0x403f
movq 0x69d3(%rip), %rbx      # 0xd7b0
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
pushq $0x40
popq %rdi
callq 0x2150
movq %rax, 0x69a9(%rip)      # 0xd7b0
testq %rax, %rax
je 0x71ea
pushq $0x1
popq %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x24a0
testq %rax, %rax
je 0x7517
movq %rax, %rbx
leaq 0x2225(%rip), %rdi      # 0x9055
movl $0xfff, %edx            # imm = 0xFFF
movq %rax, %rsi
callq 0x2370
testl %eax, %eax
jle 0x7533
movq %r12, 0x20(%rsp)
movq %r14, 0x10(%rsp)
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movb $0x0, (%rbx,%rax)
pushq $0x2f
popq %rsi
movq %rbx, %rdi
callq 0x22f0
testq %rax, %rax
je 0x6e6b
movb $0x0, (%rax)
movq %rbx, %rdi
callq 0x2270
addl $0x16, %eax
movslq %eax, %r14
pushq $0x1
popq %rdi
movq %r14, %rsi
callq 0x24a0
testq %rax, %rax
je 0x754f
movq %rax, %rbp
leaq 0x220a(%rip), %rdx      # 0x90a1
leaq 0x20d8(%rip), %r8       # 0x8f76
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x20b0
leaq 0x19ed(%rip), %rsi      # 0x88a2
movq %rbp, %rdi
callq 0x2160
testq %rax, %rax
je 0x7576
movq %rax, %r14
movq %rbx, 0x18(%rsp)
movq %r15, %rbx
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x20e0
pushq $0x2
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r14, %rdi
callq 0x20a0
testq %rax, %rax
jle 0x75ad
movq %rax, %r15
leaq 0x1(%rax), %r13
pushq $0x1
popq %rdi
movq %r13, %rsi
callq 0x24a0
testq %rax, %rax
je 0x75d4
movq %rax, %r12
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x20e0
pushq $0x1
popq %rsi
movq %r12, %rdi
movq %r13, %rdx
movq %r14, %rcx
callq 0x23e0
cmpq %r15, %rax
jae 0x6f6c
callq 0x2400
movl (%rax), %edi
callq 0x2330
leaq 0x16b2(%rip), %rsi      # 0x8600
leaq 0x1fba(%rip), %rdx      # 0x8f0f
leaq 0x21ad(%rip), %r8       # 0x9109
pushq $0x3
popq %rdi
pushq $0x4c
popq %rcx
movq %rax, %r9
xorl %eax, %eax
callq 0x403f
movq %r14, %rdi
callq 0x24b0
movq %rbp, %rdi
callq 0x2250
movq %r12, %rdi
callq 0x2270
leaq 0x2000(%rip), %rdx      # 0x8f8b
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
movq %r12, %rdi
movl %eax, %esi
callq 0x371a
testq %rax, %rax
je 0x760b
cmpl $0x0, 0x8(%rsp)
jne 0x760b
movl 0xc(%rsp), %esi
testl %esi, %esi
jle 0x760b
movq %rbx, %r13
movq %rax, %rdi
callq 0x25a0
movq 0x67df(%rip), %rcx      # 0xd7b0
movq %rax, (%rcx)
movq %r12, %rdi
callq 0x2270
leaq 0x1fd4(%rip), %rdx      # 0x8fb7
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
movq %r12, %rdi
movl %eax, %esi
callq 0x371a
testq %rax, %rax
movq 0x20(%rsp), %rbx
je 0x7634
cmpl $0x0, 0x8(%rsp)
jne 0x7634
movl 0xc(%rsp), %esi
testl %esi, %esi
jle 0x7634
movq %rax, %rdi
callq 0x25a0
movq 0x6785(%rip), %rcx      # 0xd7b0
movq %rax, 0x8(%rcx)
movq %r12, %rdi
callq 0x2270
leaq 0x1f84(%rip), %rdx      # 0x8fc2
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
movq %r12, %rdi
movl %eax, %esi
callq 0x371a
testq %rax, %rax
je 0x765d
cmpl $0x0, 0x8(%rsp)
jne 0x765d
movl 0xc(%rsp), %esi
testl %esi, %esi
jle 0x765d
movq %rax, %rdi
callq 0x25a0
movq 0x672f(%rip), %rcx      # 0xd7b0
movq %rax, 0x10(%rcx)
movq %r12, %rdi
callq 0x2270
leaq 0x1f38(%rip), %rdx      # 0x8fcc
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
movq %r12, %rdi
movl %eax, %esi
callq 0x371a
testq %rax, %rax
je 0x7686
cmpl $0x0, 0x8(%rsp)
jne 0x7686
movl 0xc(%rsp), %esi
testl %esi, %esi
jle 0x7686
movq %rax, %rdi
callq 0x25a0
movq 0x66d9(%rip), %rcx      # 0xd7b0
movq %rax, 0x30(%rcx)
movq %r12, %rdi
callq 0x2270
leaq 0x1eec(%rip), %rdx      # 0x8fd6
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
movq %r12, %rdi
movl %eax, %esi
callq 0x371a
testq %rax, %rax
je 0x76ac
cmpl $0x3, 0x8(%rsp)
jne 0x76ac
cmpl $0x0, 0xc(%rsp)
jle 0x76ac
movq %rax, %rdi
callq 0x2380
movq 0x6684(%rip), %rcx      # 0xd7b0
movb %al, 0x3c(%rcx)
movq %r12, %rdi
callq 0x2270
leaq 0x1ea2(%rip), %rdx      # 0x8fe0
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
movq %r12, %rdi
movl %eax, %esi
callq 0x371a
testq %rax, %rax
je 0x76d2
cmpl $0x3, 0x8(%rsp)
jne 0x76d2
cmpl $0x0, 0xc(%rsp)
jle 0x76d2
movq %rax, %rdi
callq 0x2380
movq 0x6630(%rip), %rcx      # 0xd7b0
movl %eax, 0x38(%rcx)
movq %r12, %rdi
callq 0x2270
leaq 0x1e5a(%rip), %rdx      # 0x8fec
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
movq %r12, %rdi
movl %eax, %esi
callq 0x371a
testq %rax, %rax
je 0x76f8
cmpl $0x3, 0x8(%rsp)
jne 0x76f8
cmpl $0x0, 0xc(%rsp)
jle 0x76f8
movq %rax, %rdi
callq 0x2380
movq 0x65dc(%rip), %r14      # 0xd7b0
movb %al, 0x3d(%r14)
testq %rbx, %rbx
je 0x7215
movq %rbx, %rdi
callq 0x2410
jmp 0x7272
leaq 0x140f(%rip), %rsi      # 0x8600
leaq 0x1d17(%rip), %rdx      # 0x8f0f
leaq 0x1d46(%rip), %r8       # 0x8f45
xorl %ebx, %ebx
pushq $0x3
popq %rdi
movl $0xa7, %ecx
xorl %eax, %eax
callq 0x403f
jmp 0x6ddd
movq %r12, %rdi
callq 0x2270
leaq 0x1dd4(%rip), %rdx      # 0x8ff8
leaq 0xc(%rsp), %r14
leaq 0x8(%rsp), %r15
movq %r12, %rdi
movl %eax, %esi
movq %r14, %rcx
movq %r15, %r8
callq 0x371a
testq %rax, %rax
setne %dl
cmpl $0x0, (%r15)
sete %sil
movl (%r14), %ecx
testl %ecx, %ecx
setg %dil
andb %sil, %dil
andb %dl, %dil
cmpb $0x1, %dil
jne 0x7276
movl %ecx, %esi
movq %rax, %rdi
callq 0x25a0
movq 0x653e(%rip), %r14      # 0xd7b0
movq %rax, 0x18(%r14)
testq %r13, %r13
je 0x728a
movq %r13, %rdi
callq 0x2410
movq 0x10(%rsp), %r14
jmp 0x72e5
movq %r12, %rdi
callq 0x2270
leaq 0x1d6b(%rip), %rdx      # 0x9004
leaq 0xc(%rsp), %r14
leaq 0x8(%rsp), %r15
movq %r12, %rdi
movl %eax, %esi
movq %r14, %rcx
movq %r15, %r8
callq 0x371a
testq %rax, %rax
setne %dl
cmpl $0x0, (%r15)
sete %sil
movl (%r14), %ecx
testl %ecx, %ecx
setg %dil
andb %sil, %dil
andb %dl, %dil
cmpb $0x1, %dil
movq 0x10(%rsp), %r14
jne 0x72f0
movl %ecx, %esi
movq %rax, %rdi
callq 0x25a0
movq 0x64c4(%rip), %rcx      # 0xd7b0
movq %rax, 0x20(%rcx)
testq %r14, %r14
je 0x72ff
movq %r14, %rdi
callq 0x2410
jmp 0x7359
movq %r12, %rdi
callq 0x2270
leaq 0x1d02(%rip), %rdx      # 0x9010
leaq 0xc(%rsp), %r14
leaq 0x8(%rsp), %r15
movq %r12, %rdi
movl %eax, %esi
movq %r14, %rcx
movq %r15, %r8
callq 0x371a
testq %rax, %rax
setne %dl
cmpl $0x0, (%r15)
sete %sil
movl (%r14), %ecx
testl %ecx, %ecx
setg %dil
andb %sil, %dil
andb %dl, %dil
cmpb $0x1, %dil
jne 0x750b
movl %ecx, %esi
movq %rax, %rdi
callq 0x25a0
movq 0x6450(%rip), %r14      # 0xd7b0
movq %rax, 0x28(%r14)
movq 0x18(%rsp), %rdi
callq 0x2250
movq %r12, %rdi
callq 0x2250
testq %r14, %r14
je 0x7504
movq (%r14), %r9
leaq 0x12d0(%rip), %rbx      # 0x8659
leaq 0x1b7f(%rip), %r14      # 0x8f0f
leaq 0x1d93(%rip), %r8       # 0x912a
pushq $0x1
popq %rbp
pushq $0xf
popq %rcx
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x403f
movq 0x63fd(%rip), %rax      # 0xd7b0
movq 0x8(%rax), %r9
leaq 0x1d79(%rip), %r8       # 0x9137
pushq $0x10
popq %rcx
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x403f
movq 0x63d9(%rip), %rax      # 0xd7b0
movq 0x10(%rax), %r9
leaq 0x1d64(%rip), %r8       # 0x9146
pushq $0x11
popq %rcx
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x403f
movq 0x63b5(%rip), %rax      # 0xd7b0
movzbl 0x3c(%rax), %r9d
leaq 0x1d4d(%rip), %r8       # 0x9154
pushq $0x12
popq %rcx
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x403f
movq 0x6390(%rip), %rax      # 0xd7b0
movq 0x30(%rax), %r9
leaq 0x1d38(%rip), %r8       # 0x9163
pushq $0x13
popq %rcx
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x403f
movq 0x636c(%rip), %rax      # 0xd7b0
movl 0x38(%rax), %r9d
leaq 0x1d22(%rip), %r8       # 0x9171
pushq $0x14
popq %rcx
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x403f
movq 0x6348(%rip), %rbx      # 0xd7b0
movq 0x18(%rbx), %r9
testq %r9, %r9
je 0x749a
leaq 0x11e1(%rip), %rsi      # 0x8659
leaq 0x1a90(%rip), %rdx      # 0x8f0f
leaq 0x1cfb(%rip), %r8       # 0x9181
pushq $0x1
popq %rdi
pushq $0x16
popq %rcx
xorl %eax, %eax
callq 0x403f
movq 0x6316(%rip), %rbx      # 0xd7b0
movq 0x20(%rbx), %r9
testq %r9, %r9
je 0x74cc
leaq 0x11af(%rip), %rsi      # 0x8659
leaq 0x1a5e(%rip), %rdx      # 0x8f0f
leaq 0x1cd9(%rip), %r8       # 0x9191
pushq $0x1
popq %rdi
pushq $0x18
popq %rcx
xorl %eax, %eax
callq 0x403f
movq 0x62e4(%rip), %rbx      # 0xd7b0
movq 0x28(%rbx), %r9
testq %r9, %r9
je 0x6ddd
addq $0xa, %r9
leaq 0x1175(%rip), %rsi      # 0x8659
leaq 0x1a24(%rip), %rdx      # 0x8f0f
leaq 0x1caf(%rip), %r8       # 0x91a1
pushq $0x1
popq %rdi
pushq $0x1a
popq %rcx
xorl %eax, %eax
callq 0x403f
jmp 0x6dd6
xorl %ebx, %ebx
jmp 0x6ddd
movq 0x629e(%rip), %r14      # 0xd7b0
jmp 0x7364
leaq 0x10e2(%rip), %rsi      # 0x8600
leaq 0x19ea(%rip), %rdx      # 0x8f0f
leaq 0x1b01(%rip), %r8       # 0x902d
pushq $0x3
popq %rdi
pushq $0x5d
jmp 0x7569
leaq 0x10c6(%rip), %rsi      # 0x8600
leaq 0x19ce(%rip), %rdx      # 0x8f0f
leaq 0x1b1c(%rip), %r8       # 0x9064
pushq $0x3
popq %rdi
pushq $0x75
jmp 0x7569
leaq 0x10aa(%rip), %rsi      # 0x8600
leaq 0x19b2(%rip), %rdx      # 0x8f0f
leaq 0x1b15(%rip), %r8       # 0x9079
pushq $0x3
popq %rdi
pushq $0x2b
popq %rcx
xorl %eax, %eax
callq 0x403f
jmp 0x7723
callq 0x2400
movl (%rax), %edi
callq 0x2330
movq %rax, (%rsp)
leaq 0x1073(%rip), %rsi      # 0x8600
leaq 0x197b(%rip), %rdx      # 0x8f0f
leaq 0x1b0c(%rip), %r8       # 0x90a7
pushq $0x3
popq %rdi
pushq $0x32
popq %rcx
movq %rbp, %r9
xorl %eax, %eax
callq 0x403f
jmp 0x75fe
leaq 0x104c(%rip), %rsi      # 0x8600
leaq 0x1954(%rip), %rdx      # 0x8f0f
leaq 0x1b01(%rip), %r8       # 0x90c3
pushq $0x3
popq %rdi
pushq $0x3b
popq %rcx
movq %rbp, %r9
xorl %eax, %eax
callq 0x403f
jmp 0x75f6
leaq 0x1025(%rip), %rsi      # 0x8600
leaq 0x192d(%rip), %rdx      # 0x8f0f
leaq 0x1aec(%rip), %r8       # 0x90d5
pushq $0x3
popq %rdi
pushq $0x44
popq %rcx
xorl %eax, %eax
callq 0x403f
movq %r14, %rdi
callq 0x24b0
movq %rbp, %rdi
callq 0x2250
jmp 0x7723
leaq 0xfee(%rip), %rsi       # 0x8600
leaq 0x18f6(%rip), %rdx      # 0x8f0f
leaq 0x1974(%rip), %r8       # 0x8f94
leaq 0x1964(%rip), %r9       # 0x8f8b
pushq $0x3
popq %rdi
movl $0xaf, %ecx
jmp 0x771c
leaq 0xfc5(%rip), %rsi       # 0x8600
leaq 0x18cd(%rip), %rdx      # 0x8f0f
leaq 0x194b(%rip), %r8       # 0x8f94
leaq 0x1967(%rip), %r9       # 0x8fb7
pushq $0x3
popq %rdi
movl $0xb0, %ecx
jmp 0x771c
leaq 0xf9c(%rip), %rsi       # 0x8600
leaq 0x18a4(%rip), %rdx      # 0x8f0f
leaq 0x1922(%rip), %r8       # 0x8f94
leaq 0x1949(%rip), %r9       # 0x8fc2
pushq $0x3
popq %rdi
movl $0xb1, %ecx
jmp 0x771c
leaq 0xf73(%rip), %rsi       # 0x8600
leaq 0x187b(%rip), %rdx      # 0x8f0f
leaq 0x18f9(%rip), %r8       # 0x8f94
leaq 0x192a(%rip), %r9       # 0x8fcc
pushq $0x3
popq %rdi
movl $0xb2, %ecx
jmp 0x771c
leaq 0xf4d(%rip), %rsi       # 0x8600
leaq 0x1855(%rip), %rdx      # 0x8f0f
leaq 0x18d3(%rip), %r8       # 0x8f94
leaq 0x190e(%rip), %r9       # 0x8fd6
pushq $0x3
popq %rdi
movl $0xb3, %ecx
jmp 0x771c
leaq 0xf27(%rip), %rsi       # 0x8600
leaq 0x182f(%rip), %rdx      # 0x8f0f
leaq 0x18ad(%rip), %r8       # 0x8f94
leaq 0x18f2(%rip), %r9       # 0x8fe0
pushq $0x3
popq %rdi
movl $0xb4, %ecx
jmp 0x771c
leaq 0xf01(%rip), %rsi       # 0x8600
leaq 0x1809(%rip), %rdx      # 0x8f0f
leaq 0x1887(%rip), %r8       # 0x8f94
leaq 0x18d8(%rip), %r9       # 0x8fec
pushq $0x3
popq %rdi
movl $0xb5, %ecx
xorl %eax, %eax
callq 0x403f
pushq $0x1
popq %rdi
callq 0x2100