// File: /workspace/github_c_makefile_star2_O3/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 0x4afc2
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 0x4afce
movl %esi, %ebx
leaq 0x209a4(%rip), %rcx     # 0x6b7e4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, %rdi
callq 0x4ebc4
cmpl %ebx, -0x8(%rax)
jle 0x4af4c
movq %r14, %rdi
callq 0x4ebc4
jmp 0x4af30
movq %r14, %rdi
callq 0x4ebc4
movq %rax, %r14
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
callq 0x4ee44
movq %r14, %rdi
movq %rax, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x46988
movq %r14, %rdi
callq 0x4ebc4
cmpl %ebx, 0x10(%rax)
jle 0x4af4c
movq %r14, %rdi
callq 0x4ebc4
movq 0x18(%rax), %rax
jmp 0x4af0c
testl %ebx, %ebx
jne 0x4af4c
movq %r14, %rdi
callq 0x4ebc4
movq 0x40(%rax), %rax
jmp 0x4afb7
movq %r14, %rdi
callq 0x4ebc4
movq %rax, %r14
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
callq 0x4ee44
movq %r14, %rdi
movq %rax, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x474e0
movq %r14, %rdi
callq 0x4ebc4
cmpl %ebx, -0x10(%rax)
jle 0x4af4c
movq %r14, %rdi
callq 0x4ebc4
movl %ebx, %ecx
movq (%rax,%rcx,8), %rax
jmp 0x4afb7
movq %r14, %rdi
callq 0x4ebc4
cmpl %ebx, 0x10(%rax)
jle 0x4af4c
movq %r14, %rdi
callq 0x4ebc4
movq 0x18(%rax), %rax
movl %ebx, %ecx
movzbl (%rax,%rcx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x4ee44
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x4ece6
movq %r14, %rdi
callq 0x4ebc4
movq -0x10(%rax), %rax
movq 0x18(%rax), %r15
testq %r15, %r15
je 0x4afe4
movq %r14, %rdi
callq 0x4ebc4
movq %rax, %r14
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
callq 0x4ee44
leaq -0x20(%rbp), %rdx
movq %r14, %rdi
movq %rax, %rsi
callq *%r15
testl %eax, %eax
je 0x4afa8
movq -0x20(%rbp), %rax
jmp 0x4afb7
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4ece6
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2096f(%rip), %rdi     # 0x6b938
callq 0x191a3
leaq 0x9112(%rip), %rdi      # 0x540e7
movl $0xff0, %esi            # imm = 0xFF0
movq %r14, %rdx
xorl %eax, %eax
callq 0x190bb
leaq 0x20924(%rip), %rdi     # 0x6b90f
movq %r14, %rsi
xorl %eax, %eax
callq 0x190bb