// File: /workspace/github_c_makefile_star2_O0/nerves-project[P]nerves_initramfs/src/nerves_initramfs.c
// Function: dm_create
static int dm_create(off_t rootfs_blocks, const char *cipher, const char *secret)
{
    int dm_control = open("/dev/mapper/control", O_RDWR);
    if (dm_control < 0)
        fatal("Can't continue since '/dev/mapper/control' does not exist.");

    uint8_t request_buffer[16384];
    struct dm_ioctl *dm = (struct dm_ioctl *) request_buffer;

    memset(&request_buffer, 0, sizeof(request_buffer));
    dm->version[0] = DM_VERSION_MAJOR;
    dm->version[1] = DM_VERSION_MINOR;
    dm->version[2] = DM_VERSION_PATCHLEVEL;
    dm->data_size = sizeof(request_buffer);
    dm->data_start = sizeof(struct dm_ioctl);
    dm->target_count = 0;
    dm->open_count = 0;
    dm->flags = 0;
    dm->event_nr = 0;
    dm->dev = 0;
    strcpy(dm->name, "rootfs");
    strcpy(dm->uuid, "CRYPT-PLAIN-rootfs");

    OK_OR_FATAL(ioctl(dm_control, DM_DEV_CREATE, request_buffer), "Enable CONFIG_DM_CRYPT in kernel");

    memset(&request_buffer, 0, sizeof(request_buffer));
    dm->version[0] = DM_VERSION_MAJOR;
    dm->version[1] = DM_VERSION_MINOR;
    dm->version[2] = DM_VERSION_PATCHLEVEL;
    dm->data_size = sizeof(request_buffer);
    dm->data_start = sizeof(struct dm_ioctl);
    dm->target_count = 1;
    dm->open_count = 0;
    dm->flags = DM_SECURE_DATA_FLAG;
    dm->dev = 0;
    strcpy(dm->name, "rootfs");
    struct dm_target_spec *target = (struct dm_target_spec *) &request_buffer[dm->data_start];
    memset(target, 0, sizeof(struct dm_target_spec));
    target->sector_start = 0;
    target->length = rootfs_blocks;
    strcpy(target->target_type, "crypt");
    sprintf((char *) &request_buffer[dm->data_start + sizeof(struct dm_target_spec)], "%s %s 0 /dev/loop0 0", cipher, secret);
    OK_OR_FATAL(ioctl(dm_control, DM_TABLE_LOAD, request_buffer), "Check CONFIG_DM_CRYPT and crypto algs enabled");

    memset(&request_buffer, 0, sizeof(request_buffer));
    dm->version[0] = DM_VERSION_MAJOR;
    dm->version[1] = DM_VERSION_MINOR;
    dm->version[2] = DM_VERSION_PATCHLEVEL;
    dm->data_size = sizeof(request_buffer);
    dm->data_start = sizeof(struct dm_ioctl);
    dm->target_count = 0;
    dm->flags = DM_SECURE_DATA_FLAG;
    strcpy(dm->name, "rootfs");
    OK_OR_FATAL(ioctl(dm_control, DM_DEV_SUSPEND, request_buffer), "DM_DEV_SUSPEND failed");

    close(dm_control);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4030, %rsp           # imm = 0x4030
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq 0x9467(%rip), %rdi      # 0xc265
movl $0x2, %esi
movb $0x0, %al
callq 0x23d0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x2e21
leaq 0x945f(%rip), %rdi      # 0xc279
movb $0x0, %al
callq 0x3390
leaq -0x4020(%rbp), %rax
movq %rax, -0x4028(%rbp)
leaq -0x4020(%rbp), %rdi
xorl %esi, %esi
movl $0x4000, %edx           # imm = 0x4000
callq 0x2210
movq -0x4028(%rbp), %rax
movl $0x4, (%rax)
movq -0x4028(%rbp), %rax
movl $0x2d, 0x4(%rax)
movq -0x4028(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x4028(%rbp), %rax
movl $0x4000, 0xc(%rax)      # imm = 0x4000
movq -0x4028(%rbp), %rax
movl $0x138, 0x10(%rax)      # imm = 0x138
movq -0x4028(%rbp), %rax
movl $0x0, 0x14(%rax)
movq -0x4028(%rbp), %rax
movl $0x0, 0x18(%rax)
movq -0x4028(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq -0x4028(%rbp), %rax
movl $0x0, 0x20(%rax)
movq -0x4028(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x4028(%rbp), %rdi
addq $0x30, %rdi
leaq 0x93e0(%rip), %rsi      # 0xc2c0
callq 0x2090
movq -0x4028(%rbp), %rdi
addq $0xb0, %rdi
leaq 0x93ba(%rip), %rsi      # 0xc2b4
callq 0x2090
movl -0x1c(%rbp), %edi
leaq -0x4020(%rbp), %rdx
movl $0xc138fd03, %esi       # imm = 0xC138FD03
movb $0x0, %al
callq 0x2220
cmpl $0x0, %eax
jge 0x2f28
leaq 0x93a6(%rip), %rdi      # 0xc2c7
movb $0x0, %al
callq 0x3390
jmp 0x2f2a
leaq -0x4020(%rbp), %rdi
xorl %esi, %esi
movl $0x4000, %edx           # imm = 0x4000
callq 0x2210
movq -0x4028(%rbp), %rax
movl $0x4, (%rax)
movq -0x4028(%rbp), %rax
movl $0x2d, 0x4(%rax)
movq -0x4028(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x4028(%rbp), %rax
movl $0x4000, 0xc(%rax)      # imm = 0x4000
movq -0x4028(%rbp), %rax
movl $0x138, 0x10(%rax)      # imm = 0x138
movq -0x4028(%rbp), %rax
movl $0x1, 0x14(%rax)
movq -0x4028(%rbp), %rax
movl $0x0, 0x18(%rax)
movq -0x4028(%rbp), %rax
movl $0x8000, 0x1c(%rax)     # imm = 0x8000
movq -0x4028(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x4028(%rbp), %rdi
addq $0x30, %rdi
leaq 0x92f3(%rip), %rsi      # 0xc2c0
callq 0x2090
movq -0x4028(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %ecx
leaq -0x4020(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x4030(%rbp)
movq -0x4030(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x2210
movq -0x4030(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rcx
movq -0x4030(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x4030(%rbp), %rdi
addq $0x18, %rdi
leaq 0x92b7(%rip), %rsi      # 0xc2e8
callq 0x2090
movq -0x4028(%rbp), %rax
movl 0x10(%rax), %eax
addq $0x28, %rax
leaq -0x4020(%rbp), %rdi
addq %rax, %rdi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq 0x9291(%rip), %rsi      # 0xc2ee
movb $0x0, %al
callq 0x2440
movl -0x1c(%rbp), %edi
leaq -0x4020(%rbp), %rdx
movl $0xc138fd09, %esi       # imm = 0xC138FD09
movb $0x0, %al
callq 0x2220
cmpl $0x0, %eax
jge 0x308d
leaq 0x927d(%rip), %rdi      # 0xc303
movb $0x0, %al
callq 0x3390
jmp 0x308f
leaq -0x4020(%rbp), %rdi
xorl %esi, %esi
movl $0x4000, %edx           # imm = 0x4000
callq 0x2210
movq -0x4028(%rbp), %rax
movl $0x4, (%rax)
movq -0x4028(%rbp), %rax
movl $0x2d, 0x4(%rax)
movq -0x4028(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x4028(%rbp), %rax
movl $0x4000, 0xc(%rax)      # imm = 0x4000
movq -0x4028(%rbp), %rax
movl $0x138, 0x10(%rax)      # imm = 0x138
movq -0x4028(%rbp), %rax
movl $0x0, 0x14(%rax)
movq -0x4028(%rbp), %rax
movl $0x8000, 0x1c(%rax)     # imm = 0x8000
movq -0x4028(%rbp), %rdi
addq $0x30, %rdi
leaq 0x91ab(%rip), %rsi      # 0xc2c0
callq 0x2090
movl -0x1c(%rbp), %edi
leaq -0x4020(%rbp), %rdx
movl $0xc138fd06, %esi       # imm = 0xC138FD06
movb $0x0, %al
callq 0x2220
cmpl $0x0, %eax
jge 0x3143
leaq 0x91f5(%rip), %rdi      # 0xc331
movb $0x0, %al
callq 0x3390
jmp 0x3145
movl -0x1c(%rbp), %edi
callq 0x2250
xorl %eax, %eax
addq $0x4030, %rsp           # imm = 0x4030
popq %rbp
retq
nopl (%rax,%rax)