// File: /workspace/github_c_makefile_star2_O0/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
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xae58
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xae58
cmpl $0x0, -0x1c(%rbp)
jne 0xae65
movq $0x0, -0x8(%rbp)
jmp 0xaffc
movq -0x18(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0xb010
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0xaf3e
movl -0x2c(%rbp), %eax
movq -0x28(%rbp), %rcx
xorl %edx, %edx
divl 0x8(%rcx)
movl %edx, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movslq -0x30(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xaec4
movq -0x40(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0xaec4
jmp 0xaf3c
movq -0x40(%rbp), %rax
movl (%rax), %eax
cmpl -0x2c(%rbp), %eax
jne 0xaf1f
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x4(%rax), %eax
cmpl -0x1c(%rbp), %eax
jne 0xaf1f
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0xc, %rdi
movq -0x18(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
callq 0x3080
cmpl $0x0, %eax
jne 0xaf1d
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0xaffc
jmp 0xaf1f
movl -0x30(%rbp), %eax
addl $0x1, %eax
movq -0x28(%rbp), %rcx
cltd
idivl 0x8(%rcx)
movl %edx, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0xae98
jmp 0xaf3e
movq -0x28(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0xaf58
movq -0x28(%rbp), %rdi
movl $0x10, %esi
callq 0xabb0
jmp 0xaf92
movq -0x28(%rbp), %rax
movl 0xc(%rax), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x28(%rbp), %rax
imull $0x3, 0x8(%rax), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x4c(%rbp), %eax
cmpl %ecx, %eax
jle 0xaf90
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %esi
shll %esi
callq 0xabb0
jmp 0xaf92
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x1c(%rbp), %rcx
addq $0x10, %rcx
movl %ecx, %esi
xorl %ecx, %ecx
movl %ecx, %edi
callq *%rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl $0x1, (%rax)
movl -0x1c(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x48(%rbp), %rdi
addq $0xc, %rdi
movq -0x18(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
callq 0x3070
movq -0x48(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movb $0x0, 0xc(%rax,%rcx)
movq -0x28(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq -0x48(%rbp), %rdx
callq 0xace0
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)