// File: /workspace/github_c_makefile_star2_O2/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 $0x78, %rsp
movq %r9, %r12
movq %r8, %rbp
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, (%rsp)
leaq 0xf995c(%rip), %rax     # 0x117dd0
movq (%rax), %rsi
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x717f5
andq $0x0, 0x10(%r14)
movq 0x8(%r13), %rax
testq %rax, %rax
je 0x1e4ca
movq 0x8(%r15), %rdx
movabsq $-0x59040ffc58933ff2, %rcx # imm = 0xA6FBF003A76CC00E
cmpq %rcx, %rdx
je 0x1e4f4
movabsq $0x213393bef2495d15, %rsi # imm = 0x213393BEF2495D15
cmpq %rsi, %rdx
je 0x1e4e8
testq %rdx, %rdx
jne 0x1e500
movq 0x20(%r13), %rdx
movq 0x20(%r15), %rcx
leaq 0x8f0e6(%rip), %rsi     # 0xad5ae
jmp 0x1e4d9
movq 0x20(%r13), %rdx
movq 0x20(%r15), %rcx
leaq 0x8f099(%rip), %rsi     # 0xad572
movq %rbx, %rdi
xorl %eax, %eax
callq 0xd7c4
jmp 0x1e599
leaq 0x8f12a(%rip), %rsi     # 0xad619
jmp 0x1e58f
leaq 0x8f0eb(%rip), %rsi     # 0xad5e6
jmp 0x1e58f
cmpq %rsi, %rax
je 0x1e513
cmpq %rcx, %rax
jne 0x1e51c
leaq 0x8f13b(%rip), %rsi     # 0xad64c
jmp 0x1e58f
leaq 0x8f163(%rip), %rsi     # 0xad67d
jmp 0x1e58f
movabsq $0x65c9718e19e3df34, %rdx # imm = 0x65C9718E19E3DF34
movq 0x10(%r13), %rax
movq 0x10(%r15), %rcx
cmpq %rdx, %rax
jne 0x1e54f
cmpq %rdx, %rcx
je 0x1e569
cmpq $0x0, 0x20(%r13)
jle 0x1e54f
cmpq $0x0, 0x20(%r15)
jle 0x1e54f
leaq 0x8f161(%rip), %rsi     # 0xad6ae
jmp 0x1e58f
movabsq $-0x12e90733f18038df, %rdx # imm = 0xED16F8CC0E7FC721
cmpq %rdx, %rcx
setne %cl
cmpq %rdx, %rax
sete %al
orb %cl, %al
je 0x1e588
movq %r13, %rdi
movq %r15, %rsi
callq 0xea8c
testb %al, %al
je 0x1e5b8
movq %r12, %rdi
movq %rbp, %rsi
callq 0x1e42a
jmp 0x1e834
leaq 0x8f13d(%rip), %rsi     # 0xad6cc
movq %rbx, %rdi
xorl %eax, %eax
callq 0xd7c4
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x71b64
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x48(%rsp), %r14
movq %r14, 0x10(%rsp)
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0x717f5
movq $0x1, 0x10(%r14)
movq 0x8(%r15), %rsi
cmpq 0x8(%r13), %rsi
jne 0x1e5e9
xorl %r14d, %r14d
jmp 0x1e78f
movq (%rsp), %r14
movq %r14, %rdi
callq 0x1e874
testb %al, %al
je 0x1e66d
cmpq $0x1, 0x20(%r15)
jne 0x1e66d
movq 0x8(%r13), %rsi
movq %r14, %rdi
callq 0x1e874
movq %r14, %rcx
movb $0x1, %r14b
testb %al, %al
jne 0x1e78f
movq 0x8(%r13), %rsi
movq %rcx, %rdi
callq 0x1e881
movq 0x8(%r13), %rsi
testb %al, %al
je 0x1e773
movq (%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x16085
cmpb $0x0, 0x38(%rax)
jne 0x1e78f
cmpb $0x0, 0x2b(%r15)
jne 0x1e78f
movq 0x8(%r13), %rsi
movq (%rsp), %rdi
callq 0x1cf9d
leaq 0x8f085(%rip), %rdi     # 0xad6ed
jmp 0x1e865
leaq 0x8f152(%rip), %rdi     # 0xad7c6
xorl %eax, %eax
callq 0x8ec7d
movabsq $-0x503db0e6e1c2e704, %rdx # imm = 0xAFC24F191E3D18FC
xorl %r14d, %r14d
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0x71967
testq %rax, %rax
je 0x1e78f
movq %rax, 0x8(%rsp)
xorl %eax, %eax
callq 0x8eb65
leaq 0x48(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
movabsq $-0x503db0e6e1c2e704, %r12 # imm = 0xAFC24F191E3D18FC
movq %r12, %rdx
movq %rax, %rcx
callq 0x71967
movq %rax, %rbp
xorl %eax, %eax
callq 0x8eb65
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %rax, %rcx
callq 0x71967
movq %rax, %r14
movq (%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x1d257
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1d257
xorl %eax, %eax
callq 0x8eb65
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
movabsq $-0x503db0e6e1c2e704, %rdx # imm = 0xAFC24F191E3D18FC
movq %rax, %rcx
callq 0x71967
movq %rax, %r15
movq 0x8(%rbp), %rdx
movq 0x8(%r14), %rcx
leaq 0x8f0c1(%rip), %rsi     # 0xad7fb
movq %rax, %rdi
xorl %eax, %eax
callq 0x8f4ef
leaq 0x8f0eb(%rip), %rsi     # 0xad836
movq %r15, %rdi
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x8f4ef
leaq 0x962c1(%rip), %rsi     # 0xb4a22
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xd7c4
movq %rax, %rbx
jmp 0x1e7ce
movq (%rsp), %rdi
callq 0x1e88a
testb %al, %al
je 0x1e845
cmpb $0x0, 0x2b(%r15)
je 0x1e851
callq 0x2637f
leaq 0x48(%rsp), %rdi
pushq $0x1
popq %rsi
movabsq $-0x7850996cdf80346a, %rdx # imm = 0x87AF6693207FCB96
movq %rax, %rcx
callq 0x71967
movq 0x20(%r15), %rcx
movq %rbx, %rsi
movq %r13, %rdx
movq %rax, %r13
movq %rbp, %r8
movq %rax, %r9
callq 0x1e317
movq %rax, %rbx
testq %rax, %rax
je 0x1e7d8
leaq 0x48(%rsp), %rdi
jmp 0x1e5a1
testb %r14b, %r14b
je 0x1e814
callq 0x266e0
movq %rax, %rbx
movq %r15, %rdi
callq 0xe0b1
movq %rax, %r14
movq %r13, %rdi
callq 0x6026d
movq %rbx, %rdi
movq (%rsp), %rsi
movq %r14, %rdx
movq %rax, %rcx
callq 0x1e8d4
movq %rbx, %rdi
callq 0x1e893
jmp 0x1e81f
movq %r13, %rdi
callq 0x6026d
movq %rax, %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1de41
leaq 0x10(%rsp), %rdi
callq 0x71b48
leaq 0x18(%rsp), %rdi
callq 0x71b64
xorl %ebx, %ebx
jmp 0x1e5a6
leaq 0x8ef58(%rip), %rdi     # 0xad7a4
jmp 0x1e674
movq 0x8(%r13), %rsi
movq (%rsp), %rdi
callq 0x1cf9d
leaq 0x8eedf(%rip), %rdi     # 0xad744
movq %rax, %rsi
xorl %eax, %eax
callq 0x8ec7d
jmp 0x1e67b