// File: /workspace/github_c_makefile_star2_O2/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 $0x248, %rsp            # imm = 0x248
movq %rdi, 0x28(%rsp)
leaq 0x209c(%rip), %rdi      # 0x99a9
leaq 0x3d4(%rip), %rdx       # 0x7ce8
movq 0x56b5(%rip), %rcx      # 0xcfd0
leaq 0x18(%rsp), %rsi
callq 0x2260
movl %eax, %ebx
testl %eax, %eax
movl $0x0, %eax
cmovgl %ebx, %eax
movq %rax, 0x30(%rsp)
xorl %r14d, %r14d
xorl %ebp, %ebp
movl %ebx, 0x20(%rsp)
cmpq 0x30(%rsp), %r14
je 0x7b1e
movq 0x18(%rsp), %rax
movq (%rax,%r14,8), %rsi
addq $0x13, %rsi
leaq 0x204b(%rip), %rdi      # 0x99a9
callq 0x7cf2
testq %rax, %rax
je 0x7b16
movq %rax, %r12
pushq $0x28
popq %rdi
callq 0x2380
movq %rax, %r15
movq %rbp, (%rax)
movq 0x18(%rsp), %rax
movq %r14, 0x38(%rsp)
movq (%rax,%r14,8), %rdi
addq $0x13, %rdi
callq 0x24d0
movq %rax, 0x8(%r15)
movq %r12, 0x10(%r15)
andl $0x0, 0x18(%r15)
andq $0x0, 0x20(%r15)
movl $0x100, %esi            # imm = 0x100
leaq 0x140(%rsp), %rbx
movq %rbx, %rdi
leaq 0x2160(%rip), %rdx      # 0x9b1d
movq %rax, %rcx
xorl %eax, %eax
callq 0x2210
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x3a8(%rip), %rdx       # 0x7d7e
movq 0x55f3(%rip), %rcx      # 0xcfd0
callq 0x2260
testl %eax, %eax
movl $0x0, %r13d
movl %eax, 0x24(%rsp)
cmovgl %eax, %r13d
movq %r15, 0x10(%rsp)
movq %r15, %rbp
xorl %r14d, %r14d
cmpq %r14, %r13
je 0x7ae3
movq 0x8(%rsp), %rax
movq (%rax,%r14,8), %rsi
addq $0x13, %rsi
leaq 0x140(%rsp), %rbx
movq %rbx, %rdi
callq 0x7cf2
movq %rax, %r12
movq 0x8(%rsp), %rax
movq (%rax,%r14,8), %r8
addq $0x13, %r8
movl $0x100, %esi            # imm = 0x100
leaq 0x40(%rsp), %r15
movq %r15, %rdi
leaq 0x20e4(%rip), %rdx      # 0x9b2b
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2210
movq %r15, %rdi
leaq 0x6b7(%rip), %rsi       # 0x8112
callq 0x2430
testq %rax, %rax
je 0x7adb
movq %rax, %r15
movq %rax, %rdi
leaq 0x20a8(%rip), %rsi      # 0x9b1a
leaq 0x4(%rsp), %rdx
xorl %eax, %eax
callq 0x20c0
cmpl $0x1, %eax
je 0x7a88
andl $0x0, 0x4(%rsp)
movq %r15, %rdi
callq 0x2170
movl 0x4(%rsp), %ebx
testq %r12, %r12
sete %al
testl %ebx, %ebx
sete %cl
orb %al, %cl
jne 0x7adb
pushq $0x28
popq %rdi
callq 0x2380
movq %rax, %r15
movq %rbp, (%rax)
movq 0x8(%rsp), %rax
movq (%rax,%r14,8), %rdi
addq $0x13, %rdi
callq 0x24d0
movq %rax, 0x8(%r15)
movq %r12, 0x10(%r15)
movl %ebx, 0x18(%r15)
movq 0x10(%rsp), %rax
movq %rax, 0x20(%r15)
movq %r15, %rbp
incq %r14
jmp 0x79fd
movl 0x24(%rsp), %eax
testl %eax, %eax
js 0x7b0d
movl %eax, %ebx
xorl %r14d, %r14d
movq 0x8(%rsp), %rdi
cmpq %r14, %rbx
je 0x7b08
movq (%rdi,%r14,8), %rdi
callq 0x2040
incq %r14
jmp 0x7af0
callq 0x2040
movl 0x20(%rsp), %ebx
movq 0x38(%rsp), %r14
incq %r14
jmp 0x793f
testl %ebx, %ebx
movq 0x28(%rsp), %r15
jg 0x7b39
leaq 0x1f97(%rip), %rdi      # 0x9ac5
xorl %eax, %eax
callq 0x2ee4
testl %ebx, %ebx
js 0x7b5b
movl %ebx, %ebx
xorl %r14d, %r14d
movq 0x18(%rsp), %rdi
cmpq %r14, %rbx
je 0x7b56
movq (%rdi,%r14,8), %rdi
callq 0x2040
incq %r14
jmp 0x7b3e
callq 0x2040
leaq 0x40(%rsp), %rsi
movq %r15, %rdi
callq 0x2340
testl %eax, %eax
js 0x7b91
movq 0x68(%rsp), %rax
testq %rax, %rax
je 0x7c23
movq %rbp, %rcx
testq %rcx, %rcx
je 0x7c12
cmpq %rax, 0x10(%rcx)
je 0x7bb3
movq (%rcx), %rcx
jmp 0x7b7d
callq 0x2070
movl (%rax), %edi
callq 0x24e0
leaq 0x1f9d(%rip), %rdi      # 0x9b41
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2ee4
jmp 0x7c23
movq 0x20(%rcx), %r12
testq %r12, %r12
je 0x7c12
movq 0x8(%r12), %rsi
leaq 0x765(%rip), %rdi       # 0x832d
callq 0x7c58
leaq 0x1eec(%rip), %rbx      # 0x9ac0
leaq 0x40(%rsp), %r14
pushq $0x8
popq %r15
movq %rbp, 0x10(%rsp)
testq %rbp, %rbp
je 0x7c35
cmpq %r12, 0x20(%rbp)
jne 0x7c0c
movl 0x18(%rbp), %ecx
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2210
movq 0x8(%rbp), %rsi
movq %r14, %rdi
callq 0x7c58
movq (%rbp), %rbp
jmp 0x7be2
leaq 0x1e5c(%rip), %rdi      # 0x9a75
movq %r15, %rsi
xorl %eax, %eax
callq 0x2ee4
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %r14
testq %r14, %r14
je 0x7c23
movq (%r14), %rbx
movq 0x8(%r14), %rdi
callq 0x2040
movq %r14, %rdi
callq 0x2040
movq %rbx, %r14
jmp 0x7c3a