// File: /workspace/github_c_makefile_star2_O2/ryvnf[P]czc/eval.c
// Function: sizeof_type
size_t sizeof_type(struct loc *loc, struct type *type)
{
    switch (type_type(type->tag)) {
        case VOID_TYPE_FLAG:
            fatal(loc, "cannot compute the size of void");
            return 0;
        case FUNC_TYPE_FLAG:
            fatal(loc, "cannot compute the size of a function");
            return 0;
        case BOOL_TYPE_FLAG:
        case INT_TYPE_FLAG:
        case FLOAT_TYPE_FLAG:
            return sizeof_basic_type(type);
        case PTR_TYPE_FLAG:
            // This would not be portable on computers where size of function
            // pointers is different from regular pointers.
            return sizeof (void *);
        case ARRAY_TYPE_FLAG: {
            struct type *elem_type = array_type(type)->of;
            size_t elem_size = sizeof_type(loc, elem_type);
            size_t elem_align = alignof_type(loc, elem_type);
            size_t n_elems = array_type(type)->len;
            return align_size(elem_size, elem_align) * n_elems;
        }
        case STRUCT_TYPE_FLAG: {
            size_t n_fields = struct_type(type)->n_fields;
            struct field *fields = struct_type(type)->fields;
            size_t size = 0;

            for (size_t i = 0; i < n_fields; i++) {
                size_t field_size = sizeof_type(loc, fields[i].type);
                size_t field_align = alignof_type(loc, fields[i].type);
                size += align_size(field_size, field_align);
            }

            return size;
        }
    }

    unreachable();
    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rsi, %r15
movq %rdi, %rbx
movl (%rsi), %r14d
andl $0x3ff, %r14d           # imm = 0x3FF
leal -0x1(%r14), %eax
cmpl $0x7, %eax
jbe 0x5e50
cmpl $0x10, %r14d
je 0x5e71
cmpl $0x40, %r14d
je 0x5ecb
cmpl $0x80, %r14d
je 0x5e60
cmpl $0x20, %r14d
jne 0x5f29
leaq 0x619e(%rip), %rsi      # 0xbfe9
jmp 0x5f51
leaq 0x5ca5(%rip), %rcx      # 0xbafc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r15, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0xa404
movq %r15, %rdi
callq 0xa7aa
movq 0x8(%rax), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5dff
movq %rax, %r12
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5cfc
movq %rax, %r14
movq %r15, %rdi
callq 0xa7aa
movq %rax, %rcx
movq %r12, %rax
xorl %edx, %edx
divq %r14
subq %rdx, %r14
testq %rdx, %rdx
cmoveq %rdx, %r14
addq %r12, %r14
imulq 0x10(%rcx), %r14
movq %r14, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %r15, %rdi
callq 0xa80e
movq 0x10(%rax), %r13
movq %r15, %rdi
callq 0xa80e
movq %rax, %r15
addq $0x28, %r15
xorl %r14d, %r14d
subq $0x1, %r13
jb 0x5ebe
movq (%r15), %rsi
movq %rbx, %rdi
callq 0x5dff
movq %rax, %r12
movq (%r15), %rsi
movq %rbx, %rdi
callq 0x5cfc
movq %rax, %rcx
movq %r12, %rax
xorl %edx, %edx
divq %rcx
subq %rdx, %rcx
testq %rdx, %rdx
cmoveq %rdx, %rcx
addq %r12, %r14
addq %rcx, %r14
addq $0x10, %r15
jmp 0x5ee9
leaq 0x5f90(%rip), %rdi      # 0xbec0
leaq 0x5faf(%rip), %rsi      # 0xbee6
leaq 0x60de(%rip), %rcx      # 0xc01c
movl $0x34b, %edx            # imm = 0x34B
xorl %eax, %eax
callq 0x4918
leaq 0x6078(%rip), %rsi      # 0xbfc9
movq %rbx, %rdi
xorl %eax, %eax
callq 0x4a05