// File: /workspace/github_c_makefile_star2_O3/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:
testq %rsi, %rsi
je 0x8073
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r13
movb (%rsi), %al
testb %al, %al
sete %cl
testl %edx, %edx
sete %sil
orb %cl, %sil
je 0x807b
xorl %r9d, %r9d
jmp 0x8205
xorl %r9d, %r9d
jmp 0x8213
movq 0x8(%rdi), %r15
movslq %edx, %rcx
decq %rcx
movl $0x811c9dc5, %r14d      # imm = 0x811C9DC5
xorl %edx, %edx
movabsq $0x100000000, %rsi      # imm = 0x100000000
xorl %r12d, %r12d
addq %rsi, %r12
movsbl %al, %eax
xorl %r14d, %eax
imull $0x1000193, %eax, %r14d # imm = 0x1000193
movb 0x1(%r13,%rdx), %al
leaq 0x1(%rdx), %rbx
testb %al, %al
je 0x80bf
cmpq %rdx, %rcx
movq %rbx, %rdx
jne 0x809a
movl 0x8(%r15), %esi
testl %esi, %esi
movq %r15, -0x38(%rbp)
je 0x817b
movq %r13, -0x40(%rbp)
movl %r14d, %eax
xorl %edx, %edx
divl %esi
movl %edx, %edi
movq (%r15), %r8
sarq $0x20, %r12
movl %edx, %r13d
movq %rsi, -0x50(%rbp)
movl %edx, -0x2c(%rbp)
movq %r8, -0x48(%rbp)
movslq %r13d, %rcx
shlq $0x4, %rcx
leaq (%r8,%rcx), %rax
movl (%r8,%rcx), %ecx
testl %ecx, %ecx
jne 0x810b
cmpq $0x0, 0x8(%rax)
je 0x8150
cmpl %r14d, %ecx
jne 0x8140
movq 0x8(%rax), %r15
cmpl %ebx, 0x4(%r15)
jne 0x8140
leaq 0xc(%r15), %rdi
movq -0x40(%rbp), %rsi
movq %r12, %rdx
callq 0x3080
movq -0x48(%rbp), %r8
movl -0x2c(%rbp), %edi
movq -0x50(%rbp), %rsi
movq %r15, %r9
testl %eax, %eax
je 0x8202
incl %r13d
movl %r13d, %eax
cltd
idivl %esi
movl %edx, %r13d
cmpl %edi, %edx
jne 0x80f1
leal (%rsi,%rsi,2), %eax
leal (%rsi,%rsi,2), %ecx
addl $0x3, %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x2, %ecx
movq -0x38(%rbp), %r15
cmpl %ecx, 0xc(%r15)
movq -0x40(%rbp), %r13
jl 0x818c
addl %esi, %esi
movq %r15, %rdi
callq 0x7f18
jmp 0x818c
movq %r15, %rdi
movl $0x10, %esi
callq 0x7f18
sarq $0x20, %r12
leal 0x10(%rbx), %esi
xorl %edi, %edi
callq *0x10(%r15)
movq %rax, %r15
movl $0x1, (%rax)
movl %ebx, 0x4(%rax)
leaq 0xc(%rax), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x3070
movq %r15, %r9
movq -0x38(%rbp), %r15
movb $0x0, 0xc(%r9,%r12)
movl 0x8(%r15), %esi
movl %r14d, %eax
xorl %edx, %edx
divl %esi
movl %edx, %ecx
movq (%r15), %rdi
movslq %edx, %r8
shlq $0x4, %r8
leaq (%rdi,%r8), %rax
cmpl $0x0, (%rdi,%r8)
je 0x81f3
cmpq $0x0, 0x8(%rax)
je 0x81f3
incl %edx
movl %edx, %eax
cltd
idivl %esi
cmpl %ecx, %edx
jne 0x81cd
jmp 0x8205
movl %r14d, (%rax)
movq %r9, 0x8(%rax)
movl %edx, 0x8(%r9)
addq $0xc, %r15
incl (%r15)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
movq %r9, %rax
retq