// File: /workspace/github_c_makefile_star2_O2/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
pushq $-0x1
popq %r15
orb %al, %cl
jne 0x37b8
movq %rdi, %rbx
movq %rsi, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x22f0
cmpl $-0x1, %eax
je 0x37b8
movl %eax, %r14d
leaq -0xc60(%rbp), %rax
movb $0x0, 0x502(%rax)
andw $0x0, 0x500(%rax)
leaq -0x750(%rbp), %rdi
movq $0x0, -0x38(%rbp)
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 -0x1060(%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 -0x1460(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x21a0
leaq -0x29(%rbp), %r13
pushq $0x1
popq %r12
movl $0x502, %edx            # imm = 0x502
leaq -0xc60(%rbp), %rdi
xorl %esi, %esi
callq 0x21a0
xorl %r15d, %r15d
movl %r14d, %edi
movq %r13, %rsi
movq %r12, %rdx
callq 0x21e0
testl %eax, %eax
jle 0x35b8
movb -0x29(%rbp), %cl
cmpb $0xa, %cl
je 0x35b8
cmpq $0x503, %r15            # imm = 0x503
je 0x37ad
movb %cl, -0xc60(%rbp,%r15)
incq %r15
jmp 0x3584
testq %r15, %r15
je 0x35d6
cmpb $0xd, -0xc61(%rbp,%r15)
jne 0x35d9
movb $0x0, -0xc61(%rbp,%r15)
decl %r15d
jmp 0x35d9
xorl %r15d, %r15d
testl %eax, %eax
jle 0x37ad
testl %r15d, %r15d
js 0x37ad
je 0x356e
movzbl -0xc60(%rbp), %eax
cmpl $0x23, %eax
je 0x356e
cmpl $0x3b, %eax
je 0x356e
leaq -0xc60(%rbp), %rdi
leaq 0x3b23(%rip), %rsi      # 0x7136
leaq -0x750(%rbp), %rdx
movl $0x502, %ecx            # imm = 0x502
callq 0x56b7
movb -0x750(%rbp), %r15b
testb %r15b, %r15b
je 0x356e
movl $0x100, %edx            # imm = 0x100
leaq -0x140(%rbp), %rdi
xorl %esi, %esi
callq 0x21a0
movl $0x400, %edx            # imm = 0x400
leaq -0x1060(%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 -0x1460(%rbp), %rdi
xorl %esi, %esi
callq 0x21a0
cmpb $0x5b, %r15b
je 0x376b
cmpq $0x0, -0x38(%rbp)
je 0x356e
movq %r12, %rdx
testb %r15b, %r15b
je 0x356e
movzbl %r15b, %eax
cmpl $0x3d, %eax
je 0x36b7
movb -0x750(%rbp,%rdx), %r15b
incq %rdx
jmp 0x3698
cmpb $0x0, -0x750(%rbp,%rdx)
je 0x356e
leaq (%rdx,%rbp), %rax
addq $-0x750, %rax           # imm = 0xF8B0
movq %rax, -0x40(%rbp)
decq %rdx
leaq -0x240(%rbp), %r15
movq %r15, %rdi
leaq -0x750(%rbp), %rsi
callq 0x2070
leaq -0x1460(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x2090
movq %r15, %rdi
leaq 0x3a30(%rip), %r15      # 0x7136
movq %r15, %rsi
leaq -0x140(%rbp), %rdx
movl $0x100, %ecx            # imm = 0x100
callq 0x56b7
leaq -0x1460(%rbp), %rdi
movq %r15, %rsi
leaq -0x1060(%rbp), %rdx
movl $0x400, %ecx            # imm = 0x400
callq 0x56b7
cmpb $0x0, -0x140(%rbp)
je 0x356e
cmpb $0x0, -0x1060(%rbp)
je 0x356e
movq -0x38(%rbp), %rdi
leaq -0x140(%rbp), %rsi
leaq -0x1060(%rbp), %rdx
callq 0x3851
jmp 0x356e
xorl %edx, %edx
movzbl -0x74f(%rbp,%rdx), %eax
testl %eax, %eax
je 0x37cd
cmpl $0x5d, %eax
je 0x3783
incq %rdx
jmp 0x376d
leaq -0x140(%rbp), %r15
movq %r15, %rdi
leaq -0x74f(%rbp), %rsi
callq 0x2070
movq %rbx, %rdi
movq %r15, %rsi
callq 0x37d3
movq %rax, -0x38(%rbp)
jmp 0x356e
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
pushq $-0x1
popq %r15
jmp 0x37b8