// File: /workspace/github_c_makefile_star2_O3/mahrr[P]raven/src/compiler.c
// Function: string_interpolated
static void string_interpolated(Parser *parser) {
    Debug_Log(parser);

    Allocator *allocator = &parser->vm->allocator;
    RavString *begin = object_string(
        allocator,
        parser->previous.lexeme + 1, // +1 advances the double quote
        parser->previous.length - 3  // -3 for the delimiters count
    );
    emit_constant(parser, Obj_Value(begin));

    while (parser->previous.type != TOKEN_STRING_END) {
        expression(parser);
        emit_byte(parser, OP_CONCAT);

        bool string_part = consume_if(parser, TOKEN_STRING_PART);
        bool string_end = consume_if(parser, TOKEN_STRING_END);

        if (string_part || string_end) {
            const char *chars = parser->previous.lexeme + 2; // +2 advances '}}'
            int length = 0;

            // enclosed between '}}' and '{{'
            if (string_part) {
                length = parser->previous.length - 4;
            }
            // enclosed between '}}' and '"'
            else if (string_end) {
                length = parser->previous.length - 3;
            }

            if (length != 0) {
                RavString *part = object_string(allocator, chars, length);
                emit_constant(parser, Obj_Value(part));
                emit_byte(parser, OP_CONCAT);
            }
        } else {
            error_current(parser, "ill-formed interpolated string");
            break;
        }
    }

    Debug_Exit(parser);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movabsq $-0x4000000000000, %r14 # imm = 0xFFFC000000000000
movq 0x10(%rdi), %rdi
movq 0x38(%rbx), %rsi
incq %rsi
movl 0x40(%rbx), %edx
addl $-0x3, %edx
movq %rdi, 0x8(%rsp)
callq 0x4fd0
orq %r14, %rax
movq 0x8(%rbx), %rcx
movq 0x8(%rcx), %rdi
addq $0x20, %rdi
movq %rax, %rsi
callq 0x4b99
cmpl $0x100, %eax            # imm = 0x100
jl 0x82de
leaq 0x3630(%rip), %rsi      # 0xb8eb
movq %rbx, %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x621b
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rdi
movl $0x0, 0x848(%rdi)
xorl %ebp, %ebp
jmp 0x82e8
movl %eax, %ebp
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rdi
movl 0x44(%rbx), %edx
addq $0x20, %rdi
movl $0x3, %esi
callq 0x4af1
movq 0x8(%rbx), %rax
movl 0x44(%rbx), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movzbl %bpl, %esi
callq 0x4af1
cmpl $0x34, 0x30(%rbx)
je 0x84d8
leaq 0x30(%rbx), %r13
leaq 0x18(%rbx), %r15
leaq 0x10(%rsp), %r12
movq %rbx, %rdi
movl $0x1, %esi
callq 0x679e
movq 0x8(%rbx), %rax
movl 0x44(%rbx), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl $0x24, %esi
callq 0x4af1
movl 0x18(%rbx), %r14d
movl %r14d, %ebp
cmpl $0x33, %r14d
jne 0x8391
movq 0x10(%r15), %rax
movq %rax, 0x10(%r13)
movups (%r15), %xmm0
movups %xmm0, (%r13)
movq (%rbx), %rsi
movq %r12, %rdi
callq 0x941f
movq 0x20(%rsp), %rax
movq %rax, 0x10(%r15)
movups 0x10(%rsp), %xmm0
movups %xmm0, (%r15)
movl 0x18(%rbx), %ebp
cmpl $0x35, %ebp
je 0x836c
cmpl $0x34, %ebp
jne 0x83ca
movq 0x10(%r15), %rax
movq %rax, 0x10(%r13)
movups (%r15), %xmm0
movups %xmm0, (%r13)
movq (%rbx), %rsi
movq %r12, %rdi
callq 0x941f
movq 0x20(%rsp), %rax
movq %rax, 0x10(%r15)
movups 0x10(%rsp), %xmm0
movups %xmm0, (%r15)
cmpl $0x35, 0x18(%rbx)
je 0x83a7
cmpl $0x34, %ebp
setne %al
cmpl $0x33, %r14d
setne %cl
testb %al, %cl
jne 0x84c6
cmpl $0x34, %ebp
setne %al
cmpl $0x33, %r14d
setne %cl
testb %al, %cl
jne 0x84b9
xorl %edx, %edx
cmpl $0x33, %r14d
sete %dl
xorl $-0x3, %edx
addl 0x40(%rbx), %edx
je 0x84b9
movq 0x38(%rbx), %rsi
addq $0x2, %rsi
movq 0x8(%rsp), %rdi
callq 0x4fd0
movabsq $-0x4000000000000, %rcx # imm = 0xFFFC000000000000
orq %rcx, %rax
movq 0x8(%rbx), %rcx
movq 0x8(%rcx), %rdi
addq $0x20, %rdi
movq %rax, %rsi
callq 0x4b99
cmpl $0x100, %eax            # imm = 0x100
jl 0x846d
movq %rbx, %rdi
leaq 0x349e(%rip), %rsi      # 0xb8eb
movl $0x100, %edx            # imm = 0x100
callq 0x621b
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rdi
movl $0x0, 0x848(%rdi)
xorl %ebp, %ebp
jmp 0x8477
movl %eax, %ebp
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rdi
movl 0x44(%rbx), %edx
addq $0x20, %rdi
movl $0x3, %esi
callq 0x4af1
movq 0x8(%rbx), %rax
movl 0x44(%rbx), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movzbl %bpl, %esi
callq 0x4af1
movq 0x8(%rbx), %rax
movl 0x44(%rbx), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl $0x24, %esi
callq 0x4af1
cmpl $0x34, (%r13)
jne 0x8328
jmp 0x84d8
leaq 0x388d(%rip), %rdx      # 0xbd5a
movq %rbx, %rdi
movq %r15, %rsi
callq 0x61ef
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq