// File: /workspace/github_c_makefile_star2_O0/nerves-project[P]nerves_initramfs/src/script.c
// Function: function_saveenv
static const struct term *function_saveenv(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_WRONLY, 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);
    if (uboot_env_write(&working_uboot_env, buffer) < 0) {
        free(buffer);
        return NULL;
    }

    ssize_t amount_written = write(fd, buffer, working_uboot_env.env_size);
    close(fd);
    free(buffer);

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

    set_boolean_variable("uboot_env.modified", false);
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
leaq 0x56af(%rip), %rdi      # 0xd702
callq 0x74e0
movq %rax, -0x18(%rbp)
leaq 0x415f(%rip), %rdi      # 0xc1c2
callq 0x7580
movl %eax, -0x44(%rbp)
leaq 0x4160(%rip), %rdi      # 0xc1d2
callq 0x7580
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
shll $0x9, %eax
movslq %eax, %rcx
leaq 0x9526(%rip), %rax      # 0x115b0
movq %rcx, (%rax)
movq -0x18(%rbp), %rdi
leaq -0x40(%rbp), %rdx
movl $0x1, %esi
callq 0xa900
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jge 0x80c7
movq -0x18(%rbp), %rsi
leaq 0x56c4(%rip), %rdi      # 0xd777
movb $0x0, %al
callq 0x32a0
movq $0x0, -0x8(%rbp)
jmp 0x81c5
movl -0x4c(%rbp), %edi
movl -0x44(%rbp), %eax
shll $0x9, %eax
movslq %eax, %rsi
xorl %edx, %edx
callq 0x2200
cmpq $0x0, %rax
jge 0x8110
movl -0x44(%rbp), %esi
movl -0x44(%rbp), %edx
shll $0x9, %edx
leaq -0x40(%rbp), %rcx
leaq 0x5697(%rip), %rdi      # 0xd78b
movb $0x0, %al
callq 0x32a0
movl -0x4c(%rbp), %edi
callq 0x2250
movq $0x0, -0x8(%rbp)
jmp 0x81c5
leaq 0x9499(%rip), %rax      # 0x115b0
movq (%rax), %rdi
callq 0x2330
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rsi
leaq 0x9482(%rip), %rdi      # 0x115b0
callq 0x3b90
cmpl $0x0, %eax
jge 0x814b
movq -0x58(%rbp), %rdi
callq 0x2040
movq $0x0, -0x8(%rbp)
jmp 0x81c5
movl -0x4c(%rbp), %edi
movq -0x58(%rbp), %rsi
leaq 0x9457(%rip), %rax      # 0x115b0
movq (%rax), %rdx
callq 0x2120
movq %rax, -0x60(%rbp)
movl -0x4c(%rbp), %edi
callq 0x2250
movq -0x58(%rbp), %rdi
callq 0x2040
movq -0x60(%rbp), %rax
leaq 0x942f(%rip), %rcx      # 0x115b0
cmpq (%rcx), %rax
je 0x81af
movl -0x48(%rbp), %esi
leaq 0x9420(%rip), %rax      # 0x115b0
movq (%rax), %rdx
leaq -0x40(%rbp), %rcx
leaq 0x5672(%rip), %rdi      # 0xd810
movb $0x0, %al
callq 0x32a0
movq $0x0, -0x8(%rbp)
jmp 0x81c5
leaq 0x3ff9(%rip), %rdi      # 0xc1af
xorl %esi, %esi
callq 0x7610
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nop