// File: /workspace/github_c_makefile_star2_O1/janet-lang[P]janet/src/core/value.c
// Function: janet_getindex
Janet janet_getindex(Janet ds, int32_t index) {
    Janet value;
    if (index < 0) janet_panic("expected non-negative index");
    switch (janet_type(ds)) {
        default:
            janet_panicf("expected %T, got %v", JANET_TFLAG_LENGTHABLE, ds);
            break;
        case JANET_STRING:
        case JANET_SYMBOL:
        case JANET_KEYWORD:
            if (index >= janet_string_length(janet_unwrap_string(ds))) {
                value = janet_wrap_nil();
            } else {
                value = janet_wrap_integer(janet_unwrap_string(ds)[index]);
            }
            break;
        case JANET_ARRAY:
            if (index >= janet_unwrap_array(ds)->count) {
                value = janet_wrap_nil();
            } else {
                value = janet_unwrap_array(ds)->data[index];
            }
            break;
        case JANET_BUFFER:
            if (index >= janet_unwrap_buffer(ds)->count) {
                value = janet_wrap_nil();
            } else {
                value = janet_wrap_integer(janet_unwrap_buffer(ds)->data[index]);
            }
            break;
        case JANET_TUPLE:
            if (index >= janet_tuple_length(janet_unwrap_tuple(ds))) {
                value = janet_wrap_nil();
            } else {
                value = janet_unwrap_tuple(ds)[index];
            }
            break;
        case JANET_TABLE:
            value = janet_table_get(janet_unwrap_table(ds), janet_wrap_integer(index));
            break;
        case JANET_STRUCT:
            value = janet_struct_get(janet_unwrap_struct(ds), janet_wrap_integer(index));
            break;
        case JANET_ABSTRACT: {
            JanetAbstractType *type = (JanetAbstractType *)janet_abstract_type(janet_unwrap_abstract(ds));
            if (type->get) {
                if (!(type->get)(janet_unwrap_abstract(ds), janet_wrap_integer(index), &value))
                    value = janet_wrap_nil();
            } else {
                janet_panicf("no getter for %v ", ds);
            }
            break;
        }
        case JANET_FIBER: {
            if (index == 0) {
                value = janet_unwrap_fiber(ds)->last_value;
            } else {
                value = janet_wrap_nil();
            }
            break;
        }
    }
    return value;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
testl %esi, %esi
js 0x4bb8e
movq %rdi, %r14
movq %rdi, %xmm0
movq %rdi, %rcx
shrq $0x2f, %rcx
andl $0xf, %ecx
xorl %eax, %eax
ucomisd %xmm0, %xmm0
cmovpl %ecx, %eax
addl $-0x3, %eax
cmpl $0xb, %eax
ja 0x4bb9a
movl %esi, %ebx
leaq 0x20dcc(%rip), %rcx     # 0x6c804
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, %rdi
callq 0x4f838
cmpl %ebx, -0x8(%rax)
jle 0x4bb6c
movq %r14, %rdi
callq 0x4f838
jmp 0x4bb1b
movq %r14, %rdi
callq 0x4f838
movq %rax, %r14
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
callq 0x4fab8
movq %r14, %rdi
movq %rax, %rsi
callq 0x47388
jmp 0x4bb7b
movq %r14, %rdi
callq 0x4f838
cmpl %ebx, 0x10(%rax)
jle 0x4bb6c
movq %r14, %rdi
callq 0x4f838
movq 0x18(%rax), %rax
jmp 0x4bafa
testl %ebx, %ebx
jne 0x4bb6c
movq %r14, %rdi
callq 0x4f838
movq 0x40(%rax), %rax
jmp 0x4bb7b
movq %r14, %rdi
callq 0x4f838
movq %rax, %r14
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
callq 0x4fab8
movq %r14, %rdi
movq %rax, %rsi
callq 0x47f51
jmp 0x4bb7b
movq %r14, %rdi
callq 0x4f838
cmpl %ebx, -0x10(%rax)
jle 0x4bb6c
movq %r14, %rdi
callq 0x4f838
movl %ebx, %ecx
movq (%rax,%rcx,8), %rax
jmp 0x4bb7b
movq %r14, %rdi
callq 0x4f838
cmpl %ebx, 0x10(%rax)
jle 0x4bb6c
movq %r14, %rdi
callq 0x4f838
movq 0x18(%rax), %rax
movl %ebx, %ecx
movzbl (%rax,%rcx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
callq 0x4fab8
jmp 0x4bb7b
movq %r14, %rdi
callq 0x4f838
movq -0x10(%rax), %rax
movq 0x18(%rax), %r15
testq %r15, %r15
je 0x4bbb0
movq %r14, %rdi
callq 0x4f838
movq %rax, %r14
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
callq 0x4fab8
leaq -0x20(%rbp), %rdx
movq %r14, %rdi
movq %rax, %rsi
callq *%r15
testl %eax, %eax
jne 0x4bb7f
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4f95a
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x20dc3(%rip), %rdi     # 0x6c958
callq 0x19263
leaq 0x9546(%rip), %rdi      # 0x550e7
movl $0xff0, %esi            # imm = 0xFF0
movq %r14, %rdx
xorl %eax, %eax
callq 0x1917b
leaq 0x20d78(%rip), %rdi     # 0x6c92f
movq %r14, %rsi
xorl %eax, %eax
callq 0x1917b