// File: /workspace/github_c_makefile_star2_O2/johsteffens[P]beth/xoico/src/xoico.xo.c
// Function: xoico_che_s_trans_builtin_t_scope
er_t xoico_che_s_trans_builtin_t_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:271:1
    BLM_INIT_LEVEL(0);
    bl_t has_arg = false;
    bl_t closing_bracket = true;
    
    sz_t level = 0;
    
    xoico_che_result_arr_s* result_type_expr = ((xoico_che_result_arr_s*)BLM_LEVEL_T_PUSH(0,xoico_che_result_arr_s,xoico_che_result_arr_s_create()));
    
    if( result_expr ) // member call
    {
        BLM_TRY(x_source_parse_fa(source," ( " ))
        xoico_che_result_a_clear(result_out);
        BLM_TRY(xoico_che_s_trans_expression(o,source,((xoico_che_result*)( result_type_expr)), NULL ))
        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));
    
        BLM_TRY(x_source_parse_fa(source," , " ))
        BLM_TRY(xoico_che_s_trans_expression(o,source,((xoico_che_result*)( result_type_expr)), NULL ))
    
        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 ))
    
    BLM_TRY(xoico_che_result_push_fa(result_out,")BLM_LEVEL_TV_PUSH(#<sz_t>,", level ))
    xoico_che_result_a_push_result_c(result_out,((const xoico_che_result*)(result_type_expr )));
    BLM_TRY(xoico_che_result_push_fa(result_out,"," ))
    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, 0x20(%rsp)
movq %r8, 0x8(%rsp)
movq %rcx, %rbx
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, (%rsp)
movabsq $-0x7850996cdf80346a, %r14 # imm = 0x87AF6693207FCB96
leaq 0xf34d0(%rip), %rax     # 0x117dd0
movq (%rax), %rsi
leaq 0x28(%rsp), %r15
movq %r15, %rdi
callq 0x717f5
andq $0x0, 0x10(%r15)
callq 0x2637f
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %rax, %rcx
callq 0x71967
movq %rax, %rbp
testq %r13, %r13
je 0x24a56
leaq 0x89d82(%rip), %rsi     # 0xae6bf
movq %r12, %rdi
xorl %eax, %eax
callq 0xd600
testq %rax, %rax
jne 0x24afe
movq 0x8(%rsp), %rdi
callq 0x235f4
movq (%rsp), %rdi
movq %r12, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x1fc8a
testq %rax, %rax
jne 0x24afe
leaq 0x879df(%rip), %rsi     # 0xac35a
movq %r12, %rdi
callq 0xe5ff
cmpq $0x0, 0x8(%rbx)
je 0x24ae4
movl %eax, %r14d
movabsq $-0x12e90733f18038df, %rax # imm = 0xED16F8CC0E7FC721
cmpq %rax, 0x10(%rbx)
jne 0x24aed
movq %rbx, %rdi
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 0x89be3(%rip), %rsi     # 0xae5c1
movq 0x8(%rsp), %rdi
callq 0x1d59d
testq %rax, %rax
jne 0x24afe
testb %r14b, %r14b
je 0x24b1d
leaq 0x9cd7c(%rip), %rsi     # 0xc177d
movq %r12, %rdi
xorl %eax, %eax
callq 0xd600
testq %rax, %rax
movq (%rsp), %r14
jne 0x24afe
movq %rbx, 0x18(%rsp)
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %r12, %rsi
callq 0x1d5df
movq %rax, %rbx
leaq 0x60(%r14), %rdi
movq %rax, %rsi
callq 0x67ae9
testb %al, %al
je 0x24b67
leaq 0x38(%r14), %rdi
movq %rbx, %rsi
callq 0x2511f
movq %rax, %rbx
jmp 0x24b28
leaq 0x89c5d(%rip), %rsi     # 0xae6ba
movq %r12, %rdi
xorl %eax, %eax
callq 0xd600
testq %rax, %rax
jne 0x24afe
callq 0x2637f
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %rax, %rcx
callq 0x71967
movq %rax, %r13
callq 0xe090
movabsq $-0x641110359430e9c5, %rdx # imm = 0x9BEEEFCA6BCF163B
movq %rbx, %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0x71967
movq %rax, %rbx
movq (%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %rax, %rcx
callq 0x1fc8a
testq %rax, %rax
jne 0x24afe
leaq 0x85890(%rip), %rsi     # 0xaa35d
movq %r12, %rdi
xorl %eax, %eax
callq 0xd600
testq %rax, %rax
jne 0x24afe
movq %r14, %rdi
jmp 0x2495e
leaq 0x89bd8(%rip), %rsi     # 0xae6c3
jmp 0x24af4
leaq 0x89bf0(%rip), %rsi     # 0xae6e4
movq %r12, %rdi
xorl %eax, %eax
callq 0xd7c4
movq %rax, %r15
leaq 0x28(%rsp), %rdi
callq 0x71b64
movq %r15, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, 0x18(%rsp)
xorl %ebx, %ebx
movq (%rsp), %r14
leaq 0xa43b7(%rip), %rsi     # 0xc8ee6
movq %r12, %rdi
xorl %eax, %eax
callq 0xd600
testq %rax, %rax
jne 0x24afe
movq %rbx, 0x10(%rsp)
movq 0x18(%rsp), %rbx
cmpq $0x1, 0x20(%rbx)
jne 0x24b5e
cmpb $0x1, 0x2d(%rbx)
jne 0x24b93
leaq 0x89c0f(%rip), %rsi     # 0xae76b
jmp 0x24af4
leaq 0x89be0(%rip), %rsi     # 0xae745
jmp 0x24af4
movabsq $0x5e9151f1091c19ba, %rax # imm = 0x5E9151F1091C19BA
cmpq %rax, %rbx
je 0x24c55
movabsq $-0x38096408726e4e99, %rax # imm = 0xC7F69BF78D91B167
cmpq %rax, %rbx
jne 0x24c5c
movq 0x28(%r14), %rbx
jmp 0x24b28
movq %r14, %rdi
movq %rbx, %rsi
movq 0x8(%rsp), %r14
movq %r14, %rdx
callq 0x1d30a
testq %rax, %rax
jne 0x24afe
movq %rbx, %r12
leaq 0x89c7b(%rip), %rsi     # 0xae834
movq %r14, %rdi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x1edfd
testq %rax, %rax
jne 0x24afe
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1e42a
leaq 0x86561(%rip), %rsi     # 0xab144
movq %r14, %rdi
xorl %eax, %eax
callq 0x1edfd
testq %rax, %rax
jne 0x24afe
movq %r14, %rdi
movq %r13, %rsi
callq 0x1e42a
leaq 0x887d3(%rip), %rsi     # 0xad3db
movq %r14, %rdi
callq 0x1d59d
testq %rax, %rax
jne 0x24afe
movq (%rsp), %rax
movq 0x98(%rax), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movb $0x1, 0x10(%rax)
cmpq $0x0, 0x20(%rsp)
je 0x24c4d
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe075
movb $0x1, 0x2d(%rbx)
xorl %r15d, %r15d
jmp 0x24b01
xorl %ebx, %ebx
jmp 0x24b28
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1cf9d
leaq 0x89a9c(%rip), %rsi     # 0xae70a
movq %r12, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xd7c4
jmp 0x24afe