// File: /workspace/github_c_makefile_star2_O2/naleksiev[P]fin/src/fin_str.c
// Function: fin_str_create
fin_str_t* fin_str_create(fin_ctx_t* ctx, const char* cstr, int32_t len) {
    fin_str_pool_t* pool = ctx->pool;
    if (cstr == NULL || cstr[0] == '\0' || len == 0)
        return NULL;

    int32_t hash = fin_str_hash(cstr, &len);
    if (pool->capacity) {
        int32_t slot = (uint32_t)hash % pool->capacity;
        int32_t end_slot = slot;
        do {
            fin_str_entry_t* entry = &pool->entries[slot];
            if (entry->hash == 0 && entry->str == NULL)
                break;
            if (entry->hash == hash && entry->str->len == len) {
                if (strncmp(entry->str->cstr, cstr, len) == 0) {
                    entry->str->ref++;
                    return entry->str;
                }
            }
            slot = (slot + 1) % pool->capacity;
        } while (slot != end_slot);
    }
    if (pool->capacity == 0)
        fin_str_resize(pool, 16);
    else if (pool->count + 1 > pool->capacity * 3 / 4)
        fin_str_resize(pool, pool->capacity * 2);
    fin_str_t* str = (fin_str_t*)pool->alloc(NULL, sizeof(fin_str_t) + len);
    str->ref = 1;
    str->len = len;
    strncpy(str->cstr, cstr, len);
    str->cstr[len] = '\0';
    fin_str_insert(pool, hash, str);
    return str;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
testq %rsi, %rsi
je 0x7849
movq %rsi, %r14
movb (%rsi), %al
testb %al, %al
sete %cl
testl %edx, %edx
sete %sil
orb %cl, %sil
je 0x7851
xorl %r13d, %r13d
jmp 0x7993
movq 0x8(%rdi), %r13
movslq %edx, %rcx
movl $0x811c9dc5, %r15d      # imm = 0x811C9DC5
xorl %ebx, %ebx
movabsq $0x100000000, %rdx      # imm = 0x100000000
xorl %r12d, %r12d
testb %al, %al
je 0x7890
cmpq %rbx, %rcx
je 0x7890
movsbl %al, %eax
xorl %eax, %r15d
imull $0x1000193, %r15d, %r15d # imm = 0x1000193
movb 0x1(%r14,%rbx), %al
addq %rdx, %r12
incq %rbx
jmp 0x786d
movl 0x8(%r13), %r8d
testl %r8d, %r8d
movq %r13, -0x38(%rbp)
je 0x794b
movq %r14, -0x40(%rbp)
movl %r15d, %eax
xorl %edx, %edx
divl %r8d
movl %edx, %esi
movq (%r13), %rdi
sarq $0x20, %r12
movl %edx, %r14d
movq %r8, -0x50(%rbp)
movl %edx, -0x2c(%rbp)
movq %rdi, -0x48(%rbp)
movslq %r14d, %rcx
shlq $0x4, %rcx
leaq (%rdi,%rcx), %rax
movl (%rdi,%rcx), %ecx
testl %ecx, %ecx
jne 0x78de
cmpq $0x0, 0x8(%rax)
je 0x7921
cmpl %r15d, %ecx
jne 0x7910
movq 0x8(%rax), %r13
cmpl %ebx, 0x4(%r13)
jne 0x7910
leaq 0xc(%r13), %rdi
movq -0x40(%rbp), %rsi
movq %r12, %rdx
callq 0x3080
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq -0x50(%rbp), %r8
testl %eax, %eax
je 0x79a5
incl %r14d
movl %r14d, %eax
cltd
idivl %r8d
movl %edx, %r14d
cmpl %esi, %edx
jne 0x78c5
movq -0x38(%rbp), %r13
movl 0xc(%r13), %ecx
leal (%r8,%r8,2), %eax
pushq $0x4
popq %rsi
cltd
idivl %esi
cmpl %eax, %ecx
movq -0x40(%rbp), %r14
jl 0x795a
addl %r8d, %r8d
movq %r13, %rdi
movl %r8d, %esi
callq 0x76d4
jmp 0x795a
pushq $0x10
popq %rsi
movq %r13, %rdi
callq 0x76d4
sarq $0x20, %r12
leal 0x10(%rbx), %esi
xorl %edi, %edi
callq *0x10(%r13)
movq %rax, %r13
movl $0x1, (%rax)
movl %ebx, 0x4(%rax)
leaq 0xc(%rax), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x3070
movb $0x0, 0xc(%r13,%r12)
movq -0x38(%rbp), %rdi
movl %r15d, %esi
movq %r13, %rdx
callq 0x7788
movq %r13, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incl (%r13)
jmp 0x7993