// File: /workspace/github_c_makefile_star2_O1/nerves-project[P]nerves_initramfs/src/rootdisk.c
// Function: create_rootdisk_symlinks
void create_rootdisk_symlinks(const char *rootfs_devname)
{
    struct block_device_info *infos = scan_for_block_devices();

    dev_t rootfs_dev = rootfs_device(rootfs_devname);
    if (rootfs_dev == 0)
        return;

    struct block_device_info *rootfs_info = NULL;
    for (struct block_device_info *i = infos; i != NULL; i = i->next) {
        if (i->dev == rootfs_dev) {
            rootfs_info = i;
            break;
        }
    }

    if (!rootfs_info || !rootfs_info->parent) {
        info("Root disk is supposed to be %s, but it wasn't found or wasn't a partition.", rootfs_devname);
        return;
    }

    struct block_device_info *rootdisk_info = rootfs_info->parent;

    // Create the main disk's symlink.
    create_dev_symlink("0", rootdisk_info->name);

    // Create all of the partition symlinks (of which one will be the rootfs).
    for (struct block_device_info *i = infos; i != NULL; i = i->next) {
        if (i->parent == rootdisk_info) {
            char partition_suffix[8];
            snprintf(partition_suffix, sizeof(partition_suffix), "0p%d", i->partition_number);
            create_dev_symlink(partition_suffix, i->name);
        }
    }

    free_block_device_info(infos);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rdi, 0x28(%rsp)
leaq 0x2274(%rip), %rdi      # 0xa979
leaq 0x416(%rip), %rdx       # 0x8b22
movq 0x58bd(%rip), %rcx      # 0xdfd0
leaq 0x20(%rsp), %rsi
callq 0x2260
movl %eax, %ebp
movl %eax, %r14d
testl %eax, %eax
jle 0x893e
xorl %r15d, %r15d
xorl %r13d, %r13d
movq %r14, 0x38(%rsp)
movl %ebp, 0x30(%rsp)
movq 0x20(%rsp), %rax
movq (%rax,%r15,8), %rsi
addq $0x13, %rsi
leaq 0x222c(%rip), %rdi      # 0xa979
callq 0x8b2c
testq %rax, %rax
je 0x8930
movq %rax, %rbx
movl $0x28, %edi
callq 0x2370
movq %rax, %r14
movq %r13, (%rax)
movq 0x20(%rsp), %rax
movq %r15, 0x40(%rsp)
movq (%rax,%r15,8), %rdi
addq $0x13, %rdi
callq 0x24c0
movq %rax, 0x8(%r14)
movq %rbx, 0x10(%r14)
movl $0x0, 0x18(%r14)
movq $0x0, 0x20(%r14)
movl $0x100, %esi            # imm = 0x100
leaq 0x150(%rsp), %rbx
movq %rbx, %rdi
leaq 0x2339(%rip), %rdx      # 0xaaed
movq %rax, %rcx
xorl %eax, %eax
callq 0x2210
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x3eb(%rip), %rdx       # 0x8bb8
movq 0x57fc(%rip), %rcx      # 0xdfd0
callq 0x2260
movl %eax, %r15d
movl %eax, 0x34(%rsp)
testl %eax, %eax
jle 0x88ed
movq %r14, 0x48(%rsp)
movq %r14, 0x18(%rsp)
xorl %ebp, %ebp
movq 0x8(%rsp), %rax
movq (%rax,%rbp,8), %rsi
addq $0x13, %rsi
leaq 0x150(%rsp), %r12
movq %r12, %rdi
callq 0x8b2c
movq %rax, %rbx
movq 0x8(%rsp), %rax
movq (%rax,%rbp,8), %r8
addq $0x13, %r8
xorl %r13d, %r13d
movl $0x100, %esi            # imm = 0x100
leaq 0x50(%rsp), %r14
movq %r14, %rdi
leaq 0x22c3(%rip), %rdx      # 0xaafb
movq %r12, %rcx
xorl %eax, %eax
callq 0x2210
movq %r14, %rdi
leaq 0x8c6(%rip), %rsi       # 0x9112
callq 0x2420
testq %rax, %rax
je 0x8889
movq %rax, %r12
movq %rax, %rdi
leaq 0x2287(%rip), %rsi      # 0xaaea
leaq 0x14(%rsp), %rdx
xorl %eax, %eax
callq 0x20c0
cmpl $0x1, %eax
je 0x887c
movl $0x0, 0x14(%rsp)
movq %r12, %rdi
callq 0x2170
movl 0x14(%rsp), %r13d
testq %rbx, %rbx
sete %al
testl %r13d, %r13d
sete %cl
orb %al, %cl
jne 0x88df
movl $0x28, %edi
callq 0x2370
movq %rax, %r12
movq 0x18(%rsp), %rax
movq %rax, (%r12)
movq 0x8(%rsp), %rax
movq (%rax,%rbp,8), %rdi
addq $0x13, %rdi
callq 0x24c0
movq %rax, 0x8(%r12)
movq %rbx, 0x10(%r12)
movl %r13d, 0x18(%r12)
movq 0x48(%rsp), %rax
movq %rax, 0x20(%r12)
movq %r12, 0x18(%rsp)
incq %rbp
cmpq %rbp, %r15
jne 0x87f4
jmp 0x88f2
movq %r14, 0x18(%rsp)
cmpl $0x0, 0x34(%rsp)
movq 0x18(%rsp), %r13
movq 0x38(%rsp), %r14
movl 0x30(%rsp), %ebp
js 0x892b
je 0x8921
xorl %ebx, %ebx
movq 0x8(%rsp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x2040
incq %rbx
cmpq %rbx, %r15
jne 0x890b
movq 0x8(%rsp), %rdi
callq 0x2040
movq 0x40(%rsp), %r15
incq %r15
cmpq %r14, %r15
jne 0x8739
jmp 0x8941
xorl %r13d, %r13d
testl %ebp, %ebp
jg 0x8953
leaq 0x2149(%rip), %rdi      # 0xaa95
xorl %eax, %eax
callq 0x3270
testl %ebp, %ebp
js 0x897b
je 0x8971
xorl %ebx, %ebx
movq 0x20(%rsp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x2040
incq %rbx
cmpq %rbx, %r14
jne 0x895b
movq 0x20(%rsp), %rdi
callq 0x2040
leaq 0x50(%rsp), %rsi
movq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x2330
testl %eax, %eax
js 0x8998
movq 0x78(%rsp), %rbx
jmp 0x89ba
callq 0x2070
movl (%rax), %edi
callq 0x24d0
leaq 0x2166(%rip), %rdi      # 0xab11
xorl %ebx, %ebx
movq %r14, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3270
testq %rbx, %rbx
je 0x8a80
testq %r13, %r13
je 0x89e2
movq %r13, %rax
movq 0x28(%rsp), %rsi
cmpq %rbx, 0x10(%rax)
je 0x89e9
movq (%rax), %rax
testq %rax, %rax
jne 0x89d0
xorl %eax, %eax
jmp 0x89e9
xorl %eax, %eax
movq 0x28(%rsp), %rsi
testq %rax, %rax
je 0x8a72
movq 0x20(%rax), %r15
testq %r15, %r15
je 0x8a72
movq 0x8(%r15), %rsi
leaq 0x927(%rip), %rdi       # 0x932d
callq 0x8a92
testq %r13, %r13
je 0x8a80
leaq 0x2079(%rip), %rbx      # 0xaa90
leaq 0x50(%rsp), %r14
movq %r13, %r12
cmpq %r15, 0x20(%r12)
jne 0x8a4a
movl 0x18(%r12), %ecx
movl $0x8, %esi
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2210
movq 0x8(%r12), %rsi
movq %r14, %rdi
callq 0x8a92
movq (%r12), %r12
testq %r12, %r12
jne 0x8a1f
movq (%r13), %rbx
movq 0x8(%r13), %rdi
callq 0x2040
movq %r13, %rdi
callq 0x2040
movq %rbx, %r13
testq %rbx, %rbx
jne 0x8a53
jmp 0x8a80
leaq 0x1fcc(%rip), %rdi      # 0xaa45
xorl %eax, %eax
callq 0x3270
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq