// File: /workspace/github_c_makefile_star2_O1/johsteffens[P]beth/xoico/src/xoico.xo.c
// Function: xoico_che_s_adapt_expression
er_t xoico_che_s_adapt_expression( xoico_che_s* o, x_source* source, const xoico_typespec_s* typespec_expr, const xoico_typespec_s* typespec_target, const xoico_che_result* result_expr, xoico_che_result* result )
{
    // xoico_che.x:812:1
    BLM_INIT_LEVEL(0);
    if( !typespec_expr->type )
    {
        BLM_RETURNV(er_t, x_source_parse_error_fa(source,"xoico_che_s_adapt_expression: no expression type specified.",
            typespec_expr->indirection,
            typespec_target->indirection
        ))
    }
    
    if( !typespec_target->type )
    {
        BLM_RETURNV(er_t, x_source_parse_error_fa(source,"xoico_che_s_adapt_expression: no target type specified.",
            typespec_expr->indirection,
            typespec_target->indirection
        ))
    }
    
    if( typespec_target->type == ((tp_t)(TYPEOF_type_deduce)) ) BLM_RETURNV(er_t, x_source_parse_error_fa(source,"adapt_expression: typespec_target is 'type_deduce'" ))
    if( typespec_target->type == ((tp_t)(TYPEOF_type_object)) ) BLM_RETURNV(er_t, x_source_parse_error_fa(source,"adapt_expression: typespec_target is 'type_object'" ))
    if( typespec_expr->type == ((tp_t)(TYPEOF_type_deduce)) ) BLM_RETURNV(er_t, x_source_parse_error_fa(source,"adapt_expression: typespec_expr is 'type_deduce'" ))
    if( typespec_expr->type == ((tp_t)(TYPEOF_type_object)) ) BLM_RETURNV(er_t, x_source_parse_error_fa(source,"adapt_expression: typespec_expr is 'type_object'" ))
    
    bl_t discarding_const =
        ( typespec_expr->access_class == TYPEOF_const && typespec_expr->access_class != typespec_target->access_class ) &&
        ( typespec_expr->indirection > 0 && typespec_target->indirection > 0 );
    
    if( discarding_const ) BLM_RETURNV(er_t, x_source_parse_error_fa(source,"Discarding 'const' qualifier." ))
    
    if( typespec_target->access_class == TYPEOF_discardable && typespec_expr->access_class != TYPEOF_discardable )
    {
        BLM_RETURNV(er_t, x_source_parse_error_fa(source,"Discardable expression expected." ))
    }
    
    if( xoico_typespec_s_converts_to(typespec_expr,typespec_target ) )
    {
        xoico_che_result_a_push_result_c(result,result_expr );
    }
    else
    {BLM_INIT_LEVEL(1);
        bl_t implicit_cast = false;
        st_s* fail_msg = NULL;
        if( typespec_target->type != typespec_expr->type )
        {
            if( xoico_che_s_is_group(o,typespec_target->type ) && typespec_target->indirection == 1 )
            {
                if( xoico_che_s_is_group(o,typespec_expr->type ) )
                {
                    implicit_cast = true;
                }
                else if( xoico_che_s_is_stamp(o,typespec_expr->type ) )
                {
                    const xoico_stamp_s* stamp = xoico_che_s_get_stamp(o,typespec_expr->type );
                    if( stamp->is_aware || typespec_target->flag_obliv )
                    {
                        implicit_cast = true;
                    }
                    else
                    {
                        fail_msg = ((st_s*)BLM_LEVEL_T_PUSH(0,st_s,st_s_create_fa("'#<sc_t>' is obliv but the target typespec does not explicitly tolerate obliv objects.", xoico_che_s_nameof(o,typespec_expr->type ) )));
                    }
                }
                else if( xoico_che_s_is_type(o,typespec_expr->type ) )
                {
                    if( typespec_target->flag_obliv )
                    {
                        implicit_cast = true;
                    }
                    else
                    {
                        fail_msg = ((st_s*)BLM_LEVEL_T_PUSH(0,st_s,st_s_create_fa("'#<sc_t>' is presumed obliv but the target typespec does not explicitly tolerate obliv objects.", xoico_che_s_nameof(o,typespec_expr->type ) )));
                    }
                }
                else
                {
                    fail_msg = ((st_s*)BLM_LEVEL_T_PUSH(0,st_s,st_s_create_fa("Source type cannot be classified." )));
                }
            }
            else
            {
                fail_msg = ((st_s*)BLM_LEVEL_T_PUSH(0,st_s,st_s_create_fa("Target is not a group or target indirection is != 1." )));
            }
        }
    
        if( fail_msg )
        {
            st_s* st_typespec_expr = ((st_s*)BLM_LEVEL_T_PUSH(0,st_s,st_s_create()));
            st_s* st_typespec_target = ((st_s*)BLM_LEVEL_T_PUSH(0,st_s,st_s_create()));
            xoico_che_s_typespec_to_sink(o,typespec_expr,((x_sink*)( st_typespec_expr )));
            xoico_che_s_typespec_to_sink(o,typespec_target,((x_sink*)( st_typespec_target )));
            st_s* msg = ((st_s*)BLM_LEVEL_T_PUSH(0,st_s,st_s_create()));
            st_s_push_fa(msg,"Implicit cast from '#<sc_t>' to '#<sc_t>' is not allowed. ", st_typespec_expr->sc, st_typespec_target->sc );
            st_s_push_fa(msg,"Reason: #<st_s*>\n", fail_msg );
            BLM_RETURNV(er_t, x_source_parse_error_fa(source,"#<st_s*>", msg ))
        }
    
        xoico_che_result* result_expression =((xoico_che_result*)( ((xoico_che_result_arr_s*)BLM_LEVEL_T_PUSH(1,xoico_che_result_arr_s,xoico_che_result_arr_s_create()))));
        BLM_TRY(xoico_che_s_adapt_expression_indirection(o,source, typespec_expr, typespec_target->indirection, result_expr, result_expression ))
    
        if( implicit_cast )
        {
            xoico_che_result_a_push_result_d(result,((xoico_che_result*)(xoico_che_result_cast_s_reduce(xoico_che_result_cast_s__(xoico_che_result_cast_s_create(),o, xoico_typespec_s_clone(typespec_target), ((xoico_che_result*)bcore_fork(result_expression)) )) )));
        }
        else
        {
            xoico_che_result_a_push_result_d(result,((xoico_che_result*)bcore_fork(result_expression)) );
        }
    
    BLM_DOWN();}
    BLM_RETURNV(er_t, 0)
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, %r12
movq %r8, %rbp
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, (%rsp)
leaq 0x16e5b0(%rip), %rax    # 0x1a8dd0
movq (%rax), %rsi
leaq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0xe0431
movq $0x0, 0x10(%r14)
movq 0x8(%r13), %rax
testq %rax, %rax
je 0x3a879
movq 0x8(%r15), %rdx
movabsq $-0x59040ffc58933ff2, %rcx # imm = 0xA6FBF003A76CC00E
cmpq %rcx, %rdx
je 0x3a8a0
movabsq $0x213393bef2495d15, %rsi # imm = 0x213393BEF2495D15
cmpq %rsi, %rdx
je 0x3a897
testq %rdx, %rdx
jne 0x3a8a9
movq 0x20(%r13), %rdx
movq 0x20(%r15), %rcx
leaq 0x100d37(%rip), %rsi    # 0x13b5ae
jmp 0x3a888
movq 0x20(%r13), %rdx
movq 0x20(%r15), %rcx
leaq 0x100cea(%rip), %rsi    # 0x13b572
movq %rbx, %rdi
xorl %eax, %eax
callq 0xddb2
jmp 0x3a91b
leaq 0x100d7b(%rip), %rsi    # 0x13b619
jmp 0x3a911
leaq 0x100d3f(%rip), %rsi    # 0x13b5e6
jmp 0x3a911
cmpq %rsi, %rax
je 0x3a8bc
cmpq %rcx, %rax
jne 0x3a8c5
leaq 0x100d92(%rip), %rsi    # 0x13b64c
jmp 0x3a911
leaq 0x100dba(%rip), %rsi    # 0x13b67d
jmp 0x3a911
movabsq $0x65c9718e19e3df34, %rcx # imm = 0x65C9718E19E3DF34
movq 0x10(%r13), %rax
cmpq %rcx, %rax
jne 0x3a8f5
cmpq %rcx, 0x10(%r15)
je 0x3a8f5
cmpq $0x0, 0x20(%r13)
jle 0x3a8f5
cmpq $0x0, 0x20(%r15)
jle 0x3a8f5
leaq 0x100dbb(%rip), %rsi    # 0x13b6ae
jmp 0x3a911
movabsq $-0x12e90733f18038df, %rcx # imm = 0xED16F8CC0E7FC721
cmpq %rcx, %rax
je 0x3a93d
cmpq %rcx, 0x10(%r15)
jne 0x3a93d
leaq 0x100dbb(%rip), %rsi    # 0x13b6cc
movq %rbx, %rdi
xorl %eax, %eax
callq 0xddb2
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0xe0b30
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
movq %r15, %rsi
callq 0x12150
testb %al, %al
je 0x3a95c
movq %r12, %rdi
movq %rbp, %rsi
callq 0x3a736
jmp 0x3ab35
leaq 0x58(%rsp), %rdi
movq %rdi, 0x8(%rsp)
leaq 0x28(%rsp), %rsi
callq 0xe0431
movq 0x8(%rsp), %rax
movq %rax, 0x10(%rsp)
movq $0x1, 0x10(%rax)
movq 0x8(%r15), %rsi
cmpq 0x8(%r13), %rsi
jne 0x3a993
xorl %ecx, %ecx
xorl %r14d, %r14d
jmp 0x3a9ff
movq (%rsp), %r14
movq 0x18(%r14), %rdi
addq $0x50, %rdi
callq 0xd4857
testb %al, %al
je 0x3a9d2
cmpq $0x1, 0x20(%r15)
jne 0x3a9d2
movq 0x8(%r13), %rsi
movq 0x18(%r14), %rdi
addq $0x50, %rdi
callq 0xd4857
movq %r14, %rcx
movb $0x1, %r14b
testb %al, %al
je 0x3ab9c
xorl %ecx, %ecx
jmp 0x3a9ff
leaq 0x100ded(%rip), %rdi    # 0x13b7c6
xorl %eax, %eax
callq 0x114d03
xorl %r14d, %r14d
movq 0x10(%rsp), %rdi
xorl %esi, %esi
movabsq $-0x503db0e6e1c2e704, %rdx # imm = 0xAFC24F191E3D18FC
movq %rax, %rcx
callq 0xe0676
movq %rax, %rcx
testq %rcx, %rcx
je 0x3aae0
xorl %eax, %eax
movq %rcx, 0x20(%rsp)
callq 0x114bbb
movq 0x10(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
movabsq $-0x503db0e6e1c2e704, %r14 # imm = 0xAFC24F191E3D18FC
movq %r14, %rdx
movq %rax, %rcx
callq 0xe0676
movq %rax, 0x18(%rsp)
xorl %eax, %eax
callq 0x114bbb
movq %r12, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %rax, %rcx
callq 0xe0676
movq %rax, %r14
movq (%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movq 0x18(%rsp), %r13
movq %r13, %rdx
callq 0x3467f
movq %rbp, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x3467f
xorl %eax, %eax
callq 0x114bbb
movq %r12, %rdi
xorl %esi, %esi
movabsq $-0x503db0e6e1c2e704, %rdx # imm = 0xAFC24F191E3D18FC
movq %rax, %rcx
callq 0xe0676
movq %rax, %r15
movq 0x8(%r13), %rdx
movq 0x8(%r14), %rcx
leaq 0x100d54(%rip), %rsi    # 0x13b7fb
movq %rax, %rdi
xorl %eax, %eax
callq 0x1157cb
leaq 0x100d7e(%rip), %rsi    # 0x13b836
movq %r15, %rdi
movq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x1157cb
leaq 0x107cbc(%rip), %rsi    # 0x14278a
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xddb2
movq %rax, %rbx
jmp 0x3ab21
callq 0x4c277
movabsq $-0x7850996cdf80346a, %rdx # imm = 0x87AF6693207FCB96
movl $0x1, %esi
movq 0x10(%rsp), %rdi
movq %rax, %rcx
callq 0xe0676
movq 0x20(%r15), %rcx
movq %rbx, %rsi
movq %r13, %rdx
movq %rbp, %r8
movq %rax, %rbp
movq %rax, %r9
callq 0x3a0ec
movq %rax, %rbx
testq %rax, %rax
je 0x3ab3c
movq 0x8(%rsp), %rdi
callq 0xe0b30
xorl %eax, %eax
testb %al, %al
je 0x3a928
xorl %ebx, %ebx
jmp 0x3a91e
testb %r14b, %r14b
je 0x3ab78
callq 0x4d7c2
movq %rax, %r13
movq %r15, %rdi
callq 0x101d1
movq %rax, %r14
movq %rbp, %rdi
callq 0xc8348
movq %r13, %rdi
movq (%rsp), %rsi
movq %r14, %rdx
movq %rax, %rcx
callq 0x3ad7d
movq %r13, %rdi
callq 0x3ac97
jmp 0x3ab83
movq %rbp, %rdi
callq 0xc8348
movq %rax, %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x37d93
leaq 0x8(%rsp), %rdi
callq 0xe0b11
movb $0x1, %al
jmp 0x3ab2d
movq 0x8(%r13), %rsi
movq %rcx, %rdi
callq 0x3ac2f
movq 0x8(%r13), %rsi
testb %al, %al
je 0x3abe4
movq (%rsp), %rdi
callq 0x3ac63
cmpb $0x0, 0x38(%rax)
jne 0x3a9ce
cmpb $0x0, 0x2b(%r15)
jne 0x3a9ce
movq 0x8(%r13), %rsi
movq (%rsp), %rdi
callq 0x3417e
leaq 0x100b0b(%rip), %rdi    # 0x13b6ed
jmp 0x3ac14
movq (%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x32c57
testb %al, %al
je 0x3ac23
cmpb $0x0, 0x2b(%r15)
jne 0x3a9ce
movq 0x8(%r13), %rsi
movq (%rsp), %rdi
callq 0x3417e
leaq 0x100b30(%rip), %rdi    # 0x13b744
movq %rax, %rsi
xorl %eax, %eax
callq 0x114d03
jmp 0x3a9e0
leaq 0x100b7a(%rip), %rdi    # 0x13b7a4
jmp 0x3a9d9