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

    // scan through to end sequence ('}') or illegal name chars
    char *name = build + i + 2;
    size_t j = strcspn(name, "} \t$\\{");
    if (name[j] != '}') {
        fprintf(stderr, "Warning: no closing brace ('}') found in build "
                "command after `%s'\n  Consider escaping the characters "
                "'${' like so: '\\$\\{'\n", build + i);
        goto recover;
    } else if (j == 0) { // empty var name
        fprintf(stderr, "Warning: no name in env var reference in build "
                "rule at `%s'\n  Unless you are missing a variable name, "
                "consider escaping the '${' like so: '\\$\\{'\n", build + i);
        goto recover;
    }

    assert(name[j] == '}');
    // end brace found - look up env var
    name[j] = '\0';
    char *value = getenv(name);
    name[j] = '}';

    if (value) {
        sb_add_str(sb, value);
    } // else empty env var - nothing to copy

    return i + 2 + j + 1;
 recover:
    sb_add_char(sb, '$');
    return i + 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x24, %eax
jne 0x2d99
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movsbl 0x1(%rax,%rcx), %eax
cmpl $0x7b, %eax
jne 0x2d99
jmp 0x2db8
leaq 0x76a8(%rip), %rdi      # 0xa448
leaq 0x76c8(%rip), %rsi      # 0xa46f
movl $0x13a, %edx            # imm = 0x13A
leaq 0x76c9(%rip), %rcx      # 0xa47c
callq 0x2120
movq -0x18(%rbp), %rax
addq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
leaq 0x76eb(%rip), %rsi      # 0xa4be
callq 0x2160
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x7d, %eax
je 0x2e12
movq 0xc204(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
addq -0x20(%rbp), %rdx
leaq 0x76bf(%rip), %rsi      # 0xa4c5
movb $0x0, %al
callq 0x21a0
jmp 0x2ec1
cmpq $0x0, -0x30(%rbp)
jne 0x2e3e
movq 0xc1d8(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
addq -0x20(%rbp), %rdx
leaq 0x770e(%rip), %rsi      # 0xa540
movb $0x0, %al
callq 0x21a0
jmp 0x2ec1
jmp 0x2e40
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x7d, %eax
jne 0x2e53
jmp 0x2e72
leaq 0x7778(%rip), %rdi      # 0xa5d2
leaq 0x760e(%rip), %rsi      # 0xa46f
movl $0x14b, %edx            # imm = 0x14B
leaq 0x760f(%rip), %rcx      # 0xa47c
callq 0x2120
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x28(%rbp), %rdi
callq 0x2030
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movb $0x7d, (%rax,%rcx)
cmpq $0x0, -0x38(%rbp)
je 0x2eab
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x9480
movq -0x20(%rbp), %rax
addq $0x2, %rax
addq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
jmp 0x2edb
movq -0x10(%rbp), %rdi
movl $0x24, %esi
callq 0x93d0
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)