// File: /workspace/github_c_makefile_star2_O3/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 0x49b1(%rip), %rdi      # 0xa670
callq 0x5908
movq %rax, %r15
leaq 0x3520(%rip), %rdi      # 0x91ee
callq 0x5944
movl %eax, %r14d
leaq 0x3521(%rip), %rdi      # 0x91fe
callq 0x5944
movl %eax, %ebx
shll $0x9, %eax
cltq
leaq 0x88b0(%rip), %r13      # 0xe5a0
movq %rax, (%r13)
movq %rsp, %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x7fa6
testl %eax, %eax
js 0x5dbe
movl %eax, %ebp
movl %r14d, %r15d
shll $0x9, %r15d
movslq %r15d, %rsi
movl %eax, %edi
xorl %edx, %edx
callq 0x2220
testq %rax, %rax
js 0x5dd1
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 0x5df1
xorl %edi, %edi
callq 0x5450
leaq 0x3462(%rip), %rdi      # 0x91ca
movq %rax, %rsi
callq 0x5165
xorl %edi, %edi
callq 0x5450
leaq 0x345d(%rip), %rdi      # 0x91db
movq %rax, %rsi
callq 0x5165
leaq 0x8813(%rip), %rdi      # 0xe5a0
movq %r14, %rsi
callq 0x34af
movl %eax, %ebx
movq %r14, %rdi
callq 0x2040
testl %ebx, %ebx
js 0x5e0f
movl $0x1, %edi
callq 0x5450
leaq 0x3416(%rip), %rdi      # 0x91ca
movq %rax, %rsi
callq 0x5165
jmp 0x5e0f
leaq 0x4920(%rip), %rdi      # 0xa6e5
movq %r15, %rsi
xorl %eax, %eax
callq 0x3204
jmp 0x5e0f
leaq 0x4921(%rip), %rdi      # 0xa6f9
movq %rsp, %rcx
movl %r14d, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x3204
movl %ebp, %edi
callq 0x2280
jmp 0x5e0f
movq %r14, %rdi
callq 0x2040
leaq 0x492d(%rip), %rdi      # 0xa72d
movq %rsp, %rcx
movl %ebx, %esi
movq %r15, %rdx
xorl %eax, %eax
callq 0x3204
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq