// File: /workspace/github_c_makefile_star2_O3/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
cmpl $0xf, %r14d
jg 0x660b
leal -0x1(%r14), %eax
cmpl $0x7, %eax
ja 0x6717
leaq 0x7506(%rip), %rcx      # 0xdafc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x79c3(%rip), %rsi      # 0xdfc9
jmp 0x670d
cmpl $0x3f, %r14d
jle 0x6635
cmpl $0x40, %r14d
je 0x668e
cmpl $0x80, %r14d
jne 0x6717
movq %r15, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0xb4e8
cmpl $0x10, %r14d
jne 0x6700
movq %r15, %rdi
callq 0xb969
movq 0x8(%rax), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x65c3
movq %rax, %r12
movq %rbx, %rdi
movq %r14, %rsi
callq 0x64a8
movq %rax, %r14
movq %r15, %rdi
callq 0xb969
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
jmp 0x66f3
movq %r15, %rdi
callq 0xb9cd
movq 0x10(%rax), %r13
movq %r15, %rdi
callq 0xb9cd
testq %r13, %r13
je 0x66f0
movq %rax, %r15
addq $0x28, %r15
xorl %r14d, %r14d
movq (%r15), %rsi
movq %rbx, %rdi
callq 0x65c3
movq %rax, %r12
movq (%r15), %rsi
movq %rbx, %rdi
callq 0x64a8
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
decq %r13
jne 0x66b1
jmp 0x66f3
xorl %r14d, %r14d
movq %r14, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
cmpl $0x20, %r14d
jne 0x6717
leaq 0x78dc(%rip), %rsi      # 0xdfe9
movq %rbx, %rdi
xorl %eax, %eax
callq 0x4fa1
leaq 0x77a2(%rip), %rdi      # 0xdec0
leaq 0x77c1(%rip), %rsi      # 0xdee6
leaq 0x78f0(%rip), %rcx      # 0xe01c
movl $0x34b, %edx            # imm = 0x34B
xorl %eax, %eax
callq 0x4eac