// File: /workspace/github_c_makefile_star2_O0/mahrr[P]raven/src/mem.c
// Function: free_object
static void free_object(Allocator *allocator, Object *object) {
#ifdef DEUBG_TRACE_MEMORY
    printf("[Memory] %p : free type %d\n", object, object->type);
#endif

    switch (object->type) {
    case OBJ_STRING: {
        RavString *string = (RavString *)object;
        Free_Array(allocator, char, string->chars, string->length + 1);
        Free(allocator, RavString, string);
        break;
    }

    case OBJ_PAIR: {
        Free(allocator, RavPair, object);
        break;
    }

    case OBJ_ARRAY: {
        RavArray *array = (RavArray *)object;
        Free_Array(allocator, Value, array->values, array->capacity);
        Free(allocator, RavArray, array);
        break;
    }

    case OBJ_MAP: {
        RavMap *map = (RavMap *)object;
        table_free(&map->table);
        Free(allocator, RavMap, map);
        break;
    }

    case OBJ_FUNCTION: {
        RavFunction *function = (RavFunction *)object;
        chunk_free(&function->chunk);
        Free(allocator, RavFunction, function);
        break;
    }

    case OBJ_UPVALUE: {
        Free(allocator, RavUpvalue, object);
        break;
    }

    case OBJ_CLOSURE: {
        RavClosure *closure = (RavClosure *)object;
        Free_Array(allocator, RavClosure*, closure->upvalues, closure->upvalue_count);
        Free(allocator, RavClosure, object);
        break;
    }

    case OBJ_CFUNCTION: {
        Free(allocator, RavCFunction, object);
        break;
    }

    default:
        assert(!"invalid object type");
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x40(%rbp)
subq $0x7, %rax
ja 0xd771
movq -0x40(%rbp), %rax
leaq 0x1e3d(%rip), %rcx      # 0xf42c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
addl $0x1, %eax
movslq %eax, %rdx
shlq $0x0, %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0xd7a0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x20, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0xd7a0
jmp 0xd790
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x20, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0xd7a0
jmp 0xd790
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdx
shlq $0x3, %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0xd7a0
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x28, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0xd7a0
jmp 0xd790
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
addq $0x10, %rdi
callq 0x7290
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl $0x20, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0xd7a0
jmp 0xd790
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
addq $0x20, %rdi
callq 0x6fc0
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl $0x850, %edx            # imm = 0x850
xorl %eax, %eax
movl %eax, %ecx
callq 0xd7a0
jmp 0xd790
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x28, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0xd7a0
jmp 0xd790
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x38(%rbp), %rax
movslq 0x20(%rax), %rdx
shlq $0x3, %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0xd7a0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x28, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0xd7a0
jmp 0xd790
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x20, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0xd7a0
jmp 0xd790
leaq 0xebd(%rip), %rdi       # 0xe635
leaq 0x1ce5(%rip), %rsi      # 0xf464
movl $0x50, %edx
leaq 0x1ce3(%rip), %rcx      # 0xf46e
callq 0x20e0
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)