// File: /workspace/github_c_makefile_star2_O0/nerves-project[P]nerves_initramfs/src/uboot_env.c
// Function: uboot_env_read
int uboot_env_read(struct uboot_env *env, const char *buffer)
{
    uboot_env_free(env);

    uint32_t expected_crc32 = ((uint8_t) buffer[0] | ((uint8_t) buffer[1] << 8) | ((uint8_t) buffer[2] << 16) | ((uint8_t) buffer[3] << 24));
    uint32_t actual_crc32 = crc32buf(buffer + 4, env->env_size - 4);
    if (expected_crc32 != actual_crc32)
        ERR_RETURN("U-boot environment CRC32 mismatch (expected 0x%08x; got 0x%08x)", expected_crc32, actual_crc32);

    const char *end = buffer + env->env_size;
    const char *name = buffer + 4;
    while (name != end && *name != '\0') {
        const char *endname = name + 1;
        for (;;) {
            if (endname == end || *endname == '\0')
                ERR_RETURN("Invalid U-boot environment");

            if (*endname == '=')
                break;

            endname++;
        }

        const char *value = endname + 1;
        const char *endvalue = value;
        for (;;) {
            if (endvalue == end)
                ERR_RETURN("Invalid U-boot environment");

            if (*endvalue == '\0')
                break;

            endvalue++;
        }

        struct uboot_name_value *pair = malloc(sizeof(struct uboot_name_value));
        pair->name = strndup(name, endname - name);
        pair->value = strndup(value, value - endvalue);
        pair->next = env->vars;
        env->vars = pair;

        name = endvalue + 1;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x38f0
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
movq -0x18(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movq -0x18(%rbp), %rcx
movzbl 0x2(%rcx), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movq -0x18(%rbp), %rcx
movzbl 0x3(%rcx), %ecx
shll $0x18, %ecx
orl %ecx, %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
addq $0x4, %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
subq $0x4, %rsi
callq 0x3640
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x376f
jmp 0x374f
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %edx
leaq 0x90a4(%rip), %rdi      # 0xc800
movb $0x0, %al
callq 0x32a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x38e4
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
addq (%rcx), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rcx
xorl %eax, %eax
cmpq -0x28(%rbp), %rcx
movb %al, -0x51(%rbp)
je 0x37a9
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x37b5
jmp 0x38dd
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x28(%rbp), %rax
je 0x37d7
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x37f3
jmp 0x37d9
leaq 0x9060(%rip), %rdi      # 0xc840
movb $0x0, %al
callq 0x32a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x38e4
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3d, %eax
jne 0x3801
jmp 0x380f
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x37c1
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x3849
jmp 0x382f
leaq 0x900a(%rip), %rdi      # 0xc840
movb $0x0, %al
callq 0x32a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x38e4
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x3857
jmp 0x3865
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x3823
movl $0x18, %edi
callq 0x2330
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rax
subq %rax, %rsi
callq 0x2290
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rax
subq %rax, %rsi
callq 0x2290
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x50(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x378a
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)