// File: /workspace/github_c_makefile_star2_O0/ieyasu[P]funit/build_rule.c
// Function: parse_internal_var
static size_t parse_internal_var(struct BRFragments *f,
                                 struct StringBuffer *sb,
                                 char *build, size_t i)
{
    assert(build[i] == '{' && build[i + 1] == '{');

    // find end of var name
     char *name = build + i + 2;
     size_t j = 0;
     while (name[j] != '\0' && name[j] != '}') j++;

     if (j == 0) {
         warn_ivar("no name given in build var reference at", build + i);
         goto recover;
     } else if (name[j] != '}' || name[j + 1] != '}') { // no "}}" terminator
         warn_ivar("no closing braces ('}}') after", build + i);
         goto recover;
     }

     name[j] = '\0'; // temporarily nul-terminate for strcmp and print purposes

     // name found, match against names in ivars[]
     struct IVar *ivar = NULL;
     for (size_t i = 0; i < n_ivars; i++) {
         if (!strcmp(name, ivars[i].name)) { // matching name
             ivar = &ivars[i];
             break;
         }
     }

     if (!ivar) {
         warn_ivar("no such build var", name);
         name[j] = '}';
         goto recover;
     }

     name[j] = '}'; // redo close brace

     // match success - append variable's value
     close_string_fragment(f, sb);
     add_ivar_fragment(f, ivar);

     return i + 2 + j + 2; // continue after closing braces

 recover: // error matching name or close braces
     sb_add_nstr(sb, "{{", 2);
     return i + 2; // continue after opening braces
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x7b, %eax
jne 0x2f2d
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl 0x1(%rax,%rcx), %eax
cmpl $0x7b, %eax
jne 0x2f2d
jmp 0x2f4c
leaq 0x76ad(%rip), %rdi      # 0xa5e1
leaq 0x7534(%rip), %rsi      # 0xa46f
movl $0x107, %edx            # imm = 0x107
leaq 0x76c1(%rip), %rcx      # 0xa608
callq 0x2120
movq -0x20(%rbp), %rax
addq -0x28(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x49(%rbp)
je 0x2f8f
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x7d, %eax
setne %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x2f98
jmp 0x2fa6
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2f64
cmpq $0x0, -0x38(%rbp)
jne 0x2fc6
movq -0x20(%rbp), %rsi
addq -0x28(%rbp), %rsi
leaq 0x76a3(%rip), %rdi      # 0xa65f
callq 0x32f0
jmp 0x30d3
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x7d, %eax
jne 0x2fe9
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movsbl 0x1(%rax,%rcx), %eax
cmpl $0x7d, %eax
je 0x3002
movq -0x20(%rbp), %rsi
addq -0x28(%rbp), %rsi
leaq 0x768f(%rip), %rdi      # 0xa687
callq 0x32f0
jmp 0x30d3
jmp 0x3004
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
cmpq $0x9, -0x48(%rbp)
jae 0x3072
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rcx
leaq 0xc13a(%rip), %rax      # 0xf170
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x2190
cmpl $0x0, %eax
jne 0x3062
movq -0x48(%rbp), %rcx
leaq 0xc11b(%rip), %rax      # 0xf170
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
jmp 0x3072
jmp 0x3064
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x3020
cmpq $0x0, -0x40(%rbp)
jne 0x3097
movq -0x30(%rbp), %rsi
leaq 0x7622(%rip), %rdi      # 0xa6a6
callq 0x32f0
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movb $0x7d, (%rax,%rcx)
jmp 0x30d3
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movb $0x7d, (%rax,%rcx)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3100
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x3330
movq -0x28(%rbp), %rax
addq $0x2, %rax
addq -0x38(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x8(%rbp)
jmp 0x30f4
movq -0x18(%rbp), %rdi
leaq 0x75da(%rip), %rsi      # 0xa6b8
movl $0x2, %edx
callq 0x9420
movq -0x28(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nop