// File: /workspace/github_c_makefile_star2_O3/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 0x3b37
movq %rdi, %rbx
movq %rsi, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x22f0
cmpl $-0x1, %eax
je 0x3b37
movl %eax, %r14d
leaq -0x1460(%rbp), %r15
movb $0x0, 0x502(%r15)
movw $0x0, 0x500(%r15)
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 -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), %r13
xorl %r12d, %r12d
movl $0x502, %edx            # imm = 0x502
movq %r15, %rdi
xorl %esi, %esi
callq 0x21a0
movl $0x1, %edx
movl %r14d, %edi
movq %r13, %rsi
callq 0x21e0
testl %eax, %eax
setg %dl
movb -0x29(%rbp), %cl
cmpb $0xa, %cl
setne %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x3956
xorl %r12d, %r12d
cmpq $0x503, %r12            # imm = 0x503
je 0x3b2c
movb %cl, -0x1460(%rbp,%r12)
incq %r12
movl $0x1, %edx
movl %r14d, %edi
movq %r13, %rsi
callq 0x21e0
testl %eax, %eax
jle 0x393f
movb -0x29(%rbp), %cl
cmpb $0xa, %cl
jne 0x390b
cmpb $0xd, -0x1461(%rbp,%r12)
jne 0x3956
movb $0x0, -0x1461(%rbp,%r12)
decl %r12d
testl %eax, %eax
jle 0x3b2c
testl %r12d, %r12d
js 0x3b2c
je 0x38ce
movzbl -0x1460(%rbp), %eax
cmpl $0x23, %eax
je 0x38ce
cmpl $0x3b, %eax
je 0x38ce
movq %r15, %rdi
leaq 0x47a6(%rip), %rsi      # 0x8136
leaq -0x750(%rbp), %rdx
movl $0x502, %ecx            # imm = 0x502
callq 0x5aab
movb -0x750(%rbp), %r12b
testb %r12b, %r12b
je 0x38ce
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, %r12b
je 0x3aea
cmpq $0x0, -0x38(%rbp)
je 0x38ce
movl $0x1, %edx
testb %r12b, %r12b
je 0x38ce
movzbl %r12b, %eax
cmpl $0x3d, %eax
je 0x3a36
movb -0x750(%rbp,%rdx), %r12b
incq %rdx
jmp 0x3a17
cmpb $0x0, -0x750(%rbp,%rdx)
je 0x38ce
leaq (%rdx,%rbp), %rax
addq $-0x750, %rax           # imm = 0xF8B0
movq %rax, -0x40(%rbp)
decq %rdx
leaq -0x240(%rbp), %r12
movq %r12, %rdi
leaq -0x750(%rbp), %rsi
callq 0x2070
leaq -0xf50(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x2090
movq %r12, %rdi
leaq 0x46b1(%rip), %r12      # 0x8136
movq %r12, %rsi
leaq -0x140(%rbp), %rdx
movl $0x100, %ecx            # imm = 0x100
callq 0x5aab
leaq -0xf50(%rbp), %rdi
movq %r12, %rsi
leaq -0xb50(%rbp), %rdx
movl $0x400, %ecx            # imm = 0x400
callq 0x5aab
cmpb $0x0, -0x140(%rbp)
je 0x38ce
cmpb $0x0, -0xb50(%rbp)
je 0x38ce
movq -0x38(%rbp), %rdi
leaq -0x140(%rbp), %rsi
leaq -0xb50(%rbp), %rdx
callq 0x3bd4
jmp 0x38ce
xorl %edx, %edx
movzbl -0x74f(%rbp,%rdx), %eax
testl %eax, %eax
je 0x3b4c
cmpl $0x5d, %eax
je 0x3b02
incq %rdx
jmp 0x3aec
leaq -0x140(%rbp), %r12
movq %r12, %rdi
leaq -0x74f(%rbp), %rsi
callq 0x2070
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3b54
movq %rax, -0x38(%rbp)
jmp 0x38ce
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
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x3b37