// File: /workspace/github_c_makefile_star2_O1/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 0x4751(%rip), %rdi      # 0xa670
callq 0x5bba
movq %rax, %r15
leaq 0x32c0(%rip), %rdi      # 0x91ee
callq 0x5bf6
movl %eax, %r14d
leaq 0x32c1(%rip), %rdi      # 0x91fe
callq 0x5bf6
movl %eax, %ebx
shll $0x9, %eax
cltq
leaq 0x8650(%rip), %r13      # 0xe5a0
movq %rax, (%r13)
movq %rsp, %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x8340
testl %eax, %eax
js 0x601e
movl %eax, %ebp
movl %r14d, %r15d
shll $0x9, %r15d
movslq %r15d, %rsi
movl %eax, %edi
xorl %edx, %edx
callq 0x2220
testq %rax, %rax
js 0x6031
movq (%r13), %r15
movq %r15, %rdi
callq 0x2370
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 0x6051
xorl %edi, %edi
callq 0x5714
leaq 0x3202(%rip), %rdi      # 0x91ca
movq %rax, %rsi
callq 0x5443
xorl %edi, %edi
callq 0x5714
leaq 0x31fd(%rip), %rdi      # 0x91db
movq %rax, %rsi
callq 0x5443
leaq 0x85b3(%rip), %rdi      # 0xe5a0
movq %r14, %rsi
callq 0x3523
movl %eax, %ebx
movq %r14, %rdi
callq 0x2040
testl %ebx, %ebx
js 0x606f
movl $0x1, %edi
callq 0x5714
leaq 0x31b6(%rip), %rdi      # 0x91ca
movq %rax, %rsi
callq 0x5443
jmp 0x606f
leaq 0x46c0(%rip), %rdi      # 0xa6e5
movq %r15, %rsi
xorl %eax, %eax
callq 0x3270
jmp 0x606f
leaq 0x46c1(%rip), %rdi      # 0xa6f9
movq %rsp, %rcx
movl %r14d, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x3270
movl %ebp, %edi
callq 0x2280
jmp 0x606f
movq %r14, %rdi
callq 0x2040
leaq 0x46cd(%rip), %rdi      # 0xa72d
movq %rsp, %rcx
movl %ebx, %esi
movq %r15, %rdx
xorl %eax, %eax
callq 0x3270
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq