// File: /workspace/github_c_makefile_star2_O2/johsteffens[P]beth/xoico/src/xoico.xo.c
// Function: xoico_che_s_trans_builtin_scope
er_t xoico_che_s_trans_builtin_scope( xoico_che_s* o, x_source* source, const xoico_che_result* result_expr, const xoico_typespec_s* typespec_expr, xoico_che_result* result_out, xoico_typespec_s* typespec_out )
{
    // xoico_che_builtin.x:156:1
    BLM_INIT_LEVEL(0);
    bl_t has_arg = false;
    bl_t closing_bracket = true;
    
    sz_t level = 0;
    
    if( result_expr ) // member call
    {
        if( x_source_parse_bl(source,"#?'^'" ) )
        {
            level = x_source_parse_bl(source,"#?'^'" ) ? 0 : o->block_level;
    
            if( !o->waive_local_scope_operator_creates_implicit_block )
            {
                if( level > 0 && xoico_che_s_stack_block_get_top_unit(o)->statement_wrapped_as_block )
                {
                    BLM_RETURNV(er_t, x_source_parse_error_fa(source,"Scope operator '^' creates an implicit block. Please use an explicit block  '{ ... }' or choose a different scope operator to clarify your intention ." ))
                }
            }
            closing_bracket = false;
        }
        else
        {
            BLM_TRY(x_source_parse_fa(source," ( " ))
            xoico_che_result_a_clear(result_out);
            has_arg = !x_source_parse_bl(source,"#=?')'" );
        }
    }
    else // direct call
    {
        BLM_TRY(x_source_parse_fa(source,"scope ( " ))
        xoico_che_result_arr_s* result = ((xoico_che_result_arr_s*)BLM_LEVEL_T_PUSH(0,xoico_che_result_arr_s,xoico_che_result_arr_s_create()));
        xoico_typespec_s* typespec = ((xoico_typespec_s*)BLM_LEVEL_T_PUSH(0,xoico_typespec_s,xoico_typespec_s_create()));
        BLM_TRY(xoico_che_s_trans_expression(o,source,((xoico_che_result*)( result)), typespec ))
        typespec_expr = typespec;
        result_expr =((const xoico_che_result*)( result));
        has_arg = x_source_parse_bl(source,"#?','" );
    }
    
    if( typespec_expr->type == 0 ) BLM_RETURNV(er_t, x_source_parse_error_fa(source,"scope: Expression not tractable." ))
    if( typespec_expr->access_class != TYPEOF_discardable ) BLM_RETURNV(er_t, x_source_parse_error_fa(source,"scope: Expression is not discardable." ))
    xoico_typespec_s* typespec_scope = ((xoico_typespec_s*)BLM_LEVEL_T_PUSH(0,xoico_typespec_s,xoico_typespec_s_clone(typespec_expr)));
    typespec_scope->access_class = TYPEOF_mutable;
    
    BLM_TRY(xoico_che_result_a_push_sc(result_out,"((" ))
    
    if( has_arg )
    {
        BLM_TRY(x_source_parse_fa(source," " ))
        tp_t tp_identifier = xoico_che_s_get_identifier(o,source, true );
    
        if( xoico_che_s_is_var(o,tp_identifier ) )
        {
            level = xoico_che_stack_var_s_get_level(&(o->stack_var),tp_identifier );
        }
        else if( tp_identifier == ((tp_t)(TYPEOF_scope_local)) )
        {
            level = o->block_level;
        }
        else if( tp_identifier == ((tp_t)(TYPEOF_scope_func)) )
        {
            level = 0;
        }
        else
        {
            BLM_RETURNV(er_t, x_source_parse_error_fa(source,"scope: identifier '#<sc_t>' does not represent a variable.", xoico_che_s_nameof(o,tp_identifier ) ))
        }
    }
    
    if( closing_bracket ) BLM_TRY(x_source_parse_fa(source," )" ))
    
    if( typespec_scope->indirection != 1 ) BLM_RETURNV(er_t, x_source_parse_error_fa(source,"scope: Expression's indirection != 1." ))
    if( typespec_scope->flag_scope )       BLM_RETURNV(er_t, x_source_parse_error_fa(source,"scope: Target is already scoped." ))
    
    BLM_TRY(xoico_che_s_push_typespec(o,typespec_scope, result_out ))
    
    if( xoico_che_s_is_group(o,typespec_scope->type ) )
    {
        if( typespec_scope->flag_obliv )
        {
            BLM_RETURNV(er_t, x_source_parse_error_fa(source,"scope: Expression yields an oblivious typespec of a group. Use t_scope to clarify which type is intended." ))
        }
        BLM_TRY(xoico_che_result_push_fa(result_out,")BLM_LEVEL_A_PUSH(#<sz_t>,", level ))
        xoico_che_result_a_push_result_c(result_out,result_expr );
        BLM_TRY(xoico_che_result_a_push_sc(result_out,"))" ))
    }
    else
    {
        BLM_TRY(xoico_che_result_push_fa(result_out,")BLM_LEVEL_T_PUSH(#<sz_t>,#<sc_t>,", level, xoico_che_s_nameof(o,typespec_scope->type ) ))
        xoico_che_result_a_push_result_c(result_out,result_expr );
        BLM_TRY(xoico_che_result_a_push_sc(result_out,"))" ))
    }
    
    o->stack_block.adl.data[ level ]->use_blm = true;
    
    if( typespec_out )
    {
        xoico_typespec_s_copy(typespec_out,typespec_scope );
        typespec_out->flag_scope = true;
    }
    
    BLM_RETURNV(er_t, 0)
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %rbp
movq %r8, %r13
movq %rcx, (%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
leaq 0xf8ca8(%rip), %rax     # 0x117dd0
movq (%rax), %rsi
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x717f5
andq $0x0, 0x10(%rbx)
movq %r14, 0x20(%rsp)
testq %r14, %r14
je 0x1f18a
leaq 0x8b590(%rip), %rsi     # 0xaa6de
movq %r15, %rdi
callq 0xe5ff
testb %al, %al
movq %r13, 0x18(%rsp)
je 0x1f23d
leaq 0x8b574(%rip), %rsi     # 0xaa6de
movq %r15, %rdi
callq 0xe5ff
testb %al, %al
movq %r12, %r14
je 0x1f28f
movq %r15, 0x8(%rsp)
xorl %r12d, %r12d
jmp 0x1f2c9
movq %r12, %r14
movq %rbp, (%rsp)
leaq 0x8f522(%rip), %rsi     # 0xae6ba
movq %r15, %rdi
xorl %eax, %eax
callq 0xd600
testq %rax, %rax
jne 0x1f3b7
callq 0x2637f
leaq 0x28(%rsp), %rbx
movabsq $-0x7850996cdf80346a, %rdx # imm = 0x87AF6693207FCB96
movq %rbx, %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0x71967
movq %r15, %r12
movq %rax, %r15
callq 0xe090
movabsq $-0x641110359430e9c5, %rdx # imm = 0x9BEEEFCA6BCF163B
movq %rbx, %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0x71967
movq %rax, %rbx
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rax, %rcx
callq 0x1fc8a
testq %rax, %rax
jne 0x1f3b7
movq %r15, 0x20(%rsp)
movq %r13, 0x18(%rsp)
leaq 0x8d13e(%rip), %rsi     # 0xac35a
movq %r12, 0x8(%rsp)
movq %r12, %rdi
callq 0xe5ff
movl %eax, %r15d
movb $0x1, %cl
xorl %r12d, %r12d
movq (%rsp), %rbp
movq %rbx, %rdi
jmp 0x1f2d2
movq %r12, %r13
movq %rbp, %r14
leaq 0x8f475(%rip), %rsi     # 0xae6bf
movq %r15, %rdi
xorl %eax, %eax
callq 0xd600
testq %rax, %rax
jne 0x1f3b7
movq 0x18(%rsp), %rdi
callq 0x235f4
leaq 0x8b283(%rip), %rsi     # 0xaa4f1
movq %r15, 0x8(%rsp)
movq %r15, %rdi
callq 0xe5ff
movl %eax, %r15d
xorb $0x1, %r15b
movb $0x1, %cl
xorl %r12d, %r12d
movq %r14, %rbp
movq %r13, %r14
jmp 0x1f2ce
movq 0x28(%r14), %r12
testq %r12, %r12
setle %al
orb 0xf(%r14), %al
jne 0x1f2c4
movq 0x98(%r14), %rax
movq 0xa0(%r14), %rcx
movq -0x8(%rax,%rcx,8), %rax
cmpb $0x1, 0x12(%rax)
jne 0x1f2c4
leaq 0x8f364(%rip), %rsi     # 0xae623
jmp 0x1f43e
movq %r15, 0x8(%rsp)
xorl %ecx, %ecx
xorl %r15d, %r15d
movq (%rsp), %rdi
cmpq $0x0, 0x8(%rdi)
je 0x1f39b
movabsq $-0x12e90733f18038df, %rax # imm = 0xED16F8CC0E7FC721
cmpq %rax, 0x10(%rdi)
jne 0x1f3a4
movq %rcx, 0x10(%rsp)
movq %rbp, (%rsp)
callq 0xe0b1
leaq 0x28(%rsp), %rdi
movabsq $-0x641110359430e9c5, %rdx # imm = 0x9BEEEFCA6BCF163B
xorl %esi, %esi
movq %rax, %rcx
callq 0x71967
movq %rax, %rbx
movabsq $-0x2c53c3baa9910217, %rax # imm = 0xD3AC3C45566EFDE9
movq %rax, 0x10(%rbx)
leaq 0x8f291(%rip), %rsi     # 0xae5c1
movq 0x18(%rsp), %r13
movq %r13, %rdi
callq 0x1d59d
testq %rax, %rax
jne 0x1f3b7
testb %r15b, %r15b
movq 0x8(%rsp), %r15
je 0x1f404
leaq 0xa2426(%rip), %rsi     # 0xc177d
movq %r15, %rdi
xorl %eax, %eax
callq 0xd600
testq %rax, %rax
jne 0x1f3b7
movq %rbx, %rbp
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x1d5df
movq %rax, %rbx
leaq 0x60(%r14), %rdi
movq %rax, %rsi
callq 0x67ae9
testb %al, %al
je 0x1f3d6
leaq 0x38(%r14), %rdi
movq %rbx, %rsi
callq 0x2511f
movq %rax, %r12
jmp 0x1f401
leaq 0x8f321(%rip), %rsi     # 0xae6c3
jmp 0x1f3ab
leaq 0x8f339(%rip), %rsi     # 0xae6e4
movq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0xd7c4
movq %rax, %rbp
leaq 0x28(%rsp), %rdi
callq 0x71b64
movq %rbp, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movabsq $0x5e9151f1091c19ba, %rax # imm = 0x5E9151F1091C19BA
cmpq %rax, %rbx
je 0x1f3fe
movabsq $-0x38096408726e4e99, %rax # imm = 0xC7F69BF78D91B167
cmpq %rax, %rbx
jne 0x1f486
movq 0x28(%r14), %r12
jmp 0x1f401
xorl %r12d, %r12d
movq %rbp, %rbx
cmpb $0x0, 0x10(%rsp)
je 0x1f421
leaq 0xa9ad4(%rip), %rsi     # 0xc8ee6
movq %r15, %rdi
xorl %eax, %eax
callq 0xd600
testq %rax, %rax
jne 0x1f3b7
cmpq $0x1, 0x20(%rbx)
jne 0x1f437
cmpb $0x1, 0x2d(%rbx)
jne 0x1f446
leaq 0x8f336(%rip), %rsi     # 0xae76b
jmp 0x1f43e
leaq 0x8f307(%rip), %rsi     # 0xae745
movq %r15, %rdi
jmp 0x1f3b0
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x1d30a
testq %rax, %rax
jne 0x1f3b7
movq 0x8(%rbx), %rsi
movq %r14, %rdi
callq 0x1e874
testb %al, %al
je 0x1f4aa
movq %rbx, 0x10(%rsp)
cmpb $0x1, 0x2b(%rbx)
movq 0x20(%rsp), %rbx
jne 0x1f4e5
leaq 0x8f308(%rip), %rsi     # 0xae78c
jmp 0x1f43e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1cf9d
leaq 0x8f272(%rip), %rsi     # 0xae70a
movq %r15, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xd7c4
jmp 0x1f3b7
movq 0x8(%rbx), %rsi
movq %r14, %rdi
callq 0x1cf9d
leaq 0x8f354(%rip), %rsi     # 0xae811
movq %r13, %rdi
movq %r12, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1edfd
testq %rax, %rax
movq 0x20(%rsp), %rsi
jne 0x1f3b7
movq %rbx, 0x10(%rsp)
movq %r13, %rdi
jmp 0x1f508
leaq 0x8f30a(%rip), %rsi     # 0xae7f6
movq %r13, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x1edfd
testq %rax, %rax
jne 0x1f3b7
movq %r13, %rdi
movq %rbx, %rsi
callq 0x1e42a
leaq 0x8dec7(%rip), %rsi     # 0xad3db
movq %r13, %rdi
callq 0x1d59d
testq %rax, %rax
jne 0x1f3b7
movq 0x98(%r14), %rax
movq (%rax,%r12,8), %rax
movb $0x1, 0x10(%rax)
movq (%rsp), %rbx
testq %rbx, %rbx
je 0x1f54e
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0xe075
movb $0x1, 0x2d(%rbx)
xorl %ebp, %ebp
jmp 0x1f3ba