// File: /workspace/github_c_makefile_star2_O2/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 0x47499
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 0x474a5
movl %esi, %ebx
leaq 0x204e1(%rip), %rcx     # 0x67804
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, %rdi
callq 0x4b1f1
cmpl %ebx, -0x8(%rax)
jle 0x47426
movq %r14, %rdi
callq 0x4b1f1
jmp 0x4740d
movq %r14, %rdi
callq 0x4b1f1
movq %rax, %r14
cvtsi2sd %ebx, %xmm0
callq 0x4b471
movq %r14, %rdi
movq %rax, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x430d3
movq %r14, %rdi
callq 0x4b1f1
cmpl %ebx, 0x10(%rax)
jle 0x47426
movq %r14, %rdi
callq 0x4b1f1
movq 0x18(%rax), %rax
jmp 0x473e9
testl %ebx, %ebx
jne 0x47426
movq %r14, %rdi
callq 0x4b1f1
movq 0x40(%rax), %rax
jmp 0x4748e
movq %r14, %rdi
callq 0x4b1f1
movq %rax, %r14
cvtsi2sd %ebx, %xmm0
callq 0x4b471
movq %r14, %rdi
movq %rax, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x43c35
movq %r14, %rdi
callq 0x4b1f1
cmpl %ebx, -0x10(%rax)
jle 0x47426
movq %r14, %rdi
callq 0x4b1f1
movl %ebx, %ecx
movq (%rax,%rcx,8), %rax
jmp 0x4748e
movq %r14, %rdi
callq 0x4b1f1
cmpl %ebx, 0x10(%rax)
jle 0x47426
movq %r14, %rdi
callq 0x4b1f1
movq 0x18(%rax), %rax
movl %ebx, %ecx
movzbl (%rax,%rcx), %eax
cvtsi2sd %eax, %xmm0
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x4b471
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x4b313
movq %r14, %rdi
callq 0x4b1f1
movq -0x10(%rax), %rax
movq 0x18(%rax), %r15
testq %r15, %r15
je 0x474bb
movq %r14, %rdi
callq 0x4b1f1
movq %rax, %r14
cvtsi2sd %ebx, %xmm0
callq 0x4b471
leaq -0x20(%rbp), %rdx
movq %r14, %rdi
movq %rax, %rsi
callq *%r15
testl %eax, %eax
je 0x4747f
movq -0x20(%rbp), %rax
jmp 0x4748e
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4b313
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x204b8(%rip), %rdi     # 0x67958
callq 0x177b1
leaq 0x8c3b(%rip), %rdi      # 0x500e7
movl $0xff0, %esi            # imm = 0xFF0
movq %r14, %rdx
xorl %eax, %eax
callq 0x176c9
leaq 0x2046d(%rip), %rdi     # 0x6792f
movq %r14, %rsi
xorl %eax, %eax
callq 0x176c9