// File: /workspace/github_c_makefile_star2_O2/nerves-project[P]nerves_initramfs/src/script.c
// Function: function_loadenv
static const struct term *function_loadenv(const struct term *parameters)
{
    (void)parameters;
    const char *devpathspec = get_variable_as_string("uboot_env.path");
    char devpath[BLOCK_DEVICE_PATH_LEN];

    int block = get_variable_as_number("uboot_env.start");
    int block_count = get_variable_as_number("uboot_env.count");

    working_uboot_env.env_size = block_count * 512;
    int fd = open_block_device(devpathspec, O_RDONLY, devpath);
    if (fd < 0) {
        info("Could not open '%s'", devpathspec);
        return NULL;
    }
    if (lseek(fd, block * 512, SEEK_SET) < 0) {
        info("Could not seek to block %d (byte offset %d) in '%s'", block, block * 512, devpath);
        close(fd);
        return NULL;
    }
    char *buffer = malloc(working_uboot_env.env_size);
    ssize_t amount_read = read(fd, buffer, working_uboot_env.env_size);
    close(fd);

    if (amount_read != (ssize_t) working_uboot_env.env_size) {
        free(buffer);
        info("Could not read %d blocks (%d bytes) from '%s'", block_count, working_uboot_env.env_size, devpath);
        return NULL;
    }

    set_boolean_variable("uboot_env.loaded", false);
    set_boolean_variable("uboot_env.modified", false);

    if (uboot_env_read(&working_uboot_env, buffer) < 0) {
        free(buffer);
        return NULL;
    }
    free(buffer);

    set_boolean_variable("uboot_env.loaded", true);

    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0x4043(%rip), %rdi      # 0x9684
callq 0x51af
movq %rax, %r15
leaq 0x2b9e(%rip), %rdi      # 0x81ee
callq 0x51eb
movl %eax, %r14d
leaq 0x2b9f(%rip), %rdi      # 0x81fe
callq 0x51eb
movl %eax, %ebx
shll $0x9, %eax
cltq
leaq 0x7f2e(%rip), %r13      # 0xd5a0
movq %rax, (%r13)
movq %rsp, %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x755b
testl %eax, %eax
js 0x5722
movl %eax, %ebp
movl %r14d, %r15d
shll $0x9, %r15d
movslq %r15d, %rsi
movl %eax, %edi
xorl %edx, %edx
callq 0x2220
testq %rax, %rax
js 0x5735
movq (%r13), %r15
movq %r15, %rdi
callq 0x2380
movq %rax, %r14
movl %ebp, %edi
movq %rax, %rsi
movq %r15, %rdx
callq 0x22c0
movq %rax, %r12
movl %ebp, %edi
callq 0x2280
movq (%r13), %r15
cmpq %r15, %r12
jne 0x5755
leaq 0x2aeb(%rip), %rdi      # 0x81ca
xorl %esi, %esi
callq 0x521c
leaq 0x2aee(%rip), %rdi      # 0x81db
xorl %esi, %esi
callq 0x521c
leaq 0x7ea5(%rip), %rdi      # 0xd5a0
movq %r14, %rsi
callq 0x3183
movl %eax, %ebx
movq %r14, %rdi
callq 0x2040
testl %ebx, %ebx
js 0x5773
leaq 0x2ab2(%rip), %rdi      # 0x81ca
pushq $0x1
popq %rsi
callq 0x521c
jmp 0x5773
leaq 0x3fd0(%rip), %rdi      # 0x96f9
movq %r15, %rsi
xorl %eax, %eax
callq 0x2ee4
jmp 0x5773
leaq 0x3fd1(%rip), %rdi      # 0x970d
movq %rsp, %rcx
movl %r14d, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x2ee4
movl %ebp, %edi
callq 0x2280
jmp 0x5773
movq %r14, %rdi
callq 0x2040
leaq 0x3fdd(%rip), %rdi      # 0x9741
movq %rsp, %rcx
movl %ebx, %esi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2ee4
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq