// File: /workspace/github_c_makefile_star2_O0/mahrr[P]raven/src/mem.c
// Function: blacken_object
static void blacken_object(Allocator *allocator, Object *object) {
#ifdef DEUBG_TRACE_MEMORY
    printf("[Memory] %p get blacken: ", object);
    value_print(Obj_Value(object));
    putchar('\n');
#endif

    switch (object->type) {
    case OBJ_PAIR: {
        RavPair *pair = (RavPair *)object;
        mark_value(allocator, pair->head);
        mark_value(allocator, pair->tail);
        break;
    }

    case OBJ_ARRAY: {
        RavArray *array = (RavArray *)object;
        mark_array(allocator, array->values, array->count);
        break;
    }

    case OBJ_MAP: {
        RavMap *map = (RavMap *)object;

        for (int i = 0; i <= map->table.hash_mask; i++) {
            Entry *entry = &map->table.entries[i];

            if (entry->key != NULL) {
                mark_object(allocator, (Object *)entry->key);
                mark_value(allocator, entry->value);
            }
        }

        break;
    }

    case OBJ_FUNCTION: {
        RavFunction *function = (RavFunction *)object;
        Chunk *chunk = &function->chunk;

        mark_array(allocator, chunk->constants, chunk->constants_count);
        mark_object(allocator, (Object *)function->name);

        break;
    }

    case OBJ_UPVALUE:
        mark_value(allocator, ((RavUpvalue *)object)->captured);
        break;

    case OBJ_CLOSURE: {
        RavClosure *closure = (RavClosure *)object;
        mark_object(allocator, (Object *)closure->function);

        for (int i = 0; i < closure->upvalue_count; i++) {
            mark_object(allocator, (Object *)closure->upvalues[i]);
        }

        break;
    }

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x60(%rbp)
subl $0x5, %eax
ja 0xdd7a
movq -0x60(%rbp), %rax
leaq 0x184a(%rip), %rcx      # 0xf44c
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 0x10(%rax), %rsi
callq 0xd9c0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0xd9c0
jmp 0xdd99
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 0x18(%rax), %rdx
callq 0xdda0
jmp 0xdd99
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jg 0xdcca
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, (%rax)
je 0xdcbd
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rsi
callq 0xda10
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0xd9c0
jmp 0xdcbf
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xdc6f
jmp 0xdd99
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
addq $0x20, %rsi
movq -0x48(%rbp), %rax
movslq 0x828(%rax), %rdx
callq 0xdda0
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0xda10
jmp 0xdd99
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0xd9c0
jmp 0xdd99
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0xda10
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jge 0xdd78
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0xda10
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0xdd48
jmp 0xdd99
leaq 0x8b4(%rip), %rdi       # 0xe635
leaq 0x16dc(%rip), %rsi      # 0xf464
movl $0xfe, %edx
leaq 0x1702(%rip), %rcx      # 0xf496
callq 0x20e0
addq $0x60, %rsp
popq %rbp
retq
nop