// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
testq %rsi, %rsi
je 0x810c
movb (%rsi), %al
testb %al, %al
sete %cl
testl %edx, %edx
sete %r8b
orb %cl, %r8b
je 0x8121
xorl %r13d, %r13d
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rdi), %rbx
movslq %edx, %rcx
decq %rcx
movl $0x811c9dc5, %r14d      # imm = 0x811C9DC5
xorl %edx, %edx
movabsq $0x100000000, %rdi      # imm = 0x100000000
xorl %r12d, %r12d
addq %rdi, %r12
movsbl %al, %eax
xorl %r14d, %eax
imull $0x1000193, %eax, %r14d # imm = 0x1000193
movb 0x1(%rsi,%rdx), %al
leaq 0x1(%rdx), %r15
testb %al, %al
je 0x8164
cmpq %rdx, %rcx
movq %r15, %rdx
jne 0x8140
movl 0x8(%rbx), %r8d
testl %r8d, %r8d
movq %rsi, -0x38(%rbp)
je 0x8257
movl %r14d, %eax
xorl %edx, %edx
divl %r8d
movl %edx, %edi
movq %rbx, -0x40(%rbp)
movq (%rbx), %r9
movq %r12, %rax
sarq $0x20, %rax
movq %rax, -0x48(%rbp)
movl %edx, %ebx
movq %r8, -0x58(%rbp)
movl %edx, -0x2c(%rbp)
movq %r9, -0x50(%rbp)
movslq %ebx, %rcx
shlq $0x4, %rcx
leaq (%r9,%rcx), %rax
movl (%r9,%rcx), %ecx
testl %ecx, %ecx
jne 0x81b8
cmpq $0x0, 0x8(%rax)
je 0x8207
cmpl %r14d, %ecx
jne 0x81ef
movq 0x8(%rax), %rax
cmpl %r15d, 0x4(%rax)
jne 0x81ef
leaq 0xc(%rax), %rdi
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rdx
callq 0x3080
movq -0x60(%rbp), %rdx
movq -0x50(%rbp), %r9
movl -0x2c(%rbp), %edi
movq -0x58(%rbp), %r8
movq -0x38(%rbp), %rsi
testl %eax, %eax
je 0x8210
incl %ebx
movl %ebx, %eax
cltd
idivl %r8d
xorl %ecx, %ecx
movb $0x1, %al
movl %edx, %ebx
testl %ecx, %ecx
jne 0x821e
cmpl %edi, %ebx
jne 0x819e
jmp 0x822b
movl $0x2, %ecx
xorl %eax, %eax
jmp 0x81fd
incl (%rdx)
movl $0x1, %ecx
xorl %eax, %eax
movq %rdx, %r13
jmp 0x81fd
cmpl $0x2, %ecx
je 0x822b
testb %al, %al
je 0x810f
testl %r8d, %r8d
movq -0x40(%rbp), %rbx
je 0x8257
leal (%r8,%r8,2), %eax
leal (%r8,%r8,2), %ecx
addl $0x3, %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x2, %ecx
cmpl %ecx, 0xc(%rbx)
jl 0x8264
addl %r8d, %r8d
movq %rbx, %rdi
movl %r8d, %esi
jmp 0x825f
movq %rbx, %rdi
movl $0x10, %esi
callq 0x7fac
leal 0x10(%r15), %esi
xorl %edi, %edi
callq *0x10(%rbx)
movq %rax, %r13
movl $0x1, (%rax)
movl %r15d, 0x4(%rax)
leaq 0xc(%rax), %rdi
sarq $0x20, %r12
movq -0x38(%rbp), %rsi
movq %r12, %rdx
callq 0x3070
movb $0x0, 0xc(%r13,%r12)
movl 0x8(%rbx), %esi
movl %r14d, %eax
xorl %edx, %edx
divl %esi
movl %edx, %ecx
movq (%rbx), %rdi
movl %edx, %eax
movslq %eax, %r8
shlq $0x4, %r8
leaq (%rdi,%r8), %rdx
cmpl $0x0, (%rdi,%r8)
je 0x82ca
cmpq $0x0, 0x8(%rdx)
je 0x82ca
incl %eax
cltd
idivl %esi
xorl %r8d, %r8d
movl %edx, %eax
jmp 0x82db
movl %r14d, (%rdx)
movq %r13, 0x8(%rdx)
movl %eax, 0x8(%r13)
incl 0xc(%rbx)
movb $0x1, %r8b
testb %r8b, %r8b
jne 0x810f
cmpl %ecx, %eax
jne 0x82a5
jmp 0x810f