// File: /workspace/github_c_makefile_star2_O1/buf1024[P]mysch/iniconf.c
// Function: ini_load
int ini_load(ini_conf_t* ini, const char* file)
{
    if(!ini || !file) return -1;

    int fd = open(file, O_RDONLY);
    if (fd == -1) return -1;

    char tmpline[INI_READ_LINE + 1] = { 0 };
    char line[INI_READ_LINE + 1] = { 0 };
    char* tmp = 0;
    char key[INI_MAX_KEY_LEN] = { 0 };
    char value[INI_MAX_VALUE_LEN] = { 0 };

    char tmpkey[INI_MAX_KEY_LEN] = { 0 };
    char tmpvalue[INI_MAX_VALUE_LEN] = { 0 };

    ini_sec_t* cur_sec = 0;

    int len = 0;
    while (1) {
        if ((len = read_line(fd, tmpline, INI_READ_LINE)) < 0) {
            break;
        }
        if (*tmpline == '#' || *tmpline == ';' || len == 0) {
            continue;
        }
        trim(tmpline, " ", line, INI_READ_LINE);
        if(line[0] == 0) {
            continue;
        }

        // start section
        memset(key, 0, INI_MAX_KEY_LEN);
        memset(value, 0, INI_MAX_VALUE_LEN);
        memset(tmpkey, 0, sizeof(tmpkey));
        memset(tmpvalue, 0, sizeof(tmpvalue));

        tmp = line;
        if (*tmp == '[') {
            const char* key_del = ++tmp;
            while (*tmp != '\0' && *tmp != ']') {
                tmp++;
            }
            if (*tmp == '\0') {
                return -1;
            }
            strncpy(key, key_del, tmp - key_del);
            cur_sec = ini_insert_sec(ini, key);
            continue;
        }
        if (cur_sec) {
            const char* eq_del = tmp;
            while (*eq_del != '\0') {
                if (*eq_del == '=') {
                    break;
                }
                eq_del++;
            }
            if (*eq_del == '\0' || *(eq_del + 1) == '\0') {
                continue;
            }

            strncpy(tmpkey, tmp, eq_del - tmp);
            strcpy(tmpvalue, eq_del + 1);

            trim(tmpkey, " ", key, INI_MAX_KEY_LEN);
            trim(tmpvalue, " ", value, INI_MAX_VALUE_LEN);

            if(key[0] == 0 || value[0] == 0) {
                continue;
            }

            ini_insert_val(cur_sec, key, value);

        }
    }
    close(fd);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1438, %rsp           # imm = 0x1438
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
orb %al, %cl
jne 0x3bf3
movq %rdi, %rbx
movq %rsi, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x22f0
cmpl $-0x1, %eax
je 0x3bf3
movl %eax, %r14d
movq %rbx, -0x40(%rbp)
leaq -0x1460(%rbp), %r15
movq $0x0, -0x38(%rbp)
movl $0x503, %edx            # imm = 0x503
movq %r15, %rdi
xorl %esi, %esi
callq 0x21a0
leaq -0x750(%rbp), %rdi
movl $0x503, %edx            # imm = 0x503
xorl %esi, %esi
callq 0x21a0
leaq -0x140(%rbp), %rdi
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x21a0
leaq -0xb50(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x21a0
leaq -0x240(%rbp), %rdi
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x21a0
leaq -0xf50(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x21a0
leaq -0x29(%rbp), %r12
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movl $0x502, %edx            # imm = 0x502
movq %r15, %rdi
xorl %esi, %esi
callq 0x21a0
movl $0x1, %edx
movl %r14d, %edi
movq %r12, %rsi
callq 0x21e0
testl %eax, %eax
setg %dl
movb -0x29(%rbp), %cl
cmpb $0xa, %cl
setne %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x39e1
xorl %r13d, %r13d
cmpq $0x503, %r13            # imm = 0x503
je 0x3a06
movb %cl, -0x1460(%rbp,%r13)
incq %r13
movl $0x1, %edx
movl %r14d, %edi
movq %r12, %rsi
callq 0x21e0
testl %eax, %eax
jle 0x39e1
movb -0x29(%rbp), %cl
cmpb $0xa, %cl
jne 0x39b1
testl %r13d, %r13d
je 0x39fe
movl %r13d, %ecx
cmpb $0xd, -0x1461(%rbp,%rcx)
jne 0x39fe
movb $0x0, -0x1461(%rbp,%rcx)
decl %r13d
testl %eax, %eax
cmovlel %ebx, %r13d
jmp 0x3a0c
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testl %r13d, %r13d
js 0x3be8
je 0x3974
movzbl -0x1460(%rbp), %eax
cmpl $0x23, %eax
je 0x3974
cmpl $0x3b, %eax
je 0x3974
movq %r15, %rdi
leaq 0x46f8(%rip), %rsi      # 0x8136
leaq -0x750(%rbp), %rdx
movl $0x502, %ecx            # imm = 0x502
callq 0x5bf1
movb -0x750(%rbp), %r13b
testb %r13b, %r13b
je 0x3974
movl $0x100, %edx            # imm = 0x100
leaq -0x140(%rbp), %rdi
xorl %esi, %esi
callq 0x21a0
movl $0x400, %edx            # imm = 0x400
leaq -0xb50(%rbp), %rdi
xorl %esi, %esi
callq 0x21a0
movl $0x100, %edx            # imm = 0x100
leaq -0x240(%rbp), %rdi
xorl %esi, %esi
callq 0x21a0
movl $0x400, %edx            # imm = 0x400
leaq -0xf50(%rbp), %rdi
xorl %esi, %esi
callq 0x21a0
cmpb $0x5b, %r13b
je 0x3b90
cmpq $0x0, -0x38(%rbp)
je 0x3974
movl $0x1, %edx
movzbl -0x751(%rbp,%rdx), %eax
testl %eax, %eax
je 0x3974
cmpl $0x3d, %eax
je 0x3adf
incq %rdx
jmp 0x3ac5
cmpb $0x0, -0x750(%rbp,%rdx)
je 0x3974
leaq (%rdx,%rbp), %r13
addq $-0x750, %r13           # imm = 0xF8B0
decq %rdx
leaq -0x240(%rbp), %rdi
leaq -0x750(%rbp), %rsi
callq 0x2070
leaq -0xf50(%rbp), %rdi
movq %r13, %rsi
callq 0x2090
leaq -0x240(%rbp), %rdi
leaq 0x460b(%rip), %r13      # 0x8136
movq %r13, %rsi
leaq -0x140(%rbp), %rdx
movl $0x100, %ecx            # imm = 0x100
callq 0x5bf1
leaq -0xf50(%rbp), %rdi
movq %r13, %rsi
leaq -0xb50(%rbp), %rdx
movl $0x400, %ecx            # imm = 0x400
callq 0x5bf1
cmpb $0x0, -0x140(%rbp)
je 0x3974
cmpb $0x0, -0xb50(%rbp)
je 0x3974
movq -0x38(%rbp), %rdi
leaq -0x140(%rbp), %rsi
leaq -0xb50(%rbp), %rdx
callq 0x3c88
jmp 0x3974
xorl %edx, %edx
movzbl -0x74f(%rbp,%rdx), %r13d
testl %r13d, %r13d
je 0x3bab
cmpl $0x5d, %r13d
je 0x3bab
incq %rdx
jmp 0x3b92
testb %r13b, %r13b
je 0x3bd7
leaq -0x140(%rbp), %rdi
leaq -0x74f(%rbp), %rsi
callq 0x2070
movq -0x40(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x3c08
movq %rax, -0x38(%rbp)
testb %r13b, %r13b
jne 0x3974
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x3bf3
movl %r14d, %edi
callq 0x21c0
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x1438, %rsp           # imm = 0x1438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq