// File: /workspace/github_c_makefile_star2_O3/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 0x16418f(%rip), %rax    # 0x19bdd0
movq (%rax), %rsi
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0xd6675
movq $0x0, 0x10(%r14)
movq 0x8(%r13), %rax
testq %rax, %rax
je 0x37c9a
movq 0x8(%r15), %rdx
movabsq $-0x59040ffc58933ff2, %rcx # imm = 0xA6FBF003A76CC00E
cmpq %rcx, %rdx
je 0x37cc4
movabsq $0x213393bef2495d15, %rsi # imm = 0x213393BEF2495D15
cmpq %rsi, %rdx
je 0x37cb8
testq %rdx, %rdx
jne 0x37cd0
movq 0x20(%r13), %rdx
movq 0x20(%r15), %rcx
leaq 0xf8916(%rip), %rsi     # 0x1305ae
jmp 0x37ca9
movq 0x20(%r13), %rdx
movq 0x20(%r15), %rcx
leaq 0xf88c9(%rip), %rsi     # 0x130572
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde10
jmp 0x37d69
leaq 0xf895a(%rip), %rsi     # 0x130619
jmp 0x37d5f
leaq 0xf891b(%rip), %rsi     # 0x1305e6
jmp 0x37d5f
cmpq %rsi, %rax
je 0x37ce3
cmpq %rcx, %rax
jne 0x37cec
leaq 0xf896b(%rip), %rsi     # 0x13064c
jmp 0x37d5f
leaq 0xf8993(%rip), %rsi     # 0x13067d
jmp 0x37d5f
movabsq $0x65c9718e19e3df34, %rdx # imm = 0x65C9718E19E3DF34
movq 0x10(%r13), %rax
movq 0x10(%r15), %rcx
cmpq %rdx, %rax
jne 0x37d1f
cmpq %rdx, %rcx
je 0x37d39
cmpq $0x0, 0x20(%r13)
jle 0x37d1f
cmpq $0x0, 0x20(%r15)
jle 0x37d1f
leaq 0xf8991(%rip), %rsi     # 0x1306ae
jmp 0x37d5f
movabsq $-0x12e90733f18038df, %rdx # imm = 0xED16F8CC0E7FC721
cmpq %rdx, %rcx
setne %cl
cmpq %rdx, %rax
sete %al
orb %cl, %al
je 0x37d58
movq %r13, %rdi
movq %r15, %rsi
callq 0x11e6e
testb %al, %al
je 0x37d88
movq %r12, %rdi
movq %rbp, %rsi
callq 0x37b5f
jmp 0x38071
leaq 0xf896d(%rip), %rsi     # 0x1306cc
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde10
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0xd6d2c
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 0xd6675
movq $0x1, 0x10(%r14)
movq 0x8(%r15), %rsi
cmpq 0x8(%r13), %rsi
jne 0x37db9
xorl %r14d, %r14d
jmp 0x37fb8
movq (%rsp), %r14
movq 0x18(%r14), %rdi
addq $0x50, %rdi
callq 0xca9a0
testb %al, %al
je 0x37e8e
cmpq $0x1, 0x20(%r15)
jne 0x37e8e
movq 0x8(%r13), %rsi
movq 0x18(%r14), %rdi
addq $0x50, %rdi
callq 0xca9a0
movq %r14, %rcx
movb $0x1, %r14b
testb %al, %al
jne 0x37fb8
movq 0x8(%r13), %rsi
movq 0x18(%rcx), %rdi
addq $0x78, %rdi
callq 0xca94f
testq %rax, %rax
je 0x37f94
movq (%rax), %rax
testq %rax, %rax
je 0x37f94
movabsq $0x12d01d78049fae7, %rcx # imm = 0x12D01D78049FAE7
cmpq %rcx, (%rax)
jne 0x37f94
movq 0x8(%r13), %rsi
movq (%rsp), %rax
movq 0x18(%rax), %rdi
addq $0x78, %rdi
callq 0xca94f
movq (%rax), %rax
xorl %ecx, %ecx
movabsq $0x12d01d78049fae7, %rdx # imm = 0x12D01D78049FAE7
cmpq %rdx, (%rax)
cmoveq %rax, %rcx
cmpb $0x0, 0x38(%rcx)
jne 0x37fb8
cmpb $0x0, 0x2b(%r15)
jne 0x37fb8
movq 0x8(%r13), %rsi
movq (%rsp), %rdi
callq 0x31f9d
leaq 0xf8864(%rip), %rdi     # 0x1306ed
jmp 0x380a2
leaq 0xf8931(%rip), %rdi     # 0x1307c6
xorl %eax, %eax
callq 0x109dca
movabsq $-0x503db0e6e1c2e704, %rdx # imm = 0xAFC24F191E3D18FC
xorl %r14d, %r14d
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0xd68a8
testq %rax, %rax
je 0x37fb8
movq %rax, 0x8(%rsp)
xorl %eax, %eax
callq 0x109c82
leaq 0x48(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
movabsq $-0x503db0e6e1c2e704, %r12 # imm = 0xAFC24F191E3D18FC
movq %r12, %rdx
movq %rax, %rcx
callq 0xd68a8
movq %rax, %rbp
xorl %eax, %eax
callq 0x109c82
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %rax, %rcx
callq 0xd68a8
movq %rax, %r14
movq (%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x3246c
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x3246c
xorl %eax, %eax
callq 0x109c82
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
movabsq $-0x503db0e6e1c2e704, %rdx # imm = 0xAFC24F191E3D18FC
movq %rax, %rcx
callq 0xd68a8
movq %rax, %r15
movq 0x8(%rbp), %rdx
movq 0x8(%r14), %rcx
leaq 0xf88a0(%rip), %rsi     # 0x1307fb
movq %rax, %rdi
xorl %eax, %eax
callq 0x10a8a5
leaq 0xf88ca(%rip), %rsi     # 0x130836
movq %r15, %rdi
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x10a8a5
leaq 0xff680(%rip), %rsi     # 0x137602
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xde10
movq %rax, %rbx
jmp 0x37ff9
movq 0x8(%r13), %rsi
movq (%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x30b69
testb %al, %al
je 0x38082
cmpb $0x0, 0x2b(%r15)
je 0x3808e
callq 0x46f7e
leaq 0x48(%rsp), %rdi
movabsq $-0x7850996cdf80346a, %rdx # imm = 0x87AF6693207FCB96
movl $0x1, %esi
movq %rax, %rcx
callq 0xd68a8
movq 0x20(%r15), %rcx
movq %rbx, %rsi
movq %r13, %rdx
movq %rax, %r13
movq %rbp, %r8
movq %rax, %r9
callq 0x37633
movq %rax, %rbx
testq %rax, %rax
je 0x38003
leaq 0x48(%rsp), %rdi
jmp 0x37d71
testb %r14b, %r14b
je 0x38051
callq 0x48423
movq %rax, %rbx
movq %r15, %rdi
callq 0x10128
movq %rax, %r14
movq %r13, %rdi
callq 0xbe7e4
movq %rax, %r15
movq (%rsp), %rax
movq %rax, 0x8(%rbx)
movq 0x10(%rbx), %rdi
callq 0x1006b
movq %r14, 0x10(%rbx)
leaq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0x48bb5
movq %rbx, %rdi
callq 0x380b1
jmp 0x3805c
movq %r13, %rdi
callq 0xbe7e4
movq %rax, %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x355d5
leaq 0x10(%rsp), %rdi
callq 0xd6d0d
leaq 0x18(%rsp), %rdi
callq 0xd6d2c
xorl %ebx, %ebx
jmp 0x37d76
leaq 0xf871b(%rip), %rdi     # 0x1307a4
jmp 0x37e95
movq 0x8(%r13), %rsi
movq (%rsp), %rdi
callq 0x31f9d
leaq 0xf86a2(%rip), %rdi     # 0x130744
movq %rax, %rsi
xorl %eax, %eax
callq 0x109dca
jmp 0x37e9c