// File: /workspace/github_c_makefile_star2_O0/aremmell[P]libsir/src/sirfilecache.c
// Function: sir_fcache_add
sirfileid _sir_fcache_add(sirfcache* sfc, const char* path, sir_levels levels,
    sir_options opts) {
    if (!_sir_validptr(sfc) || !_sir_validstr(path) || !_sir_validlevels(levels) ||
        !_sir_validopts(opts))
        return 0U;

    if (sfc->count >= SIR_MAXFILES)
        return _sir_seterror(_SIR_E_NOROOM);

    const sirfile* existing = _sir_fcache_find(sfc, (const void*)path, _sir_fcache_pred_path);
    if (NULL != existing) {
        _sir_selflog("error: already have file (path: '%s', id: %"PRIx32")",
            path, existing->id);
        return _sir_seterror(_SIR_E_DUPITEM);
    }

    sirfile* sf = _sirfile_create(path, levels, opts);
    if (_sirfile_validate(sf)) {
        _sir_selflog("adding file (path: '%s', id: %"PRIx32"); count = %zu", //-V522
            sf->path, sf->id, sfc->count + 1);

        sfc->files[sfc->count++] = sf;

        if (!_sir_bittest(sf->opts, SIRO_NOHDR) && !_sirfile_writeheader(sf, SIR_FHBEGIN))
            _sir_selflog("warning: failed to write file header (path: '%s', id: %"PRIx32")",
                sf->path, sf->id);

        return sf->id;
    }

    _sir_safefree(&sf);

    return 0U;
}

// Assembly:
subq $0x38, %rsp
movw %dx, %ax
movq %rdi, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movw %ax, 0x1e(%rsp)
movl %ecx, 0x18(%rsp)
movq 0x28(%rsp), %rdi
movl $0x1, %esi
leaq 0xc455(%rip), %rdx      # 0x10ba0
leaq 0xc12b(%rip), %rcx      # 0x1087d
movl $0x19a, %r8d            # imm = 0x19A
callq 0x5200
testb $0x1, %al
jne 0x4763
jmp 0x47cf
movq 0x20(%rsp), %rdi
movl $0x1, %esi
leaq 0xc42c(%rip), %rdx      # 0x10ba0
leaq 0xc102(%rip), %rcx      # 0x1087d
movl $0x19a, %r8d            # imm = 0x19A
callq 0x4f70
testb $0x1, %al
jne 0x478c
jmp 0x47cf
leaq 0xc40d(%rip), %rsi      # 0x10ba0
leaq 0xc0e3(%rip), %rdx      # 0x1087d
movl $0x19a, %ecx            # imm = 0x19A
movzwl 0x1e(%rsp), %edi
callq 0x7da0
testb $0x1, %al
jne 0x47af
jmp 0x47cf
movl 0x18(%rsp), %edi
leaq 0xc3e6(%rip), %rsi      # 0x10ba0
leaq 0xc0bc(%rip), %rdx      # 0x1087d
movl $0x19b, %ecx            # imm = 0x19B
callq 0x7ed0
testb $0x1, %al
jne 0x47dc
movl $0x0, 0x34(%rsp)
jmp 0x496d
movq 0x28(%rsp), %rax
cmpq $0x10, 0x80(%rax)
jb 0x4816
movl $0x80060000, %edi       # imm = 0x80060000
leaq 0xc3a9(%rip), %rsi      # 0x10ba0
leaq 0xc07f(%rip), %rdx      # 0x1087d
movl $0x19f, %ecx            # imm = 0x19F
callq 0x3940
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x34(%rsp)
jmp 0x496d
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rsi
leaq 0x1be9(%rip), %rdx      # 0x6410
callq 0x62e0
movq %rax, 0x10(%rsp)
xorl %eax, %eax
cmpq 0x10(%rsp), %rax
je 0x4880
movq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rax
movl 0x18(%rax), %edx
leaq 0xc362(%rip), %rdi      # 0x10bb0
movb $0x0, %al
callq 0x5ff0
movl $0x80040000, %edi       # imm = 0x80040000
leaq 0xc33f(%rip), %rsi      # 0x10ba0
leaq 0xc015(%rip), %rdx      # 0x1087d
movl $0x1a5, %ecx            # imm = 0x1A5
callq 0x3940
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x34(%rsp)
jmp 0x496d
movq 0x20(%rsp), %rdi
movw 0x1e(%rsp), %ax
movl 0x18(%rsp), %edx
movzwl %ax, %esi
callq 0x4dc0
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
callq 0x5100
testb $0x1, %al
jne 0x48ae
jmp 0x495b
movq 0x8(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rsp), %rax
movl 0x18(%rax), %edx
movq 0x28(%rsp), %rax
movq 0x80(%rax), %rcx
addq $0x1, %rcx
leaq 0xc309(%rip), %rdi      # 0x10bde
movb $0x0, %al
callq 0x5ff0
movq 0x8(%rsp), %rdx
movq 0x28(%rsp), %rax
movq 0x28(%rsp), %rsi
movq 0x80(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x80(%rsi)
movq %rdx, (%rax,%rcx,8)
movq 0x8(%rsp), %rax
movl 0xc(%rax), %edi
movl $0x10000, %esi          # imm = 0x10000
callq 0x62c0
testb $0x1, %al
jne 0x494d
movq 0x8(%rsp), %rdi
leaq 0xc2e6(%rip), %rsi      # 0x10c0c
callq 0x5570
testb $0x1, %al
jne 0x494d
movq 0x8(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rsp), %rax
movl 0x18(%rax), %edx
leaq 0xc2d6(%rip), %rdi      # 0x10c1c
movb $0x0, %al
callq 0x5ff0
movq 0x8(%rsp), %rax
movl 0x18(%rax), %eax
movl %eax, 0x34(%rsp)
jmp 0x496d
leaq 0x8(%rsp), %rdi
callq 0x7910
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)