decompiled_code:
__int64 do_init()
{
int v0; // ebp
int v1; // ebx
int *v3; // rbx
char *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax
char v8[4120]; // [rsp+0h] [rbp-1018h] BYREF

v0 = 0;
atexit(do_cleanup);
putenv("PATH=/bin");
init_log();
logprintf("0welcome to nsboot");
logprintf("0rebuilding root filesystem");
rebuild_fs();
logprintf("0mounting /dev (devtmpfs)");
if ( mount("devtmpfs", "/dev", "devtmpfs", 0x8000uLL, 0LL) == -1 )
{
v0 = 1;
v3 = _errno_location();
v4 = strerror(*v3);
logprintf("2%s: %s", "error mounting /dev as devtmpfs", v4);
logprintf("0retrying /dev mount with plain tmpfs");
if ( mount("tmpfs", "/dev", "tmpfs", 0x8000uLL, 0LL) == -1 )
{
v5 = strerror(*v3);
logprintf("2%s: %s", "error mounting /dev/ as tmpfs", v5);
}
}
logprintf("0mounting /proc");
mount("none", "/proc", "proc", 0x8000uLL, 0LL);
logprintf("0enabling core dumps");
enable_coredumps();
logprintf("0quieting kernel messages");
qfprintf("/proc/sys/kernel/printk", "2");
logprintf("0parsing kernel cmdline");
parse_proc_cmdline();
logprintf("0installing busybox");
system_logged("busybox --install -s");
logprintf("0symlinking binaries");
symlink_binaries();
logprintf("0mounting /sys");
mount("none", "/sys", "sysfs", 0x8000uLL, 0LL);
logprintf("0mounting /dev/pts");
mkdir("/dev/pts", 0x1EDu);
mount("none", "/dev/pts", "devpts", 0x8000uLL, 0LL);
if ( v0 )
{
logprintf("0starting legacy hotplug (mdev)");
system_logged("touch /etc/mdev.conf");
qfprintf("/proc/sys/kernel/hotplug", "/bin/mdev");
system_logged("mdev -s");
}
logprintf("0initializing vibrator");
vibrator_open("/sys/devices/virtual/timed_output/vibrator/enable");
logprintf("0loading font file");
v1 = load_font("/t.fnt");
if ( v1 )
{
logprintf("3failed to load font");
exit(1);
}
while ( 1 )
{
logprintf("0initializing graphics (attempt %d)", (unsigned int)++v1);
if ( !(unsigned int)fb_init() )
break;
usleep(0x493E0u);
if ( v1 == 5 )
{
logprintf("3failed to init graphics!");
exit(1);
}
}
atexit((void (*)(void))&fb_close);
logprintf("0reducing display brightness");
set_brightness(48LL);
start_adbd();
logprintf("0starting touchscreen service");
system_logged("tssrv >/var/tssrv.out 2>/var/tssrv.err &");
if ( v0 )
strcpy(v8, "/dev");
else
strcpy(v8, "/dev/input");
if ( (unsigned int)input_open(v8) )
{
logprintf("3failed to set up input!");
exit(1);
}
atexit((void (*)(void))&input_close);
logprintf("0mounting base partitions");
logprintf("0 - /mnt/firmware (/dev/mmcblk0p1)");
mount("/dev/mmcblk0p1", "/mnt/firmware", "vfat", 0x8001uLL, 0LL);
logprintf("0 - /mnt/boot (/dev/mmcblk0p13)");
mount("/dev/mmcblk0p13", "/mnt/boot", "ext4", 0x8000uLL, 0LL);
logprintf("0starting lvm");
system_logged("rm -rf /etc/lvm/cache");
system_logged("lvm vgchange -a y");
system_logged("lvm vgmknodes");
logprintf("0mounting base volumes");
mount_lv("media");
mkdir("/mnt/media/nsboot", 0x1EDu);
if ( chdir("/mnt/media") == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
logprintf("2%s: %s", "can't chdir into /mnt/media", v7);
}
logprintf("0mounting /tmp");
mount("tmpfs", "/tmp", "tmpfs", 0x8000uLL, 0LL);
return mount_lv("root");
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // ebp
int v1; // ebx
int *v3; // rbx
char *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax
char v8[4120]; // [rsp+0h] [rbp-1018h] BYREF

v0 = 0;
atexit(do_cleanup);
putenv("PATH=/bin");
init_log();
logprintf("0welcome to nsboot");
logprintf("0rebuilding root filesystem");
func3();
logprintf("0mounting /dev (devtmpfs)");
if ( mount("devtmpfs", "/dev", "devtmpfs", 0x8000uLL, 0LL) == -1 )
{
v0 = 1;
v3 = _errno_location();
v4 = strerror(*v3);
logprintf("2%s: %s", "error mounting /dev as devtmpfs", v4);
logprintf("0retrying /dev mount with plain tmpfs");
if ( mount("tmpfs", "/dev", "tmpfs", 0x8000uLL, 0LL) == -1 )
{
v5 = strerror(*v3);
logprintf("2%s: %s", "error mounting /dev/ as tmpfs", v5);
}
}
logprintf("0mounting /proc");
mount("none", "/proc", "proc", 0x8000uLL, 0LL);
logprintf("0enabling core dumps");
func4();
logprintf("0quieting kernel messages");
qfprintf("/proc/sys/kernel/printk", "2");
logprintf("0parsing kernel cmdline");
parse_proc_cmdline();
logprintf("0installing busybox");
system_logged("busybox --install -s");
logprintf("0symlinking binaries");
func2();
logprintf("0mounting /sys");
mount("none", "/sys", "sysfs", 0x8000uLL, 0LL);
logprintf("0mounting /dev/pts");
mkdir("/dev/pts", 0x1EDu);
mount("none", "/dev/pts", "devpts", 0x8000uLL, 0LL);
if ( v0 )
{
logprintf("0starting legacy hotplug (mdev)");
system_logged("touch /etc/mdev.conf");
qfprintf("/proc/sys/kernel/hotplug", "/bin/mdev");
system_logged("mdev -s");
}
logprintf("0initializing vibrator");
vibrator_open("/sys/devices/virtual/timed_output/vibrator/enable");
logprintf("0loading font file");
v1 = load_font("/t.fnt");
if ( v1 )
{
logprintf("3failed to load font");
exit(1);
}
while ( 1 )
{
logprintf("0initializing graphics (attempt %d)", (unsigned int)++v1);
if ( !(unsigned int)fb_init() )
break;
usleep(0x493E0u);
if ( v1 == 5 )
{
logprintf("3failed to init graphics!");
exit(1);
}
}
atexit((void (*)(void))&fb_close);
logprintf("0reducing display brightness");
set_brightness(48LL);
func6();
logprintf("0starting touchscreen service");
system_logged("tssrv >/var/tssrv.out 2>/var/tssrv.err &");
if ( v0 )
strcpy(v8, "/dev");
else
strcpy(v8, "/dev/input");
if ( (unsigned int)input_open(v8) )
{
logprintf("3failed to set up input!");
exit(1);
}
atexit((void (*)(void))&input_close);
logprintf("0mounting base partitions");
logprintf("0 - /mnt/firmware (/dev/mmcblk0p1)");
mount("/dev/mmcblk0p1", "/mnt/firmware", "vfat", 0x8001uLL, 0LL);
logprintf("0 - /mnt/boot (/dev/mmcblk0p13)");
mount("/dev/mmcblk0p13", "/mnt/boot", "ext4", 0x8000uLL, 0LL);
logprintf("0starting lvm");
system_logged("rm -rf /etc/lvm/cache");
system_logged("lvm vgchange -a y");
system_logged("lvm vgmknodes");
logprintf("0mounting base volumes");
mount_lv("media");
mkdir("/mnt/media/nsboot", 0x1EDu);
if ( chdir("/mnt/media") == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
logprintf("2%s: %s", "can't chdir into /mnt/media", v7);
}
logprintf("0mounting /tmp");
mount("tmpfs", "/tmp", "tmpfs", 0x8000uLL, 0LL);
return mount_lv("root");
}

original_code:
void do_init(void) {
 int i;
 int need_mdev = 0;
 char uinput_dir[4096];
 atexit(do_cleanup);
 putenv("PATH=/bin");
 init_log();
 logprintf("0welcome to nsboot");
 logprintf("0rebuilding root filesystem");
 rebuild_fs();
 logprintf("0mounting /dev (devtmpfs)");
 if (mount("devtmpfs", "/dev", "devtmpfs", MS_SILENT, ((void *)0)) == -1) {
  logprintf("2%s: %s", "error mounting /dev as devtmpfs", strerror((*__errno_location ())));
  logprintf("0retrying /dev mount with plain tmpfs");
  if (mount("tmpfs", "/dev", "tmpfs", MS_SILENT, ((void *)0)) == -1)
   logprintf("2%s: %s", "error mounting /dev/ as tmpfs", strerror((*__errno_location ())));
  need_mdev = 1;
 }
 logprintf("0mounting /proc");
 mount("none", "/proc", "proc", MS_SILENT, ((void *)0));
 logprintf("0enabling core dumps");
 enable_coredumps();
 logprintf("0quieting kernel messages");
 qfprintf("/proc/sys/kernel/printk", "2");
 logprintf("0parsing kernel cmdline");
 parse_proc_cmdline();
 logprintf("0installing busybox");
 system_logged("busybox --install -s");
 logprintf("0symlinking binaries");
 symlink_binaries();
 logprintf("0mounting /sys");
 mount("none", "/sys", "sysfs", MS_SILENT, ((void *)0));
 logprintf("0mounting /dev/pts");
 mkdir("/dev/pts", 0755);
 mount("none", "/dev/pts", "devpts", MS_SILENT, ((void *)0));
 if (need_mdev) {
  logprintf("0starting legacy hotplug (mdev)");
  system_logged("touch /etc/mdev.conf");
  qfprintf("/proc/sys/kernel/hotplug", "/bin/mdev");
  system_logged("mdev -s");
 }
 logprintf("0initializing vibrator");
 vibrator_open("/sys/devices/virtual/timed_output/vibrator/enable");
 logprintf("0loading font file");
 if (load_font("/t.fnt")) {
  logprintf("3failed to load font");
  exit(1);
 }
 for (i = 0; i < 5; ++i) {
  logprintf("0initializing graphics (attempt %d)", i + 1);
  if (!fb_init()) break;
  usleep(300000);
 }
 if (i == 5) {
  logprintf("3failed to init graphics!");
  exit(1);
 }
 atexit(fb_close);
 logprintf("0reducing display brightness");
 set_brightness(48);
 start_adbd();
 logprintf("0starting touchscreen service");
 system_logged("tssrv >/var/tssrv.out 2>/var/tssrv.err &");
 if (need_mdev)
  strcpy(uinput_dir, "/dev");
 else
  strcpy(uinput_dir, "/dev/input");
 if (input_open(uinput_dir)) {
  logprintf("3failed to set up input!");
  exit(1);
 }
 atexit(input_close);
 logprintf("0mounting base partitions");
 logprintf("0 - /mnt/firmware (/dev/mmcblk0p1)");
 mount("/dev/mmcblk0p1", "/mnt/firmware", "vfat",
  MS_RDONLY | MS_SILENT, ((void *)0));
 logprintf("0 - /mnt/boot (/dev/mmcblk0p13)");
 mount("/dev/mmcblk0p13", "/mnt/boot", "ext4", MS_SILENT, ((void *)0));
 logprintf("0starting lvm");
 system_logged("rm -rf /etc/lvm/cache");
 system_logged("lvm vgchange -a y");
 system_logged("lvm vgmknodes");
 logprintf("0mounting base volumes");
 mount_lv("media");
 mkdir("/mnt/media/nsboot", 0755);
 if (chdir("/mnt/media") == -1)
  logprintf("2%s: %s", "can't chdir into /mnt/media", strerror((*__errno_location ())));
 logprintf("0mounting /tmp");
 mount("tmpfs", "/tmp", "tmpfs", MS_SILENT, ((void *)0));
 mount_lv("root");
}

canonical_original_code:
void do_init() {
 int i;
 int need_mdev = 0;
 char uinput_dir[4096];
 atexit(do_cleanup);
 putenv("PATH=/bin");
 init_log();
 logprintf("0welcome to nsboot");
 logprintf("0rebuilding root filesystem");
 rebuild_fs();
 logprintf("0mounting /dev (devtmpfs)");
 if (mount("devtmpfs", "/dev", "devtmpfs", MS_SILENT, ((void *)0)) == -1) {
  logprintf("2%s: %s", "error mounting /dev as devtmpfs", strerror((*__errno_location ())));
  logprintf("0retrying /dev mount with plain tmpfs");
  if (mount("tmpfs", "/dev", "tmpfs", MS_SILENT, ((void *)0)) == -1)
   logprintf("2%s: %s", "error mounting /dev/ as tmpfs", strerror((*__errno_location ())));
  need_mdev = 1;
 }
 logprintf("0mounting /proc");
 mount("none", "/proc", "proc", MS_SILENT, ((void *)0));
 logprintf("0enabling core dumps");
 enable_coredumps();
 logprintf("0quieting kernel messages");
 qfprintf("/proc/sys/kernel/printk", "2");
 logprintf("0parsing kernel cmdline");
 parse_proc_cmdline();
 logprintf("0installing busybox");
 system_logged("busybox --install -s");
 logprintf("0symlinking binaries");
 symlink_binaries();
 logprintf("0mounting /sys");
 mount("none", "/sys", "sysfs", MS_SILENT, ((void *)0));
 logprintf("0mounting /dev/pts");
 mkdir("/dev/pts", 0755);
 mount("none", "/dev/pts", "devpts", MS_SILENT, ((void *)0));
 if (need_mdev) {
  logprintf("0starting legacy hotplug (mdev)");
  system_logged("touch /etc/mdev.conf");
  qfprintf("/proc/sys/kernel/hotplug", "/bin/mdev");
  system_logged("mdev -s");
 }
 logprintf("0initializing vibrator");
 vibrator_open("/sys/devices/virtual/timed_output/vibrator/enable");
 logprintf("0loading font file");
 if (load_font("/t.fnt")) {
  logprintf("3failed to load font");
  exit(1);
 }
 for (i = 0; i < 5; ++i) {
  logprintf("0initializing graphics (attempt %d)", i + 1);
  if (!fb_init()) break;
  usleep(300000);
 }
 if (i == 5) {
  logprintf("3failed to init graphics!");
  exit(1);
 }
 atexit(fb_close);
 logprintf("0reducing display brightness");
 set_brightness(48);
 start_adbd();
 logprintf("0starting touchscreen service");
 system_logged("tssrv >/var/tssrv.out 2>/var/tssrv.err &");
 if (need_mdev)
  strcpy(uinput_dir, "/dev");
 else
  strcpy(uinput_dir, "/dev/input");
 if (input_open(uinput_dir)) {
  logprintf("3failed to set up input!");
  exit(1);
 }
 atexit(input_close);
 logprintf("0mounting base partitions");
 logprintf("0 - /mnt/firmware (/dev/mmcblk0p1)");
 mount("/dev/mmcblk0p1", "/mnt/firmware", "vfat",
  MS_RDONLY | MS_SILENT, ((void *)0));
 logprintf("0 - /mnt/boot (/dev/mmcblk0p13)");
 mount("/dev/mmcblk0p13", "/mnt/boot", "ext4", MS_SILENT, ((void *)0));
 logprintf("0starting lvm");
 system_logged("rm -rf /etc/lvm/cache");
 system_logged("lvm vgchange -a y");
 system_logged("lvm vgmknodes");
 logprintf("0mounting base volumes");
 mount_lv("media");
 mkdir("/mnt/media/nsboot", 0755);
 if (chdir("/mnt/media") == -1)
  logprintf("2%s: %s", "can't chdir into /mnt/media", strerror((*__errno_location ())));
 logprintf("0mounting /tmp");
 mount("tmpfs", "/tmp", "tmpfs", MS_SILENT, ((void *)0));
 mount_lv("root");
}

variable_types: i int


repo: willcast/nsboot

decompiled_code:
__int64 restart_adbd()
{
stop_adbd();
return start_adbd();
}

canonical_decompiled_code:
__int64 func8()
{
func5();
return func6();
}

original_code:
void restart_adbd(void) {
 stop_adbd();
 start_adbd();
}

canonical_original_code:
void restart_adbd() {
 stop_adbd();
 start_adbd();
}

return_type: void


decompiled_code:
_BOOL8 __fastcall is_hidden(const struct dirent *a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( a1->d_name[0] == 46 )
result = *(_WORD *)&a1->d_name[1] == 46;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const struct dirent *a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( a1->d_name[0] == 46 )
result = *(_WORD *)&a1->d_name[1] == 46;
return result;
}

original_code:
int is_hidden(const struct dirent *dir) {
 if (dir->d_name[0] != '.') return 1;
 if ((dir->d_name[1] == '.') &&
  (dir->d_name[2] == '\0')) return 1;
 return 0;
}

canonical_original_code:
int is_hidden(struct dirent *dir) {
 if (dir->d_name[0] != '.') return 1;
 if ((dir->d_name[1] == '.') &&
  (dir->d_name[2] == '\0')) return 1;
 return 0;
}

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *

return_type: int


decompiled_code:
__int64 __fastcall is_lv(const struct dirent *a1)
{
return (*_ctype_b_loc())[a1->d_name[0]] & 0x400;
}

canonical_decompiled_code:
__int64 __fastcall func1(const struct dirent *a1)
{
return (*_ctype_b_loc())[a1->d_name[0]] & 0x400;
}

original_code:
int is_lv(const struct dirent *dir) {
  return ((*__ctype_b_loc ())[(int) ((dir->d_name[0]))] & (unsigned short int) _ISalpha);
}

canonical_original_code:
int is_lv(struct dirent *dir) {
  return ((*__ctype_b_loc ())[(int) ((dir->d_name[0]))] & (unsigned short) _ISalpha);
}

user_defined_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; }


decompiled_code:
void __fastcall free_dir_list(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi

if ( *((int *)ptr + 4) > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*(_QWORD *)ptr + 8 * v2);
if ( v3 )
free(v3);
v4 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2);
if ( v4 )
free(v4);
++v2;
}
while ( *((_DWORD *)ptr + 4) > (int)v2 );
}
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
v5 = (void *)*((_QWORD *)ptr + 1);
if ( v5 )
free(v5);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi

if ( *((int *)ptr + 4) > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*(_QWORD *)ptr + 8 * v2);
if ( v3 )
free(v3);
v4 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2);
if ( v4 )
free(v4);
++v2;
}
while ( *((_DWORD *)ptr + 4) > (int)v2 );
}
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
v5 = (void *)*((_QWORD *)ptr + 1);
if ( v5 )
free(v5);
free(ptr);
}

original_code:
void free_dir_list(struct dir_list *list) {
 for (int i = 0; i < list->n; ++i) {
  if (list->dents[i] != ((void *)0)) free(list->dents[i]);
  if (list->stats[i] != ((void *)0)) free(list->stats[i]);
 }
 if (list->dents != ((void *)0)) free(list->dents);
 if (list->stats != ((void *)0)) free(list->stats);
 if (list != ((void *)0)) free(list);
}

variable_types: struct dir_list { struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } **dents; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } **stats; int n; } *

user_defined_types: struct dir_list { struct dirent **dents; struct stat **stats; int n; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
int update_dir_list()
{
void *v0; // rax
_DWORD *v1; // rbx
int v2; // eax
int *v3; // rbp
__int64 v4; // rbx
_QWORD *v5; // rax
_QWORD *v6; // r12
__int64 v7; // rbx
struct stat *v8; // rax
__int64 v9; // rdx
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
char v17[4120]; // [rsp+0h] [rbp-1018h] BYREF

if ( getcwd(v17, 0x1000uLL) )
{
if ( current )
free_dir_list(current);
v0 = malloc(0x18uLL);
current = v0;
v1 = v0;
if ( !v0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
logprintf("2%s: %s", "can't allocate mem for dir_list", v15);
exit(1);
}
v2 = scandir(
v17,
(struct dirent ***)v0,
(int (*)(const struct dirent *))is_hidden,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
v3 = (int *)current;
v1[4] = v2;
v4 = v3[4];
v5 = malloc(8 * v4);
*((_QWORD *)v3 + 1) = v5;
v6 = v5;
if ( (int)v4 > 0 )
{
v7 = 0LL;
while ( 1 )
{
v8 = (struct stat *)malloc(0x90uLL);
v6[v7] = v8;
LODWORD(v5) = stat((const char *)(*(_QWORD *)(*(_QWORD *)v3 + 8 * v7) + 19LL), v8);
if ( (_DWORD)v5 )
{
v9 = *(_QWORD *)(*(_QWORD *)current + 8 * v7++);
fprintf(stderr, "file %s: ", (const char *)(v9 + 19));
v10 = _errno_location();
v11 = strerror(*v10);
LODWORD(v5) = logprintf("2%s: %s", "stat", v11);
v3 = (int *)current;
if ( *((_DWORD *)current + 4) <= (int)v7 )
return (int)v5;
}
else
{
v3 = (int *)current;
if ( *((_DWORD *)current + 4) <= (int)++v7 )
return (int)v5;
}
v6 = (_QWORD *)*((_QWORD *)v3 + 1);
}
}
}
else
{
v12 = _errno_location();
v13 = strerror(*v12);
LODWORD(v5) = logprintf("2%s: %s", "getcwd", v13);
}
return (int)v5;
}

canonical_decompiled_code:
int func3()
{
void *v0; // rax
_DWORD *v1; // rbx
int v2; // eax
int *v3; // rbp
__int64 v4; // rbx
_QWORD *v5; // rax
_QWORD *v6; // r12
__int64 v7; // rbx
struct stat *v8; // rax
__int64 v9; // rdx
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
char v17[4120]; // [rsp+0h] [rbp-1018h] BYREF

if ( getcwd(v17, 0x1000uLL) )
{
if ( current )
func2(current);
v0 = malloc(0x18uLL);
current = v0;
v1 = v0;
if ( !v0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
logprintf("2%s: %s", "can't allocate mem for dir_list", v15);
exit(1);
}
v2 = scandir(
v17,
(struct dirent ***)v0,
(int (*)(const struct dirent *))is_hidden,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
v3 = (int *)current;
v1[4] = v2;
v4 = v3[4];
v5 = malloc(8 * v4);
*((_QWORD *)v3 + 1) = v5;
v6 = v5;
if ( (int)v4 > 0 )
{
v7 = 0LL;
while ( 1 )
{
v8 = (struct stat *)malloc(0x90uLL);
v6[v7] = v8;
LODWORD(v5) = stat((const char *)(*(_QWORD *)(*(_QWORD *)v3 + 8 * v7) + 19LL), v8);
if ( (_DWORD)v5 )
{
v9 = *(_QWORD *)(*(_QWORD *)current + 8 * v7++);
fprintf(stderr, "file %s: ", (const char *)(v9 + 19));
v10 = _errno_location();
v11 = strerror(*v10);
LODWORD(v5) = logprintf("2%s: %s", "stat", v11);
v3 = (int *)current;
if ( *((_DWORD *)current + 4) <= (int)v7 )
return (int)v5;
}
else
{
v3 = (int *)current;
if ( *((_DWORD *)current + 4) <= (int)++v7 )
return (int)v5;
}
v6 = (_QWORD *)*((_QWORD *)v3 + 1);
}
}
}
else
{
v12 = _errno_location();
v13 = strerror(*v12);
LODWORD(v5) = logprintf("2%s: %s", "getcwd", v13);
}
return (int)v5;
}

original_code:
void update_dir_list(void) {
 char pwd[4096];
 if (getcwd(pwd, 4096) == ((void *)0)) {
  logprintf("2%s: %s", "getcwd", strerror((*__errno_location ())));
  return;
 }
 if (current != ((void *)0)) free_dir_list(current);
 current = malloc(sizeof(struct dir_list));
 if (current == ((void *)0)) {
  logprintf("2%s: %s", "can't allocate mem for dir_list", strerror((*__errno_location ())));
  exit(1);
 }
 current->n = scandir(pwd, &current->dents, is_hidden, alphasort);
 current->stats = malloc(current->n * sizeof(struct stat *));
 for (int i = 0; i < current->n; ++i) {
  current->stats[i] = malloc(sizeof(struct stat));
  if (stat(current->dents[i]->d_name, current->stats[i])) {
   fprintf(stderr, "file %s: ", current->dents[i]->d_name);
   logprintf("2%s: %s", "stat", strerror((*__errno_location ())));
  }
 }
}

canonical_original_code:
void update_dir_list() {
 char pwd[4096];
 if (getcwd(pwd, 4096) == ((void *)0)) {
  logprintf("2%s: %s", "getcwd", strerror((*__errno_location ())));
  return;
 }
 if (current != ((void *)0)) free_dir_list(current);
 current = malloc(sizeof(struct dir_list));
 if (current == ((void *)0)) {
  logprintf("2%s: %s", "can't allocate mem for dir_list", strerror((*__errno_location ())));
  exit(1);
 }
 current->n = scandir(pwd, &current->dents, is_hidden, alphasort);
 current->stats = malloc(current->n * sizeof(struct stat *));
 for (int i = 0; i < current->n; ++i) {
  current->stats[i] = malloc(sizeof(struct stat));
  if (stat(current->dents[i]->d_name, current->stats[i])) {
   fprintf(stderr, "file %s: ", current->dents[i]->d_name);
   logprintf("2%s: %s", "stat", strerror((*__errno_location ())));
  }
 }
}

variable_types:
pwd
char [4096]

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
int __fastcall cmp_ext(const char *a1, const char *a2)
{
char *v2; // rax
int result; // eax

v2 = strrchr(a1, 46);
if ( v2 )
result = strcasecmp(v2, a2);
else
result = 1;
return result;
}

canonical_decompiled_code:
int __fastcall func4(const char *a1, const char *a2)
{
char *v2; // rax
int result; // eax

v2 = strrchr(a1, 46);
if ( v2 )
result = strcasecmp(v2, a2);
else
result = 1;
return result;
}

original_code:
int cmp_ext(char *file, char *ext) {
 char *dot = strrchr(file, '.');
 if (dot == ((void *)0)) return 1;
 return strcasecmp(dot, ext);
}

variable_types:
file
char *

variable_types:
ext
char *

variable_types:
dot
char *


decompiled_code:
int __fastcall cmp_base(char *s1, char *s2)
{
char *v2; // rax

v2 = strchr(s1, 46);
return strncasecmp(s1, s2, v2 - s1 - 1);
}

canonical_decompiled_code:
int __fastcall func5(char *s1, char *s2)
{
char *v2; // rax

v2 = strchr(s1, 46);
return strncasecmp(s1, s2, v2 - s1 - 1);
}

original_code:
int cmp_base(char *file, char *base) {
 return strncasecmp(file, base, strchr(file, '.') - file - 1);
}

variable_types:
base
char *


original_code:
int is_android(char *name) {
 if (!strncmp(name, "android", 7)) return 1;
 if (!strncmp(name, "cm-", 3)) return 1;
 return 0;
}

variable_types:
name
char *


decompiled_code:
const char **update_lv_lists()
{
__int64 v0; // rax
_QWORD *v1; // rbx
__int64 v2; // rbp
const char **result; // rax
size_t v4; // rdx
__int64 v5; // rbp
char *v6; // rax
__int64 v7; // r15
int v8; // edx
int v9; // er13
__int64 v10; // rbx
__int64 v11; // r14
bool v12; // zf
__int64 v13; // [rsp+8h] [rbp-1060h] BYREF
char dest[32]; // [rsp+10h] [rbp-1058h] BYREF
char s[4152]; // [rsp+30h] [rbp-1038h] BYREF

if ( lvs )
free_dir_list(lvs);
if ( lv_sets )
free_str_list();
lvs = malloc(0x18uLL);
*((_DWORD *)lvs + 4) = scandir(
"/dev/store",
(struct dirent ***)lvs,
(int (*)(const struct dirent *))is_lv,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
v0 = new_str_list(*((unsigned int *)lvs + 4));
v1 = lvs;
lv_sets = v0;
v2 = *((int *)lvs + 4);
result = (const char **)malloc(8 * v2);
v1[1] = result;
if ( (int)v2 > 0 )
{
v4 = 8 * v2;
v5 = 0LL;
memset(result, 0, v4);
do
{
while ( 1 )
{
strncpy(dest, (const char *)(*(_QWORD *)(*v1 + 8 * v5) + 19LL), 0x20uLL);
sprintf(s, "blockdev --getsize64 '/dev/store/%s'", dest);
qpscanf(s, "%lld", &v13);
lv_sizes[v5] = v13 / 0x100000;
result = (const char **)is_android((unsigned __int8 *)dest);
if ( (_DWORD)result )
{
v6 = strchr(dest, 45);
v7 = lv_sets;
*v6 = 0;
v8 = *(_DWORD *)(v7 + 12);
if ( v8 <= 0 )
break;
result = *(const char ***)v7;
v9 = 1;
v10 = *(_QWORD *)v7 + 8LL;
v11 = v10 + 8LL * (unsigned int)(v8 - 1);
while ( 1 )
{
v12 = strcmp(dest, *result) == 0;
result = (const char **)v10;
if ( v12 )
v9 = 0;
if ( v11 == v10 )
break;
v10 += 8LL;
}
if ( v9 )
break;
}
v1 = lvs;
if ( *((_DWORD *)lvs + 4) <= (int)++v5 )
return result;
}
++v5;
result = (const char **)append_to_str_list(v7, dest);
v1 = lvs;
}
while ( *((_DWORD *)lvs + 4) > (int)v5 );
}
return result;
}

canonical_decompiled_code:
const char **func7()
{
__int64 v0; // rax
_QWORD *v1; // rbx
__int64 v2; // rbp
const char **result; // rax
size_t v4; // rdx
__int64 v5; // rbp
char *v6; // rax
__int64 v7; // r15
int v8; // edx
int v9; // er13
__int64 v10; // rbx
__int64 v11; // r14
bool v12; // zf
__int64 v13; // [rsp+8h] [rbp-1060h] BYREF
char dest[32]; // [rsp+10h] [rbp-1058h] BYREF
char s[4152]; // [rsp+30h] [rbp-1038h] BYREF

if ( lvs )
func2(lvs);
if ( lv_sets )
free_str_list();
lvs = malloc(0x18uLL);
*((_DWORD *)lvs + 4) = scandir(
"/dev/store",
(struct dirent ***)lvs,
(int (*)(const struct dirent *))is_lv,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
v0 = new_str_list(*((unsigned int *)lvs + 4));
v1 = lvs;
lv_sets = v0;
v2 = *((int *)lvs + 4);
result = (const char **)malloc(8 * v2);
v1[1] = result;
if ( (int)v2 > 0 )
{
v4 = 8 * v2;
v5 = 0LL;
memset(result, 0, v4);
do
{
while ( 1 )
{
strncpy(dest, (const char *)(*(_QWORD *)(*v1 + 8 * v5) + 19LL), 0x20uLL);
sprintf(s, "blockdev --getsize64 '/dev/store/%s'", dest);
qpscanf(s, "%lld", &v13);
lv_sizes[v5] = v13 / 0x100000;
result = (const char **)func6((unsigned __int8 *)dest);
if ( (_DWORD)result )
{
v6 = strchr(dest, 45);
v7 = lv_sets;
*v6 = 0;
v8 = *(_DWORD *)(v7 + 12);
if ( v8 <= 0 )
break;
result = *(const char ***)v7;
v9 = 1;
v10 = *(_QWORD *)v7 + 8LL;
v11 = v10 + 8LL * (unsigned int)(v8 - 1);
while ( 1 )
{
v12 = strcmp(dest, *result) == 0;
result = (const char **)v10;
if ( v12 )
v9 = 0;
if ( v11 == v10 )
break;
v10 += 8LL;
}
if ( v9 )
break;
}
v1 = lvs;
if ( *((_DWORD *)lvs + 4) <= (int)++v5 )
return result;
}
++v5;
result = (const char **)append_to_str_list(v7, dest);
v1 = lvs;
}
while ( *((_DWORD *)lvs + 4) > (int)v5 );
}
return result;
}

original_code:
void update_lv_lists(void) {
 char name[32], *dash, cmd[4096];
 int add;
 long long size;
 if (lvs != ((void *)0)) free_dir_list(lvs);
 if (lv_sets != ((void *)0)) free_str_list(lv_sets);
 lvs = malloc(sizeof(struct dir_list));
 lvs->n = scandir("/dev/store", &lvs->dents, is_lv, alphasort);
 lv_sets = new_str_list(lvs->n);
 lvs->stats = malloc(lvs->n * sizeof(struct stat *));
 for (int i = 0; i < lvs->n; ++i) lvs->stats[i] = ((void *)0);
 for (int i = 0; i < lvs->n; ++i) {
  strncpy(name, lvs->dents[i]->d_name, 32);
  sprintf(cmd, "blockdev --getsize64 '/dev/store/%s'", name);
  qpscanf(cmd, "%lld", &size);
  lv_sizes[i] = size / 1048576;
  if (is_android(name)) {
   dash = strchr(name, '-');
   *dash = '\0';
   add = 1;
   for (int j = 0; j < lv_sets->used; ++j)
    if (!strcmp(name, lv_sets->data[j]))
     add = 0;
   if (add) append_to_str_list(lv_sets, name);
  }
 }
}

canonical_original_code:
void update_lv_lists() {
 char name[32]; char *dash; char cmd[4096];
 int add;
 long long size;
 if (lvs != ((void *)0)) free_dir_list(lvs);
 if (lv_sets != ((void *)0)) free_str_list(lv_sets);
 lvs = malloc(sizeof(struct dir_list));
 lvs->n = scandir("/dev/store", &lvs->dents, is_lv, alphasort);
 lv_sets = new_str_list(lvs->n);
 lvs->stats = malloc(lvs->n * sizeof(struct stat *));
 for (int i = 0; i < lvs->n; ++i) lvs->stats[i] = ((void *)0);
 for (int i = 0; i < lvs->n; ++i) {
  strncpy(name, lvs->dents[i]->d_name, 32);
  sprintf(cmd, "blockdev --getsize64 '/dev/store/%s'", name);
  qpscanf(cmd, "%lld", &size);
  lv_sizes[i] = size / 1048576;
  if (is_android(name)) {
   dash = strchr(name, '-');
   *dash = '\0';
   add = 1;
   for (int j = 0; j < lv_sets->used; ++j)
    if (!strcmp(name, lv_sets->data[j]))
     add = 0;
   if (add) append_to_str_list(lv_sets, name);
  }
 }
}

variable_types:
name
char [32]

variable_types:
dash
char *

variable_types:
cmd
char [4096]

variable_types: add int

variable_types:
size
long long

variable_types: j int


decompiled_code:
_BOOL8 __fastcall file_is_dir(int a1)
{
return (*(_DWORD *)(*(_QWORD *)(*((_QWORD *)current + 1) + 8LL * a1) + 24LL) & 0xF000) == 0x4000;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(int a1)
{
return (*(_DWORD *)(*(_QWORD *)(*((_QWORD *)current + 1) + 8LL * a1) + 24LL) & 0xF000) == 0x4000;
}

original_code:
int file_is_dir(int num) {
 return ((((current->stats[num]->st_mode)) & 0170000) == (0040000));
}

variable_types: num int


decompiled_code:
__int64 __fastcall file_name(int a1)
{
return *(_QWORD *)(*(_QWORD *)current + 8LL * a1) + 19LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
return *(_QWORD *)(*(_QWORD *)current + 8LL * a1) + 19LL;
}

original_code:
char * file_name(int num) {
 return current->dents[num]->d_name;
}

canonical_original_code:
char *file_name(int num) {
 return current->dents[num]->d_name;
}

return_type: char *


decompiled_code:
__int64 file_count()
{
return *((unsigned int *)current + 4);
}

canonical_decompiled_code:
__int64 func10()
{
return *((unsigned int *)current + 4);
}

original_code:
int file_count(void) {
 return current->n;
}

canonical_original_code:
int file_count() {
 return current->n;
}


decompiled_code:
__int64 lv_count()
{
return *((unsigned int *)lvs + 4);
}

canonical_decompiled_code:
__int64 func11()
{
return *((unsigned int *)lvs + 4);
}

original_code:
int lv_count(void) {
 return lvs->n;
}

canonical_original_code:
int lv_count() {
 return lvs->n;
}


decompiled_code:
__int64 lv_set_count()
{
return *(unsigned int *)(lv_sets + 12);
}

canonical_decompiled_code:
__int64 func12()
{
return *(unsigned int *)(lv_sets + 12);
}

original_code:
int lv_set_count(void) {
 return lv_sets->used;
}

canonical_original_code:
int lv_set_count() {
 return lv_sets->used;
}


decompiled_code:
__int64 __fastcall lv_name(int a1)
{
return *(_QWORD *)(*(_QWORD *)lvs + 8LL * a1) + 19LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
return *(_QWORD *)(*(_QWORD *)lvs + 8LL * a1) + 19LL;
}

original_code:
char * lv_name(int num) {
 return lvs->dents[num]->d_name;
}

canonical_original_code:
char *lv_name(int num) {
 return lvs->dents[num]->d_name;
}


decompiled_code:
__int64 __fastcall lv_set_name(int a1)
{
return *(_QWORD *)(*(_QWORD *)lv_sets + 8LL * a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
return *(_QWORD *)(*(_QWORD *)lv_sets + 8LL * a1);
}

original_code:
char * lv_set_name(int num) {
 return lv_sets->data[num];
}

canonical_original_code:
char *lv_set_name(int num) {
 return lv_sets->data[num];
}


decompiled_code:
__int64 __fastcall file_mode(int a1)
{
return *(_DWORD *)(*(_QWORD *)(*((_QWORD *)current + 1) + 8LL * a1) + 24LL) & 0xFFF;
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
return *(_DWORD *)(*(_QWORD *)(*((_QWORD *)current + 1) + 8LL * a1) + 24LL) & 0xFFF;
}

original_code:
int file_mode(int num) {
 return current->stats[num]->st_mode & 07777;
}


decompiled_code:
__int64 __fastcall is_immutable(char *s1)
{
unsigned int v1; // er12
unsigned int v2; // ebp
unsigned __int64 v3; // rbx
int v4; // eax
const char *v5; // r15
size_t v6; // rax

v1 = 0;
v2 = 0;
v3 = (unsigned int)((_DWORD)&immutable_files + 8);
do
{
while ( 1 )
{
v4 = *(_DWORD *)(v3 - 8);
if ( !v4 )
{
if ( !strcasecmp(s1, *(const char **)v3) )
v1 = 1;
goto LABEL_3;
}
if ( v4 == 1 )
break;
logprintf("2unknown immutability match type, idx %d", v2);
LABEL_3:
++v2;
v3 += 16LL;
if ( v2 == 22 )
goto LABEL_9;
}
v5 = *(const char **)v3;
v6 = strlen(*(const char **)v3);
if ( !strncasecmp(s1, v5, v6) )
v1 = 1;
++v2;
v3 += 16LL;
}
while ( v2 != 22 );
LABEL_9:
if ( v1 )
logprintf("1%s is on the immutablity list", s1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *s1)
{
unsigned int v1; // er12
unsigned int v2; // ebp
unsigned __int64 v3; // rbx
int v4; // eax
const char *v5; // r15
size_t v6; // rax

v1 = 0;
v2 = 0;
v3 = (unsigned int)((_DWORD)&immutable_files + 8);
do
{
while ( 1 )
{
v4 = *(_DWORD *)(v3 - 8);
if ( !v4 )
{
if ( !strcasecmp(s1, *(const char **)v3) )
v1 = 1;
goto LABEL_3;
}
if ( v4 == 1 )
break;
logprintf("2unknown immutability match type, idx %d", v2);
LABEL_3:
++v2;
v3 += 16LL;
if ( v2 == 22 )
goto LABEL_9;
}
v5 = *(const char **)v3;
v6 = strlen(*(const char **)v3);
if ( !strncasecmp(s1, v5, v6) )
v1 = 1;
++v2;
v3 += 16LL;
}
while ( v2 != 22 );
LABEL_9:
if ( v1 )
logprintf("1%s is on the immutablity list", s1);
return v1;
}

original_code:
int is_immutable(const char *name) {
 int ret = 0;
 for (int i = 0; i < (sizeof(immutable_files) / sizeof(*(immutable_files))); ++i) {
  switch (immutable_files[i].match_type) {
  case MATCH_WHOLE:
   if (!strcasecmp(name, immutable_files[i].file_name))
    ret = 1;
   break;
  case MATCH_START:
   if (!strncasecmp(name, immutable_files[i].file_name,
    strlen(immutable_files[i].file_name)))
     ret = 1;
   break;
  default:
   logprintf("2unknown immutability match type, idx %d",
    i);
   break;
  }
 }
 if (ret)
  logprintf("1%s is on the immutablity list", name);
 return ret;
}

canonical_original_code:
int is_immutable(char *name) {
 int ret = 0;
 for (int i = 0; i < (sizeof(immutable_files) / sizeof(*(immutable_files))); ++i) {
  switch (immutable_files[i].match_type) {
  case MATCH_WHOLE:
   if (!strcasecmp(name, immutable_files[i].file_name))
    ret = 1;
   break;
  case MATCH_START:
   if (!strncasecmp(name, immutable_files[i].file_name,
    strlen(immutable_files[i].file_name)))
     ret = 1;
   break;
  default:
   logprintf("2unknown immutability match type, idx %d",
    i);
   break;
  }
 }
 if (ret)
  logprintf("1%s is on the immutablity list", name);
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall copy_file(const char *a1, char *a2)
{
__int64 result; // rax

result = is_immutable(a2);
if ( !(_DWORD)result )
{
logprintf("0 from: %s", a1);
logprintf("0 to: %s", a2);
result = sysprintf("cp -rf %s %s", a1, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(const char *a1, char *a2)
{
__int64 result; // rax

result = func16(a2);
if ( !(_DWORD)result )
{
logprintf("0 from: %s", a1);
logprintf("0 to: %s", a2);
result = sysprintf("cp -rf %s %s", a1, a2);
}
return result;
}

original_code:
void copy_file(const char *srcpath, const char *destpath) {
 char cmd[2*4096 + 8];
 int code;
 if (is_immutable(destpath)) return;
 logprintf("0 from: %s", srcpath);
 logprintf("0 to: %s", destpath);
 sysprintf("cp -rf %s %s", srcpath, destpath);
}

canonical_original_code:
void copy_file(char *srcpath, char *destpath) {
 char cmd[-1];
 int code;
 if (is_immutable(destpath)) return;
 logprintf("0 from: %s", srcpath);
 logprintf("0 to: %s", destpath);
 sysprintf("cp -rf %s %s", srcpath, destpath);
}

variable_types:
srcpath
char *

variable_types:
destpath
char *

variable_types:
cmd
char [-1]

variable_types: code int


decompiled_code:
__int64 __fastcall move_file(char *a1, char *a2)
{
__int64 result; // rax

result = is_immutable(a1);
if ( !(_DWORD)result )
{
result = is_immutable(a2);
if ( !(_DWORD)result )
{
logprintf("0 from: %s", a1);
logprintf("0 to: %s", a2);
result = sysprintf("mv %s %s", a1, a2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(char *a1, char *a2)
{
__int64 result; // rax

result = func16(a1);
if ( !(_DWORD)result )
{
result = func16(a2);
if ( !(_DWORD)result )
{
logprintf("0 from: %s", a1);
logprintf("0 to: %s", a2);
result = sysprintf("mv %s %s", a1, a2);
}
}
return result;
}

original_code:
void move_file(const char *srcpath, const char *destpath) {
 char cmd[2*4096 + 4];
 int code;
 if (is_immutable(srcpath)) return;
 if (is_immutable(destpath)) return;
 logprintf("0 from: %s", srcpath);
 logprintf("0 to: %s", destpath);
 sysprintf("mv %s %s", srcpath, destpath);
}

canonical_original_code:
void move_file(char *srcpath, char *destpath) {
 char cmd[-1];
 int code;
 if (is_immutable(srcpath)) return;
 if (is_immutable(destpath)) return;
 logprintf("0 from: %s", srcpath);
 logprintf("0 to: %s", destpath);
 sysprintf("mv %s %s", srcpath, destpath);
}


decompiled_code:
int __fastcall delete_file(char *name)
{
int result; // eax

result = is_immutable(name);
if ( !result )
result = unlink(name);
return result;
}

canonical_decompiled_code:
int __fastcall func19(char *name)
{
int result; // eax

result = func16(name);
if ( !result )
result = unlink(name);
return result;
}

original_code:
void delete_file(const char *path) {
 if (!is_immutable(path)) unlink(path);
}

canonical_original_code:
void delete_file(char *path) {
 if (!is_immutable(path)) unlink(path);
}

variable_types:
path
char *


decompiled_code:
int __fastcall umount_lv(const char *a1)
{
char *v1; // rax
char v3[4104]; // [rsp+0h] [rbp-1008h] BYREF

logprintf("0unmounting volume %s", a1);
sprintf(v3, "umount /mnt/%s", a1);
while ( !((unsigned __int16)system(v3) >> 8) )
;
v1 = strchr(v3, 45);
if ( v1 )
{
*v1 = 47;
do
LODWORD(v1) = system(v3);
while ( !BYTE1(v1) );
}
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
char *v1; // rax
char v3[4104]; // [rsp+0h] [rbp-1008h] BYREF

logprintf("0unmounting volume %s", a1);
sprintf(v3, "umount /mnt/%s", a1);
while ( !((unsigned __int16)system(v3) >> 8) )
;
v1 = strchr(v3, 45);
if ( v1 )
{
*v1 = 47;
do
LODWORD(v1) = system(v3);
while ( !BYTE1(v1) );
}
return (int)v1;
}

original_code:
void umount_lv(const char *lv) {
 char cmd[4096];
 char *dash;
 int code;
 logprintf("0unmounting volume %s", lv);
 sprintf(cmd, "umount /mnt/%s", lv);
 do {
  code = (((system(cmd)) & 0xff00) >> 8);
 } while (!code);
 dash = strchr(cmd, '-');
 if (dash == ((void *)0)) return;
 *dash = '/';
 do {
  code = (((system(cmd)) & 0xff00) >> 8);
 } while (!code);
}

canonical_original_code:
void umount_lv(char *lv) {
 char cmd[4096];
 char *dash;
 int code;
 logprintf("0unmounting volume %s", lv);
 sprintf(cmd, "umount /mnt/%s", lv);
 do {
  code = (((system(cmd)) & 0xff00) >> 8);
 } while (!code);
 dash = strchr(cmd, '-');
 if (dash == ((void *)0)) return;
 *dash = '/';
 do {
  code = (((system(cmd)) & 0xff00) >> 8);
 } while (!code);
}

variable_types:
lv
char *


decompiled_code:
__int64 __fastcall delete_lv(const char *a1)
{
if ( !strcmp(a1, "root") )
return logprintf("2%s", "root volume may not be removed");
logprintf("0deleting volume %s", a1);
umount_lv(a1);
return sysprintf("lvm lvremove -f store/%s", a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
if ( !strcmp(a1, "root") )
return logprintf("2%s", "root volume may not be removed");
logprintf("0deleting volume %s", a1);
func1(a1);
return sysprintf("lvm lvremove -f store/%s", a1);
}

original_code:
void delete_lv(const char *lv) {
 char cmd[4096];
 int code;
 if (!strcmp(lv, "root")) {
  logprintf("2%s", "root volume may not be removed");
  return;
 }
 logprintf("0deleting volume %s", lv);
 umount_lv(lv);
 sysprintf("lvm lvremove -f store/%s", lv);
}

canonical_original_code:
void delete_lv(char *lv) {
 char cmd[4096];
 int code;
 if (!strcmp(lv, "root")) {
  logprintf("2%s", "root volume may not be removed");
  return;
 }
 logprintf("0deleting volume %s", lv);
 umount_lv(lv);
 sysprintf("lvm lvremove -f store/%s", lv);
}


decompiled_code:
__int64 __fastcall lv_exists(const char *a1)
{
char v2[4104]; // [rsp+0h] [rbp-1008h] BYREF

sprintf(v2, "/dev/store/%s", a1);
return test_file(v2);
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
char v2[4104]; // [rsp+0h] [rbp-1008h] BYREF

sprintf(v2, "/dev/store/%s", a1);
return test_file(v2);
}

original_code:
int lv_exists(const char *lv) {
 char dev[4096];
 sprintf(dev, "/dev/store/%s", lv);
 return test_file(dev);
}

canonical_original_code:
int lv_exists(char *lv) {
 char dev[4096];
 sprintf(dev, "/dev/store/%s", lv);
 return test_file(dev);
}

variable_types:
dev
char [4096]


decompiled_code:
char *__fastcall deduce_lv(const char *a1)
{
char *v1; // rbp

v1 = basename(a1);
if ( !strncasecmp("TouchPadBuntuRootfs", v1, 0x13uLL) )
return strdup("ubuntu-root");
if ( !strncasecmp("ArchLinuxARM-touchpad", v1, 0x15uLL) )
return strdup("arch-root");
if ( !strncasecmp("bodhi-touchpad", v1, 0xEuLL) )
return strdup("bodhi-root");
if ( !strncasecmp("HPTPSlackware", v1, 0xDuLL) )
return strdup("slackware-root");
if ( !strncasecmp("HPTPFedora", v1, 0xAuLL) )
return strdup("fedora-root");
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func4(const char *a1)
{
char *v1; // rbp

v1 = basename(a1);
if ( !strncasecmp("TouchPadBuntuRootfs", v1, 0x13uLL) )
return strdup("ubuntu-root");
if ( !strncasecmp("ArchLinuxARM-touchpad", v1, 0x15uLL) )
return strdup("arch-root");
if ( !strncasecmp("bodhi-touchpad", v1, 0xEuLL) )
return strdup("bodhi-root");
if ( !strncasecmp("HPTPSlackware", v1, 0xDuLL) )
return strdup("slackware-root");
if ( !strncasecmp("HPTPFedora", v1, 0xAuLL) )
return strdup("fedora-root");
return 0LL;
}

original_code:
char * deduce_lv(const char *filename) {
 char *base = basename(filename);
 char *result = ((void *)0);
 if (!strncasecmp("TouchPadBuntuRootfs", base, 19))
  result = strdup("ubuntu-root");
 else if (!strncasecmp("ArchLinuxARM-touchpad", base, 21))
  result = strdup("arch-root");
 else if (!strncasecmp("bodhi-touchpad", base, 14))
  result = strdup("bodhi-root");
 else if (!strncasecmp("HPTPSlackware", base, 13))
  result = strdup("slackware-root");
 else if (!strncasecmp("HPTPFedora", base, 10))
  result = strdup("fedora-root");
 return result;
}

canonical_original_code:
char *deduce_lv(char *filename) {
 char *base = basename(filename);
 char *result = ((void *)0);
 if (!strncasecmp("TouchPadBuntuRootfs", base, 19))
  result = strdup("ubuntu-root");
 else if (!strncasecmp("ArchLinuxARM-touchpad", base, 21))
  result = strdup("arch-root");
 else if (!strncasecmp("bodhi-touchpad", base, 14))
  result = strdup("bodhi-root");
 else if (!strncasecmp("HPTPSlackware", base, 13))
  result = strdup("slackware-root");
 else if (!strncasecmp("HPTPFedora", base, 10))
  result = strdup("fedora-root");
 return result;
}

variable_types:
filename
char *

variable_types:
base
char *

variable_types:
result
char *


decompiled_code:
__int64 __fastcall mount_lv(const char *a1)
{
char *v1; // rax
char v3[4104]; // [rsp+0h] [rbp-1008h] BYREF

logprintf("0mounting volume %s", a1);
snprintf(v3, 0x1000uLL, "/mnt/%s", a1);
mkdir(v3, 0x1EDu);
v1 = get_lv_fstype(a1);
return sysprintf("mount -t %s /dev/store/%s /mnt/%s", v1, a1, a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
char *v1; // rax
char v3[4104]; // [rsp+0h] [rbp-1008h] BYREF

logprintf("0mounting volume %s", a1);
snprintf(v3, 0x1000uLL, "/mnt/%s", a1);
mkdir(v3, 0x1EDu);
v1 = func7(a1);
return sysprintf("mount -t %s /dev/store/%s /mnt/%s", v1, a1, a1);
}

original_code:
void mount_lv(const char *lv) {
 char cmd[4096];
 char *type;
 int code;
 logprintf("0mounting volume %s", lv);
 snprintf(cmd, sizeof(cmd), "/mnt/%s", lv);
 mkdir(cmd, 0755);
 type = get_lv_fstype(lv);
 sysprintf("mount -t %s /dev/store/%s /mnt/%s", type, lv, lv);
}

canonical_original_code:
void mount_lv(char *lv) {
 char cmd[4096];
 char *type;
 int code;
 logprintf("0mounting volume %s", lv);
 snprintf(cmd, sizeof(cmd), "/mnt/%s", lv);
 mkdir(cmd, 0755);
 type = get_lv_fstype(lv);
 sysprintf("mount -t %s /dev/store/%s /mnt/%s", type, lv, lv);
}

variable_types:
type
char *


decompiled_code:
__int64 __fastcall lv_to_tgz(const char *a1, const char *a2)
{
int *v3; // rax
char *v4; // rax
char v5[4120]; // [rsp+0h] [rbp-1018h] BYREF

logprintf("0backing up volume %s to basename %s", a1, a2);
mount_lv("media");
mount_lv(a1);
mkdir("/mnt/media/nsboot/backups", 0x1EDu);
sprintf(v5, "/mnt/%s", a1);
if ( chdir(v5) != -1 )
return sysprintf("tar --numeric-owner -czpf /mnt/media/nsboot/backups/%s.tar.gz .", a2);
v3 = _errno_location();
v4 = strerror(*v3);
return logprintf("2%s: %s", "can't chdir into source fs", v4);
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, const char *a2)
{
int *v3; // rax
char *v4; // rax
char v5[4120]; // [rsp+0h] [rbp-1018h] BYREF

logprintf("0backing up volume %s to basename %s", a1, a2);
func8("media");
func8(a1);
mkdir("/mnt/media/nsboot/backups", 0x1EDu);
sprintf(v5, "/mnt/%s", a1);
if ( chdir(v5) != -1 )
return sysprintf("tar --numeric-owner -czpf /mnt/media/nsboot/backups/%s.tar.gz .", a2);
v3 = _errno_location();
v4 = strerror(*v3);
return logprintf("2%s: %s", "can't chdir into source fs", v4);
}

original_code:
void lv_to_tgz(const char *lv, const char *bname) {
 int code;
 char cmd[4096];
 logprintf("0backing up volume %s to basename %s", lv, bname);
 mount_lv("media");
 mount_lv(lv);
 mkdir("/mnt/media/nsboot/backups", 0755);
 sprintf(cmd, "/mnt/%s", lv);
 if (chdir(cmd) == -1) {
  logprintf("2%s: %s", "can't chdir into source fs", strerror((*__errno_location ())));
  return;
 }
 sysprintf("tar --numeric-owner -czpf /mnt/media/nsboot/backups/%s.tar.gz .",
  bname);
}

canonical_original_code:
void lv_to_tgz(char *lv, char *bname) {
 int code;
 char cmd[4096];
 logprintf("0backing up volume %s to basename %s", lv, bname);
 mount_lv("media");
 mount_lv(lv);
 mkdir("/mnt/media/nsboot/backups", 0755);
 sprintf(cmd, "/mnt/%s", lv);
 if (chdir(cmd) == -1) {
  logprintf("2%s: %s", "can't chdir into source fs", strerror((*__errno_location ())));
  return;
 }
 sysprintf("tar --numeric-owner -czpf /mnt/media/nsboot/backups/%s.tar.gz .",
  bname);
}

variable_types:
bname
char *

variable_types:
cmd
char [4096]


decompiled_code:
__int64 __fastcall wipe_lv(const char *a1)
{
__int64 v1; // rcx
const char *v3; // rdi
const char *v4; // rsi
bool v5; // cf
bool v6; // zf
char *v7; // r12
char v9[4120]; // [rsp+0h] [rbp-1018h] BYREF

v1 = 5LL;
v3 = "root";
v4 = a1;
v5 = 0;
v6 = 0;
do
{
if ( !v1 )
break;
v5 = *v4 < (unsigned int)*v3;
v6 = *v4++ == *v3++;
--v1;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
return logprintf("2root volume may not be wiped", v4);
if ( !(unsigned int)is_lv_mounted("root") )
mount_lv("root");
v7 = get_lv_fstype(a1);
umount_lv(a1);
if ( !strcmp(v7, "swap") )
{
snprintf(v9, 0x1000uLL, "mkswap /dev/store/%s", a1);
}
else if ( !strcmp(v7, "msdos") || !strcmp(v7, "vfat") )
{
snprintf(v9, 0x1000uLL, "mkdosfs /dev/store/%s", a1);
}
else
{
snprintf(v9, 0x1000uLL, "mke2fs -t ext4 /dev/store/%s", a1);
}
logprintf("0making %s filesystem on volume %s", v7, a1);
return system_logged(v9);
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1)
{
__int64 v1; // rcx
const char *v3; // rdi
const char *v4; // rsi
bool v5; // cf
bool v6; // zf
char *v7; // r12
char v9[4120]; // [rsp+0h] [rbp-1018h] BYREF

v1 = 5LL;
v3 = "root";
v4 = a1;
v5 = 0;
v6 = 0;
do
{
if ( !v1 )
break;
v5 = *v4 < (unsigned int)*v3;
v6 = *v4++ == *v3++;
--v1;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
return logprintf("2root volume may not be wiped", v4);
if ( !(unsigned int)func0("root") )
func8("root");
v7 = func7(a1);
func1(a1);
if ( !strcmp(v7, "swap") )
{
snprintf(v9, 0x1000uLL, "mkswap /dev/store/%s", a1);
}
else if ( !strcmp(v7, "msdos") || !strcmp(v7, "vfat") )
{
snprintf(v9, 0x1000uLL, "mkdosfs /dev/store/%s", a1);
}
else
{
snprintf(v9, 0x1000uLL, "mke2fs -t ext4 /dev/store/%s", a1);
}
logprintf("0making %s filesystem on volume %s", v7, a1);
return system_logged(v9);
}

original_code:
void wipe_lv(const char *lv) {
 char cmd[4096], *type;
 int code;
 if (!strcmp(lv, "root")) {
  logprintf("2root volume may not be wiped");
  return;
 }
 if (!is_lv_mounted("root")) mount_lv("root");
 type = get_lv_fstype(lv);
 umount_lv(lv);
 if (!strcmp(type, "swap"))
  snprintf(cmd, sizeof(cmd), "mkswap /dev/store/%s", lv);
 else if (!strcmp(type, "msdos") || !strcmp(type, "vfat"))
  snprintf(cmd, sizeof(cmd), "mkdosfs /dev/store/%s", lv);
 else
  snprintf(cmd, sizeof(cmd), "mke2fs -t ext4 /dev/store/%s", lv);
 logprintf("0making %s filesystem on volume %s", type, lv);
 system_logged(cmd);
}

canonical_original_code:
void wipe_lv(char *lv) {
 char cmd[4096]; char *type;
 int code;
 if (!strcmp(lv, "root")) {
  logprintf("2root volume may not be wiped");
  return;
 }
 if (!is_lv_mounted("root")) mount_lv("root");
 type = get_lv_fstype(lv);
 umount_lv(lv);
 if (!strcmp(type, "swap"))
  snprintf(cmd, sizeof(cmd), "mkswap /dev/store/%s", lv);
 else if (!strcmp(type, "msdos") || !strcmp(type, "vfat"))
  snprintf(cmd, sizeof(cmd), "mkdosfs /dev/store/%s", lv);
 else
  snprintf(cmd, sizeof(cmd), "mke2fs -t ext4 /dev/store/%s", lv);
 logprintf("0making %s filesystem on volume %s", type, lv);
 system_logged(cmd);
}


decompiled_code:
int __fastcall check_lv(const char *a1)
{
char *v1; // rax
char v2; // r12
char v4[4120]; // [rsp+0h] [rbp-1018h] BYREF

logprintf("0checking filesystem on volume %s", a1);
umount_lv(a1);
v1 = get_lv_fstype(a1);
if ( strcmp(v1, "none") && strcmp(v1, "swap") )
{
if ( *v1 == 101 && v1[1] == 120 && v1[2] == 116 )
{
snprintf(v4, 0x1000uLL, "e2fsck -fy /dev/store/%s", a1);
}
else
{
if ( strcmp(v1, "vfat") && strcmp(v1, "msdos") )
{
LODWORD(v1) = logprintf("2error: unknown fstype %s", v1);
return (int)v1;
}
snprintf(v4, 0x1000uLL, "dosfsck -aw /dev/store/%s", a1);
}
LODWORD(v1) = system(v4) >> 8;
v2 = (char)v1;
if ( ((unsigned __int8)v1 & 0xF8) != 0 )
{
LODWORD(v1) = logprintf("2error: fsck quit with abnormal code %d", (unsigned __int8)v1);
}
else
{
if ( ((unsigned __int8)v1 & 1) != 0 )
LODWORD(v1) = logprintf("2%s", "warning: errors were fixed");
if ( (v2 & 4) != 0 )
LODWORD(v1) = logprintf("2%s", "warning: errors were left unfixed");
if ( (v2 & 2) != 0 )
{
logprintf("2%s", "system restart was requested, will reboot in 5s");
sleep(3u);
sync();
LODWORD(v1) = reboot(19088743);
}
}
}
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func11(const char *a1)
{
char *v1; // rax
char v2; // r12
char v4[4120]; // [rsp+0h] [rbp-1018h] BYREF

logprintf("0checking filesystem on volume %s", a1);
func1(a1);
v1 = func7(a1);
if ( strcmp(v1, "none") && strcmp(v1, "swap") )
{
if ( *v1 == 101 && v1[1] == 120 && v1[2] == 116 )
{
snprintf(v4, 0x1000uLL, "e2fsck -fy /dev/store/%s", a1);
}
else
{
if ( strcmp(v1, "vfat") && strcmp(v1, "msdos") )
{
LODWORD(v1) = logprintf("2error: unknown fstype %s", v1);
return (int)v1;
}
snprintf(v4, 0x1000uLL, "dosfsck -aw /dev/store/%s", a1);
}
LODWORD(v1) = system(v4) >> 8;
v2 = (char)v1;
if ( ((unsigned __int8)v1 & 0xF8) != 0 )
{
LODWORD(v1) = logprintf("2error: fsck quit with abnormal code %d", (unsigned __int8)v1);
}
else
{
if ( ((unsigned __int8)v1 & 1) != 0 )
LODWORD(v1) = logprintf("2%s", "warning: errors were fixed");
if ( (v2 & 4) != 0 )
LODWORD(v1) = logprintf("2%s", "warning: errors were left unfixed");
if ( (v2 & 2) != 0 )
{
logprintf("2%s", "system restart was requested, will reboot in 5s");
sleep(3u);
sync();
LODWORD(v1) = reboot(19088743);
}
}
}
return (int)v1;
}

original_code:
void check_lv(const char *lv) {
 int code;
 char cmd[4096], *type;
 logprintf("0checking filesystem on volume %s", lv);
 umount_lv(lv);
 type = get_lv_fstype(lv);
 if (!strcmp(type, "none") || !strcmp(type, "swap")) return;
 else if (!strncmp(type, "ext", 3))
  snprintf(cmd, sizeof(cmd), "e2fsck -fy /dev/store/%s", lv);
 else if (!strcmp(type, "vfat") || !strcmp(type, "msdos"))
  snprintf(cmd, sizeof(cmd), "dosfsck -aw /dev/store/%s", lv);
 else {
  logprintf("2error: unknown fstype %s", type);
  return;
 }
 code = (((system(cmd)) & 0xff00) >> 8);
 if (code > 7) {
  logprintf("2error: fsck quit with abnormal code %d", code);
  return;
 }
 if (code & 1) logprintf("2%s", "warning: errors were fixed");
 if (code & 4) logprintf("2%s", "warning: errors were left unfixed");
 if (code & 2) {
  logprintf("2%s", "system restart was requested, will reboot in 5s");
  sleep(3);
  sync();
  reboot(0x01234567);
 }
}

canonical_original_code:
void check_lv(char *lv) {
 int code;
 char cmd[4096]; char *type;
 logprintf("0checking filesystem on volume %s", lv);
 umount_lv(lv);
 type = get_lv_fstype(lv);
 if (!strcmp(type, "none") || !strcmp(type, "swap")) return;
 else if (!strncmp(type, "ext", 3))
  snprintf(cmd, sizeof(cmd), "e2fsck -fy /dev/store/%s", lv);
 else if (!strcmp(type, "vfat") || !strcmp(type, "msdos"))
  snprintf(cmd, sizeof(cmd), "dosfsck -aw /dev/store/%s", lv);
 else {
  logprintf("2error: unknown fstype %s", type);
  return;
 }
 code = (((system(cmd)) & 0xff00) >> 8);
 if (code > 7) {
  logprintf("2error: fsck quit with abnormal code %d", code);
  return;
 }
 if (code & 1) logprintf("2%s", "warning: errors were fixed");
 if (code & 4) logprintf("2%s", "warning: errors were left unfixed");
 if (code & 2) {
  logprintf("2%s", "system restart was requested, will reboot in 5s");
  sleep(3);
  sync();
  reboot(0x01234567);
 }
}


decompiled_code:
char __fastcall resize_lv(const char *a1, int a2, int a3)
{
int v4; // ebx
__int64 v5; // rax
__int64 v6; // rbx
__int64 v7; // r14
__int64 v8; // r15
bool v9; // zf
__int64 v10; // r12
__int64 v11; // r13
__int64 v12; // rsi
int v13; // eax
char *v15; // [rsp+8h] [rbp-40h]

v4 = 5;
do
{
if ( (unsigned int)is_lv_mounted(a1) )
umount_lv(a1);
--v4;
}
while ( v4 );
if ( (unsigned int)is_lv_mounted(a1) )
logprintf("3refusing to resize a volume which is likely in use.");
v5 = get_lv_size(a1);
v6 = v5;
if ( v5 != -1 )
{
v5 = get_free_vg_space();
v7 = v5;
if ( v5 != -1 )
{
v5 = get_free_lv_space(a1);
v8 = v5;
if ( v5 != -1 )
{
v15 = get_lv_fstype(a1);
v9 = strcmp(v15, "none") == 0;
LOBYTE(v5) = !v9;
if ( !v9 )
{
mount_lv("root");
v10 = (int)abs32(a3);
switch ( a2 )
{
case 0:
v11 = v6 + (int)v10;
logprintf("0growing volume %s to %ld MiB", a1, v11);
v12 = -(__int64)(int)v10;
break;
case 1:
v11 = v6 - (int)v10;
logprintf("0shrinking volume %s to %ld MiB", a1, v11);
v12 = (int)v10;
break;
case 2:
logprintf("0resizing volume %s to %ld MiB", a1, (int)v10);
v11 = (int)v10;
v12 = v6 - (int)v10;
break;
case 3:
logprintf("0reclaming %ld MiB of free space into volume %s", v7, a1);
v11 = v6 + v7;
v12 = -v7;
break;
case 4:
v11 = v6 + v7 - (int)v10;
logprintf("0making %ld MiB of space by shrinking volume %s", (int)v10, a1);
v12 = v10 - v7;
break;
default:
v11 = 0LL;
v12 = v6;
break;
}
if ( v12 > v8 )
{
LOBYTE(v5) = logprintf("2free space is too low to shrink, %ld MiB more is needed", v12 - v8);
}
else
{
v13 = (unsigned __int8)*v15 - 101;
if ( *v15 == 101 )
{
v13 = (unsigned __int8)v15[1] - 120;
if ( v15[1] == 120 )
v13 = (unsigned __int8)v15[2] - 116;
}
if ( (v13 || v11 < v6) && (umount_lv(a1), !strcmp(a1, "root")) && v11 < v6 )
{
LOBYTE(v5) = logprintf("2%s", "root volume may not be shrunken");
}
else
{
if ( v6 + v7 < v11 )
resize_lv("media", 4LL, v11 - v6);
umount_lv(a1);
check_lv(a1);
if ( v11 > v6 )
sysprintf("lvm lvresize -fL %ld'M' store/%s", v11, a1);
if ( !strcmp(v15, "vfat") || !strcmp(v15, "msdos") )
{
logprintf("0%s", "resizing FAT filesystem");
sysprintf("resizefat /dev/store/%s %ld'M'", a1, v11);
}
else if ( *v15 == 101 && v15[1] == 120 && v15[2] == 116 )
{
logprintf("0resizing %s filesystem", v15);
sysprintf("resize2fs /dev/store/%s %ld'M'", a1, v11);
}
if ( v11 < v6 )
sysprintf("lvm lvresize -fL %ld'M' store/%s", v11, a1);
if ( !strcmp(v15, "swap") )
wipe_lv(a1);
LOBYTE(v5) = mount_lv(a1);
}
}
}
}
}
}
return v5;
}

canonical_decompiled_code:
char __fastcall func13(const char *a1, int a2, int a3)
{
int v4; // ebx
__int64 v5; // rax
__int64 v6; // rbx
__int64 v7; // r14
__int64 v8; // r15
bool v9; // zf
__int64 v10; // r12
__int64 v11; // r13
__int64 v12; // rsi
int v13; // eax
char *v15; // [rsp+8h] [rbp-40h]

v4 = 5;
do
{
if ( (unsigned int)func0(a1) )
func1(a1);
--v4;
}
while ( v4 );
if ( (unsigned int)func0(a1) )
logprintf("3refusing to resize a volume which is likely in use.");
v5 = func6(a1);
v6 = v5;
if ( v5 != -1 )
{
v5 = func5();
v7 = v5;
if ( v5 != -1 )
{
v5 = func12(a1);
v8 = v5;
if ( v5 != -1 )
{
v15 = func7(a1);
v9 = strcmp(v15, "none") == 0;
LOBYTE(v5) = !v9;
if ( !v9 )
{
func8("root");
v10 = (int)abs32(a3);
switch ( a2 )
{
case 0:
v11 = v6 + (int)v10;
logprintf("0growing volume %s to %ld MiB", a1, v11);
v12 = -(__int64)(int)v10;
break;
case 1:
v11 = v6 - (int)v10;
logprintf("0shrinking volume %s to %ld MiB", a1, v11);
v12 = (int)v10;
break;
case 2:
logprintf("0resizing volume %s to %ld MiB", a1, (int)v10);
v11 = (int)v10;
v12 = v6 - (int)v10;
break;
case 3:
logprintf("0reclaming %ld MiB of free space into volume %s", v7, a1);
v11 = v6 + v7;
v12 = -v7;
break;
case 4:
v11 = v6 + v7 - (int)v10;
logprintf("0making %ld MiB of space by shrinking volume %s", (int)v10, a1);
v12 = v10 - v7;
break;
default:
v11 = 0LL;
v12 = v6;
break;
}
if ( v12 > v8 )
{
LOBYTE(v5) = logprintf("2free space is too low to shrink, %ld MiB more is needed", v12 - v8);
}
else
{
v13 = (unsigned __int8)*v15 - 101;
if ( *v15 == 101 )
{
v13 = (unsigned __int8)v15[1] - 120;
if ( v15[1] == 120 )
v13 = (unsigned __int8)v15[2] - 116;
}
if ( (v13 || v11 < v6) && (func1(a1), !strcmp(a1, "root")) && v11 < v6 )
{
LOBYTE(v5) = logprintf("2%s", "root volume may not be shrunken");
}
else
{
if ( v6 + v7 < v11 )
func13("media", 4LL, v11 - v6);
func1(a1);
func11(a1);
if ( v11 > v6 )
sysprintf("lvm lvresize -fL %ld'M' store/%s", v11, a1);
if ( !strcmp(v15, "vfat") || !strcmp(v15, "msdos") )
{
logprintf("0%s", "resizing FAT filesystem");
sysprintf("resizefat /dev/store/%s %ld'M'", a1, v11);
}
else if ( *v15 == 101 && v15[1] == 120 && v15[2] == 116 )
{
logprintf("0resizing %s filesystem", v15);
sysprintf("resize2fs /dev/store/%s %ld'M'", a1, v11);
}
if ( v11 < v6 )
sysprintf("lvm lvresize -fL %ld'M' store/%s", v11, a1);
if ( !strcmp(v15, "swap") )
func10(a1);
LOBYTE(v5) = func8(a1);
}
}
}
}
}
}
return v5;
}

original_code:
void resize_lv(const char *lv, enum resizemode mode, long arg) {
 char cmd[4096], *type;
 long oldsize, newsize, space, free;
        int code;
 for (int i = 0; i < 5; ++i) {
  if (is_lv_mounted(lv)) umount_lv(lv);
 }
 if (is_lv_mounted(lv)) {
  logprintf("3refusing to resize a volume which is likely in use.");
 }
 oldsize = get_lv_size(lv);
 if (oldsize == -1) return;
 space = get_free_vg_space();
 if (space == -1) return;
 free = get_free_lv_space(lv);
 if (free == -1) return;
 type = get_lv_fstype(lv);
 if (!strcmp(type, "none")) return;
 mount_lv("root");
 arg = abs(arg);
 switch (mode) {
 case RS_GROW:
  newsize = oldsize + arg;
  logprintf("0growing volume %s to %ld MiB", lv, newsize);
  break;
 case RS_SHRINK:
  newsize = oldsize - arg;
  logprintf("0shrinking volume %s to %ld MiB", lv, newsize);
  break;
 case RS_SET:
  newsize = arg;
  logprintf("0resizing volume %s to %ld MiB", lv, newsize);
  break;
 case RS_RECLAIM:
  newsize = oldsize + space;
  logprintf("0reclaming %ld MiB of free space into volume %s", space, lv);
  break;
 case RS_FREE:
  newsize = oldsize + space - arg;
  logprintf("0making %ld MiB of space by shrinking volume %s", arg, lv);
  break;
 }
 if (free < oldsize - newsize) {
  logprintf("2free space is too low to shrink, %ld MiB more is needed",
   oldsize - newsize - free);
  return;
 }
 if (strncmp(type, "ext", 3) || (newsize < oldsize)) umount_lv(lv);
 if (!strcmp(lv, "root") && (newsize < oldsize)) {
  logprintf("2%s", "root volume may not be shrunken");
  return;
 }
 if (newsize > oldsize + space) resize_lv("media", RS_FREE, newsize - oldsize);
 umount_lv(lv);
 check_lv(lv);
 if (newsize > oldsize)
  sysprintf("lvm lvresize -fL %ld'M' store/%s", newsize, lv);
 if (!strcmp(type, "vfat") || !strcmp(type, "msdos")) {
  logprintf("0%s","resizing FAT filesystem");
  sysprintf("resizefat /dev/store/%s %ld'M'", lv, newsize);
 } else if (!strncmp(type, "ext", 3)) {
  logprintf("0resizing %s filesystem", type);
  sysprintf("resize2fs /dev/store/%s %ld'M'", lv, newsize);
 }
 if (newsize < oldsize)
  sysprintf("lvm lvresize -fL %ld'M' store/%s", newsize, lv);
 if (!strcmp(type, "swap")) wipe_lv(lv);
 mount_lv(lv);
}

canonical_original_code:
void resize_lv(char *lv, enum resizemode mode, long arg) {
 char cmd[4096]; char *type;
 long oldsize; long newsize; long space; long free;
        int code;
 for (int i = 0; i < 5; ++i) {
  if (is_lv_mounted(lv)) umount_lv(lv);
 }
 if (is_lv_mounted(lv)) {
  logprintf("3refusing to resize a volume which is likely in use.");
 }
 oldsize = get_lv_size(lv);
 if (oldsize == -1) return;
 space = get_free_vg_space();
 if (space == -1) return;
 free = get_free_lv_space(lv);
 if (free == -1) return;
 type = get_lv_fstype(lv);
 if (!strcmp(type, "none")) return;
 mount_lv("root");
 arg = abs(arg);
 switch (mode) {
 case RS_GROW:
  newsize = oldsize + arg;
  logprintf("0growing volume %s to %ld MiB", lv, newsize);
  break;
 case RS_SHRINK:
  newsize = oldsize - arg;
  logprintf("0shrinking volume %s to %ld MiB", lv, newsize);
  break;
 case RS_SET:
  newsize = arg;
  logprintf("0resizing volume %s to %ld MiB", lv, newsize);
  break;
 case RS_RECLAIM:
  newsize = oldsize + space;
  logprintf("0reclaming %ld MiB of free space into volume %s", space, lv);
  break;
 case RS_FREE:
  newsize = oldsize + space - arg;
  logprintf("0making %ld MiB of space by shrinking volume %s", arg, lv);
  break;
 }
 if (free < oldsize - newsize) {
  logprintf("2free space is too low to shrink, %ld MiB more is needed",
   oldsize - newsize - free);
  return;
 }
 if (strncmp(type, "ext", 3) || (newsize < oldsize)) umount_lv(lv);
 if (!strcmp(lv, "root") && (newsize < oldsize)) {
  logprintf("2%s", "root volume may not be shrunken");
  return;
 }
 if (newsize > oldsize + space) resize_lv("media", RS_FREE, newsize - oldsize);
 umount_lv(lv);
 check_lv(lv);
 if (newsize > oldsize)
  sysprintf("lvm lvresize -fL %ld'M' store/%s", newsize, lv);
 if (!strcmp(type, "vfat") || !strcmp(type, "msdos")) {
  logprintf("0%s","resizing FAT filesystem");
  sysprintf("resizefat /dev/store/%s %ld'M'", lv, newsize);
 } else if (!strncmp(type, "ext", 3)) {
  logprintf("0resizing %s filesystem", type);
  sysprintf("resize2fs /dev/store/%s %ld'M'", lv, newsize);
 }
 if (newsize < oldsize)
  sysprintf("lvm lvresize -fL %ld'M' store/%s", newsize, lv);
 if (!strcmp(type, "swap")) wipe_lv(lv);
 mount_lv(lv);
}

variable_types: enum resizemode { RS_GROW=0, RS_SHRINK=1, RS_SET=2, RS_RECLAIM=3, RS_FREE=4 }

variable_types: arg long

variable_types: oldsize long

variable_types: newsize long

variable_types: space long

variable_types: free long

variable_types: i int


decompiled_code:
__int64 __fastcall new_lv(const char *a1, __int64 a2)
{
__int64 result; // rax

result = lv_exists(a1);
if ( !(_DWORD)result )
{
result = get_free_vg_space();
if ( result != -1 )
{
if ( result < a2 )
resize_lv("media", 4, a2);
logprintf("0creating a volume named %s with a size of %ld MiB", a1, a2);
result = sysprintf("lvm lvcreate -n %s -L %ld'M' store", a1, a2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(const char *a1, __int64 a2)
{
__int64 result; // rax

result = func3(a1);
if ( !(_DWORD)result )
{
result = func5();
if ( result != -1 )
{
if ( result < a2 )
func13("media", 4, a2);
logprintf("0creating a volume named %s with a size of %ld MiB", a1, a2);
result = sysprintf("lvm lvcreate -n %s -L %ld'M' store", a1, a2);
}
}
return result;
}

original_code:
void new_lv(const char *lv, const long size_mb) {
 char cmd[4096];
 long space;
 int code;
 if (lv_exists(lv)) return;
 space = get_free_vg_space();
 if (space == -1) return;
 if (space < size_mb) resize_lv("media", RS_FREE, size_mb);
 logprintf("0creating a volume named %s with a size of %ld MiB",
  lv, size_mb);
 sysprintf("lvm lvcreate -n %s -L %ld'M' store", lv, size_mb);
}

canonical_original_code:
void new_lv(char *lv, long size_mb) {
 char cmd[4096];
 long space;
 int code;
 if (lv_exists(lv)) return;
 space = get_free_vg_space();
 if (space == -1) return;
 if (space < size_mb) resize_lv("media", RS_FREE, size_mb);
 logprintf("0creating a volume named %s with a size of %ld MiB",
  lv, size_mb);
 sysprintf("lvm lvcreate -n %s -L %ld'M' store", lv, size_mb);
}

variable_types: code int


decompiled_code:
void free_boot_items()
{
__int64 v0; // r12
int v1; // ebp
_QWORD *v2; // rbx
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi
void *v6; // rdi
void *v7; // rdi

if ( menu_size > 1 )
{
v0 = 0LL;
v1 = 0;
do
{
v2 = (char *)menu + v0;
v3 = *(void **)((char *)menu + v0);
if ( v3 )
free(v3);
v4 = (void *)v2[4];
if ( v4 )
free(v4);
v5 = (void *)v2[1];
if ( v5 )
free(v5);
v6 = (void *)v2[2];
if ( v6 )
free(v6);
v7 = (void *)v2[3];
if ( v7 )
free(v7);
++v1;
v0 += 48LL;
}
while ( menu_size - 1 > v1 );
}
menu_size = 0;
free(menu);
}

canonical_decompiled_code:
void func0()
{
__int64 v0; // r12
int v1; // ebp
_QWORD *v2; // rbx
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi
void *v6; // rdi
void *v7; // rdi

if ( menu_size > 1 )
{
v0 = 0LL;
v1 = 0;
do
{
v2 = (char *)menu + v0;
v3 = *(void **)((char *)menu + v0);
if ( v3 )
free(v3);
v4 = (void *)v2[4];
if ( v4 )
free(v4);
v5 = (void *)v2[1];
if ( v5 )
free(v5);
v6 = (void *)v2[2];
if ( v6 )
free(v6);
v7 = (void *)v2[3];
if ( v7 )
free(v7);
++v1;
v0 += 48LL;
}
while ( menu_size - 1 > v1 );
}
menu_size = 0;
free(menu);
}

original_code:
void free_boot_items(void) {
 boot_item *item;
 for (int i = 0; i < menu_size - 1; ++i) {
  item = menu + i;
  if (item->label != ((void *)0)) free(item->label);
  if (item->append != ((void *)0)) free(item->append);
  if (item->cfgdev != ((void *)0)) free(item->cfgdev);
  if (item->kernel != ((void *)0)) free(item->kernel);
  if (item->initrd != ((void *)0)) free(item->initrd);
 }
 menu_size = 0;
 free(menu);
}

canonical_original_code:
void free_boot_items() {
 struct boot_item *item;
 for (int i = 0; i < menu_size - 1; ++i) {
  item = menu + i;
  if (item->label != ((void *)0)) free(item->label);
  if (item->append != ((void *)0)) free(item->append);
  if (item->cfgdev != ((void *)0)) free(item->cfgdev);
  if (item->kernel != ((void *)0)) free(item->kernel);
  if (item->initrd != ((void *)0)) free(item->initrd);
 }
 menu_size = 0;
 free(menu);
}

variable_types: struct boot_item { char *label; char *cfgdev; char *kernel; char *initrd; char *append; int prio; } *


decompiled_code:
__int64 __fastcall add_boot_item(char *s)
{
void *v1; // rax
__int64 v2; // r12
char *v3; // rax
char *v4; // rax
const char *v5; // rsi
int *v7; // rax
char *v8; // rax

v1 = realloc(menu, 48LL * ++menu_size);
v2 = (__int64)v1;
if ( v1 )
{
menu = v1;
v2 = (__int64)v1 + 48 * menu_size - 48;
v3 = strdup(s);
*(_QWORD *)(v2 + 8) = 0LL;
*(_QWORD *)v2 = v3;
*(_QWORD *)(v2 + 16) = 0LL;
*(_QWORD *)(v2 + 24) = 0LL;
v4 = (char *)malloc(0x200uLL);
v5 = kept_cmdline;
*(_QWORD *)(v2 + 32) = v4;
strcpy(v4, v5);
*(_DWORD *)(v2 + 40) = 0;
}
else
{
v7 = _errno_location();
v8 = strerror(*v7);
logprintf("2%s: %s", "can't allocate for new boot menu", v8);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s)
{
void *v1; // rax
__int64 v2; // r12
char *v3; // rax
char *v4; // rax
const char *v5; // rsi
int *v7; // rax
char *v8; // rax

v1 = realloc(menu, 48LL * ++menu_size);
v2 = (__int64)v1;
if ( v1 )
{
menu = v1;
v2 = (__int64)v1 + 48 * menu_size - 48;
v3 = strdup(s);
*(_QWORD *)(v2 + 8) = 0LL;
*(_QWORD *)v2 = v3;
*(_QWORD *)(v2 + 16) = 0LL;
*(_QWORD *)(v2 + 24) = 0LL;
v4 = (char *)malloc(0x200uLL);
v5 = kept_cmdline;
*(_QWORD *)(v2 + 32) = v4;
strcpy(v4, v5);
*(_DWORD *)(v2 + 40) = 0;
}
else
{
v7 = _errno_location();
v8 = strerror(*v7);
logprintf("2%s: %s", "can't allocate for new boot menu", v8);
}
return v2;
}

original_code:
boot_item * add_boot_item(char *item_label) {
 boot_item *new_menu, *new_item;
 ++menu_size;
 new_menu = realloc(menu, menu_size * sizeof(boot_item));
 if (new_menu == ((void *)0)) {
  logprintf("2%s: %s", "can't allocate for new boot menu", strerror((*__errno_location ())));
  return ((void *)0);
 }
 menu = new_menu;
 new_item = menu + menu_size - 1;
 new_item->label = strdup(item_label);
 new_item->cfgdev = ((void *)0);
 new_item->kernel = ((void *)0);
 new_item->initrd = ((void *)0);
 new_item->append = malloc(512);
 strcpy(new_item->append, kept_cmdline);
 new_item->prio = 0;
 return new_item;
}

canonical_original_code:
struct boot_item *add_boot_item(char *item_label) {
 struct boot_item *new_menu; struct boot_item *new_item;
 ++menu_size;
 new_menu = realloc(menu, menu_size * sizeof(boot_item));
 if (new_menu == ((void *)0)) {
  logprintf("2%s: %s", "can't allocate for new boot menu", strerror((*__errno_location ())));
  return ((void *)0);
 }
 menu = new_menu;
 new_item = menu + menu_size - 1;
 new_item->label = strdup(item_label);
 new_item->cfgdev = ((void *)0);
 new_item->kernel = ((void *)0);
 new_item->initrd = ((void *)0);
 new_item->append = malloc(512);
 strcpy(new_item->append, kept_cmdline);
 new_item->prio = 0;
 return new_item;
}

return_type: struct boot_item { char *label; char *cfgdev; char *kernel; char *initrd; char *append; int prio; } *


decompiled_code:
__int64 scan_boot_lvs()
{
unsigned int v0; // ebx
__int64 result; // rax
__int64 v2; // rax
const char *v3; // rax
char *v4; // rdi
char v5[4104]; // [rsp+0h] [rbp-1008h] BYREF

v0 = 0;
update_lv_lists();
while ( 1 )
{
result = lv_count();
if ( (int)result <= (int)v0 )
break;
v2 = lv_name(v0);
mount_lv(v2);
v3 = (const char *)lv_name(v0);
snprintf(v5, 0x1000uLL, "/mnt/%s/boot/boot.cfg", v3);
if ( (unsigned int)test_file(v5) )
{
v4 = (char *)lv_name(v0);
read_kb_file_from(v4);
}
++v0;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // ebx
__int64 result; // rax
__int64 v2; // rax
const char *v3; // rax
char *v4; // rdi
char v5[4104]; // [rsp+0h] [rbp-1008h] BYREF

v0 = 0;
update_lv_lists();
while ( 1 )
{
result = lv_count();
if ( (int)result <= (int)v0 )
break;
v2 = lv_name(v0);
mount_lv(v2);
v3 = (const char *)lv_name(v0);
snprintf(v5, 0x1000uLL, "/mnt/%s/boot/boot.cfg", v3);
if ( (unsigned int)test_file(v5) )
{
v4 = (char *)lv_name(v0);
func2(v4);
}
++v0;
}
return result;
}

original_code:
void scan_boot_lvs(void) {
 char filename[4096];
 update_lv_lists();
 for (int i = 0; i < lv_count(); ++i) {
  mount_lv(lv_name(i));
  snprintf(filename, sizeof(filename), "/mnt/%s/boot/boot.cfg", lv_name(i));
  if (test_file(filename)) read_kb_file_from(lv_name(i));
 }
}

canonical_original_code:
void scan_boot_lvs() {
 char filename[4096];
 update_lv_lists();
 for (int i = 0; i < lv_count(); ++i) {
  mount_lv(lv_name(i));
  snprintf(filename, sizeof(filename), "/mnt/%s/boot/boot.cfg", lv_name(i));
  if (test_file(filename)) read_kb_file_from(lv_name(i));
 }
}

variable_types:
filename
char [4096]


decompiled_code:
__int64 __fastcall boot_kexec(int a1)
{
char *v1; // rbx
const char *v3; // rsi
__int64 v4; // rcx
char *v5; // rdi
size_t v6; // rax
size_t v7; // rax
char v8[43]; // [rsp+0h] [rbp-418h] BYREF
char v9[1005]; // [rsp+2Bh] [rbp-3EDh] BYREF

v1 = (char *)menu + 48 * a1;
if ( *((_QWORD *)v1 + 2) )
{
mount_lv(*((_QWORD *)v1 + 1));
sysprintf("mount -o remount,ro %s", *((const char **)v1 + 1));
v3 = "kexec --load-hardboot --mem-min=0x42000000 ";
v4 = 11LL;
v5 = v8;
while ( v4 )
{
*(_DWORD *)v5 = *(_DWORD *)v3;
v3 += 4;
v5 += 4;
--v4;
}
if ( *((_QWORD *)v1 + 3) )
{
strcpy(v9, " --initrd='");
*(_WORD *)stpcpy(&v9[11], *((const char **)v1 + 3)) = 39;
}
if ( *((_QWORD *)v1 + 4) )
{
v6 = strlen(v8);
strcpy(&v8[v6], " --append='");
*(_WORD *)stpcpy(&v8[v6 + 11], *((const char **)v1 + 4)) = 39;
}
v7 = strlen(v8);
strcpy(&v8[v7], " '");
*(_WORD *)stpcpy(&v8[v7 + 2], *((const char **)v1 + 2)) = 39;
logprintf("0loading kexec kernel");
system_logged(v8);
umount_lv(*((_QWORD *)v1 + 1));
logprintf("0shutting down services");
do_shutdown();
logprintf("0booting kernel");
system_logged("kexec --exec");
logprintf("3kexec failed!");
exit(1);
}
return logprintf("2no kernel specified!");
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
char *v1; // rbx
const char *v3; // rsi
__int64 v4; // rcx
char *v5; // rdi
size_t v6; // rax
size_t v7; // rax
char v8[43]; // [rsp+0h] [rbp-418h] BYREF
char v9[1005]; // [rsp+2Bh] [rbp-3EDh] BYREF

v1 = (char *)menu + 48 * a1;
if ( *((_QWORD *)v1 + 2) )
{
mount_lv(*((_QWORD *)v1 + 1));
sysprintf("mount -o remount,ro %s", *((const char **)v1 + 1));
v3 = "kexec --load-hardboot --mem-min=0x42000000 ";
v4 = 11LL;
v5 = v8;
while ( v4 )
{
*(_DWORD *)v5 = *(_DWORD *)v3;
v3 += 4;
v5 += 4;
--v4;
}
if ( *((_QWORD *)v1 + 3) )
{
strcpy(v9, " --initrd='");
*(_WORD *)stpcpy(&v9[11], *((const char **)v1 + 3)) = 39;
}
if ( *((_QWORD *)v1 + 4) )
{
v6 = strlen(v8);
strcpy(&v8[v6], " --append='");
*(_WORD *)stpcpy(&v8[v6 + 11], *((const char **)v1 + 4)) = 39;
}
v7 = strlen(v8);
strcpy(&v8[v7], " '");
*(_WORD *)stpcpy(&v8[v7 + 2], *((const char **)v1 + 2)) = 39;
logprintf("0loading kexec kernel");
system_logged(v8);
umount_lv(*((_QWORD *)v1 + 1));
logprintf("0shutting down services");
do_shutdown();
logprintf("0booting kernel");
system_logged("kexec --exec");
logprintf("3kexec failed!");
exit(1);
}
return logprintf("2no kernel specified!");
}

original_code:
void boot_kexec(int entry_num) {
 char cmd[1024];
 int code;
 boot_item *entry = menu + entry_num;
 if (entry->kernel == ((void *)0)) {
  logprintf("2no kernel specified!");
  return;
 }
 mount_lv(entry->cfgdev);
 sysprintf("mount -o remount,ro %s", entry->cfgdev);
 strcpy(cmd, "kexec --load-hardboot --mem-min=0x42000000 ");
 if (entry->initrd != ((void *)0)) {
  strcat(cmd, " --initrd='");
  strcat(cmd, entry->initrd);
  strcat(cmd, "'");
 }
 if (entry->append != ((void *)0)) {
  strcat(cmd, " --append='");
  strcat(cmd, entry->append);
  strcat(cmd, "'");
 }
 strcat(cmd, " '");
 strcat(cmd, entry->kernel);
 strcat(cmd, "'");
 logprintf("0loading kexec kernel");
 system_logged(cmd);
 umount_lv(entry->cfgdev);
 logprintf("0shutting down services");
 do_shutdown();
 logprintf("0booting kernel");
 system_logged("kexec --exec");
 logprintf("3kexec failed!");
 exit(1);
}

canonical_original_code:
void boot_kexec(int entry_num) {
 char cmd[1024];
 int code;
 struct boot_item *entry = menu + entry_num;
 if (entry->kernel == ((void *)0)) {
  logprintf("2no kernel specified!");
  return;
 }
 mount_lv(entry->cfgdev);
 sysprintf("mount -o remount,ro %s", entry->cfgdev);
 strcpy(cmd, "kexec --load-hardboot --mem-min=0x42000000 ");
 if (entry->initrd != ((void *)0)) {
  strcat(cmd, " --initrd='");
  strcat(cmd, entry->initrd);
  strcat(cmd, "'");
 }
 if (entry->append != ((void *)0)) {
  strcat(cmd, " --append='");
  strcat(cmd, entry->append);
  strcat(cmd, "'");
 }
 strcat(cmd, " '");
 strcat(cmd, entry->kernel);
 strcat(cmd, "'");
 logprintf("0loading kexec kernel");
 system_logged(cmd);
 umount_lv(entry->cfgdev);
 logprintf("0shutting down services");
 do_shutdown();
 logprintf("0booting kernel");
 system_logged("kexec --exec");
 logprintf("3kexec failed!");
 exit(1);
}

variable_types:
cmd
char [1024]

user_defined_types: struct boot_item { char *label; char *cfgdev; char *kernel; char *initrd; char *append; int prio; }


original_code:
int nduid_to_serialno(char *nduid, char *serialno) {
 int nduid_len, i, j, k;
 char charset[] = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
 uint32_t val;
 int hval, l;
 nduid_len = strlen(nduid);
 if (nduid_len != 40) return -1;
 for (i = 0, k = 0, j = 0, val = 0; i < nduid_len; i++) {
  hval = hexval(nduid[i]);
  if (hval < 0) return -2;
  val |= ((unsigned)hval & 0xF) << (k * 4);
  k++;
  if (k == 5) {
   for (l = 0; l < 4; l++) {
    serialno[j++] = charset[(val & 0x1F)];
    val >>= 5;
   }
   k = 0;
   val = 0;
  }
 }
 serialno[j] = '\0';
 return 0;
}

canonical_original_code:
int nduid_to_serialno(char *nduid, char *serialno) {
 int nduid_len; int i; int j; int k;
 char charset[] = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
 unsigned int val;
 int hval; int l;
 nduid_len = strlen(nduid);
 if (nduid_len != 40) return -1;
 for (i = 0, k = 0, j = 0, val = 0; i < nduid_len; i++) {
  hval = hexval(nduid[i]);
  if (hval < 0) return -2;
  val |= ((unsigned int)hval & 0xF) << (k * 4);
  k++;
  if (k == 5) {
   for (l = 0; l < 4; l++) {
    serialno[j++] = charset[(val & 0x1F)];
    val >>= 5;
   }
   k = 0;
   val = 0;
  }
 }
 serialno[j] = '\0';
 return 0;
}

variable_types:
nduid
char *

variable_types:
serialno
char *

variable_types: j int

variable_types: k int

variable_types:
charset
char []

variable_types:
val
unsigned int

variable_types: hval int

variable_types: l int


decompiled_code:
char __fastcall check_keep_arg(char *src)
{
const char **v2; // rbx
const char *v3; // rbp
size_t v4; // rax
char *v5; // rbp
bool v6; // zf
size_t v7; // rax
char *v8; // rbx
char v10[104]; // [rsp+0h] [rbp-68h] BYREF

v2 = (const char **)&keepable_args;
do
{
while ( 1 )
{
v3 = *v2;
v4 = strlen(*v2);
if ( !strncmp(src, v3, v4) )
break;
if ( ++v2 == (const char **)(&keepable_args + 6) )
goto LABEL_5;
}
++v2;
strcat(kept_cmdline, src);
v5 = kept_cmdline;
*(_WORD *)&v5[strlen(kept_cmdline)] = 32;
}
while ( v2 != (const char **)(&keepable_args + 6) );
LABEL_5:
v6 = memcmp(src, "nduid=", 6uLL) == 0;
LOBYTE(v7) = !v6;
if ( v6 )
{
if ( (int)nduid_to_serialno(src + 6, (__int64)v10) < 0 )
{
LOBYTE(v7) = logprintf("1error generating android serialno");
}
else
{
strcat(kept_cmdline, v10);
v8 = kept_cmdline;
v7 = strlen(kept_cmdline);
*(_WORD *)&v8[v7] = 32;
}
}
return v7;
}

canonical_decompiled_code:
char __fastcall func6(char *src)
{
const char **v2; // rbx
const char *v3; // rbp
size_t v4; // rax
char *v5; // rbp
bool v6; // zf
size_t v7; // rax
char *v8; // rbx
char v10[104]; // [rsp+0h] [rbp-68h] BYREF

v2 = (const char **)&keepable_args;
do
{
while ( 1 )
{
v3 = *v2;
v4 = strlen(*v2);
if ( !strncmp(src, v3, v4) )
break;
if ( ++v2 == (const char **)(&keepable_args + 6) )
goto LABEL_5;
}
++v2;
strcat(kept_cmdline, src);
v5 = kept_cmdline;
*(_WORD *)&v5[strlen(kept_cmdline)] = 32;
}
while ( v2 != (const char **)(&keepable_args + 6) );
LABEL_5:
v6 = memcmp(src, "nduid=", 6uLL) == 0;
LOBYTE(v7) = !v6;
if ( v6 )
{
if ( (int)func5(src + 6, (__int64)v10) < 0 )
{
LOBYTE(v7) = logprintf("1error generating android serialno");
}
else
{
strcat(kept_cmdline, v10);
v8 = kept_cmdline;
v7 = strlen(kept_cmdline);
*(_WORD *)&v8[v7] = 32;
}
}
return v7;
}

original_code:
void check_keep_arg(char *arg) {
 char *nduid, serialno[68];
 for (int i = 0; i < (sizeof(keepable_args) / sizeof(*(keepable_args))); ++i) {
  const char *chk_arg = keepable_args[i];
  if (!strncmp(arg, chk_arg, strlen(chk_arg))) {
   strcat(kept_cmdline, arg);
   strcat(kept_cmdline, " ");
  }
 }
 if (!strncmp(arg, "nduid=", 6)) {
  nduid = arg + 6;
  if (nduid_to_serialno(nduid, serialno) < 0) {
   logprintf("1error generating android serialno");
   return;
  }
  strcat(kept_cmdline, serialno);
  strcat(kept_cmdline, " ");
 }
}

canonical_original_code:
void check_keep_arg(char *arg) {
 char *nduid; char serialno[68];
 for (int i = 0; i < (sizeof(keepable_args) / sizeof(*(keepable_args))); ++i) {
  char *chk_arg = keepable_args[i];
  if (!strncmp(arg, chk_arg, strlen(chk_arg))) {
   strcat(kept_cmdline, arg);
   strcat(kept_cmdline, " ");
  }
 }
 if (!strncmp(arg, "nduid=", 6)) {
  nduid = arg + 6;
  if (nduid_to_serialno(nduid, serialno) < 0) {
   logprintf("1error generating android serialno");
   return;
  }
  strcat(kept_cmdline, serialno);
  strcat(kept_cmdline, " ");
 }
}

variable_types:
arg
char *

variable_types:
serialno
char [68]


decompiled_code:
char *parse_proc_cmdline()
{
char *v0; // rax
int v1; // eax
int v2; // ebp
char *result; // rax
char *i; // rdi
int *v5; // rax
char *v6; // rax
char v7[520]; // [rsp+0h] [rbp-208h] BYREF

v0 = (char *)malloc(0x200uLL);
*v0 = 0;
kept_cmdline = v0;
v1 = open("/proc/cmdline", 0);
if ( v1 < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
result = (char *)logprintf("2%s: %s", "1error opening /proc/cmdline", v6);
}
else
{
v2 = v1;
v7[(int)read(v1, v7, 0x1FFuLL)] = 0;
close(v2);
result = strtok(v7, " ");
for ( i = result; result; i = result )
{
check_keep_arg(i);
result = strtok(0LL, " ");
}
}
return result;
}

canonical_decompiled_code:
char *func7()
{
char *v0; // rax
int v1; // eax
int v2; // ebp
char *result; // rax
char *i; // rdi
int *v5; // rax
char *v6; // rax
char v7[520]; // [rsp+0h] [rbp-208h] BYREF

v0 = (char *)malloc(0x200uLL);
*v0 = 0;
kept_cmdline = v0;
v1 = open("/proc/cmdline", 0);
if ( v1 < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
result = (char *)logprintf("2%s: %s", "1error opening /proc/cmdline", v6);
}
else
{
v2 = v1;
v7[(int)read(v1, v7, 0x1FFuLL)] = 0;
close(v2);
result = strtok(v7, " ");
for ( i = result; result; i = result )
{
func6(i);
result = strtok(0LL, " ");
}
}
return result;
}

original_code:
void parse_proc_cmdline(void) {
 int cmdline_fd;
 int nchars;
 char cmdline[512];
 char *cur_arg;
 kept_cmdline = malloc(512);
 kept_cmdline[0] = '\0';
 cmdline_fd = open("/proc/cmdline", 00);
 if (cmdline_fd < 0) {
  logprintf("2%s: %s", "1error opening /proc/cmdline", strerror((*__errno_location ())));
  return;
 }
 nchars = read(cmdline_fd, cmdline, 512 - 1);
 cmdline[nchars] = '\0';
 close(cmdline_fd);
 cur_arg = strtok(cmdline, " ");
 while (cur_arg != ((void *)0)) {
  check_keep_arg(cur_arg);
  cur_arg = strtok(((void *)0), " ");
 }
}

canonical_original_code:
void parse_proc_cmdline() {
 int cmdline_fd;
 int nchars;
 char cmdline[512];
 char *cur_arg;
 kept_cmdline = malloc(512);
 kept_cmdline[0] = '\0';
 cmdline_fd = open("/proc/cmdline", 00);
 if (cmdline_fd < 0) {
  logprintf("2%s: %s", "1error opening /proc/cmdline", strerror((*__errno_location ())));
  return;
 }
 nchars = read(cmdline_fd, cmdline, 512 - 1);
 cmdline[nchars] = '\0';
 close(cmdline_fd);
 cur_arg = strtok(cmdline, " ");
 while (cur_arg != ((void *)0)) {
  check_keep_arg(cur_arg);
  cur_arg = strtok(((void *)0), " ");
 }
}

variable_types: nchars int

variable_types:
cmdline
char [512]


hexval

decompiled_code:
__int64 __fastcall hexval(char a1)
{
__int64 result; // rax

if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned int)(char)(a1 - 48);
if ( (unsigned __int8)(a1 - 97) <= 5u )
return (unsigned int)(char)(a1 - 87);
result = (unsigned int)(char)(a1 - 55);
if ( (unsigned __int8)(a1 - 65) >= 6u )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1)
{
__int64 result; // rax

if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned int)(char)(a1 - 48);
if ( (unsigned __int8)(a1 - 97) <= 5u )
return (unsigned int)(char)(a1 - 87);
result = (unsigned int)(char)(a1 - 55);
if ( (unsigned __int8)(a1 - 65) >= 6u )
result = 0xFFFFFFFFLL;
return result;
}

variable_types: c char


decompiled_code:
_BOOL8 __fastcall test_file(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

return stat(a1, &v2) != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

return stat(a1, &v2) != -1;
}

original_code:
int test_file(const char *path) {
 struct stat test;
 if (stat(path, &test) == -1) return 0;
 return 1;
}

canonical_original_code:
int test_file(char *path) {
 struct stat test;
 if (stat(path, &test) == -1) return 0;
 return 1;
}

variable_types:
path
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
void __fastcall cp_file(char *file, char *a2)
{
void *v2; // rbp
int v3; // er12
int v4; // er13
size_t v5; // rax
size_t v6; // rbx
int *v7; // rax
char *v8; // rax
int *v9; // rax
const char *v10; // rsi
char *v11; // rdx
int *v12; // rax
char *v13; // rax
int *v14; // rax

if ( !test_file(file) )
{
logprintf("1file %s doesn't exist, so can't copy", file);
return;
}
v2 = malloc(0x10000uLL);
if ( !v2 )
{
v14 = _errno_location();
v10 = "2can't allocate buffer";
v11 = strerror(*v14);
goto LABEL_12;
}
v3 = open(file, 0);
if ( v3 < 0 )
{
v9 = _errno_location();
v10 = "2can't open source file";
v11 = strerror(*v9);
LABEL_12:
logprintf("2%s: %s", v10, v11);
return;
}
v4 = open(a2, 577);
if ( v4 >= 0 )
{
while ( 1 )
{
v5 = read(v3, v2, 0x10000uLL);
v6 = v5;
if ( v5 == -1LL )
break;
write(v4, v2, v5);
if ( v6 != 0x10000 )
goto LABEL_9;
}
v7 = _errno_location();
v8 = strerror(*v7);
logprintf("2%s: %s", "error reading from source file", v8);
LABEL_9:
close(v3);
close(v4);
free(v2);
}
else
{
v12 = _errno_location();
v13 = strerror(*v12);
logprintf("2%s: %s", "2can't open destination file", v13);
close(v3);
}
}

canonical_decompiled_code:
void __fastcall func5(char *file, char *a2)
{
void *v2; // rbp
int v3; // er12
int v4; // er13
size_t v5; // rax
size_t v6; // rbx
int *v7; // rax
char *v8; // rax
int *v9; // rax
const char *v10; // rsi
char *v11; // rdx
int *v12; // rax
char *v13; // rax
int *v14; // rax

if ( !func4(file) )
{
logprintf("1file %s doesn't exist, so can't copy", file);
return;
}
v2 = malloc(0x10000uLL);
if ( !v2 )
{
v14 = _errno_location();
v10 = "2can't allocate buffer";
v11 = strerror(*v14);
goto LABEL_12;
}
v3 = open(file, 0);
if ( v3 < 0 )
{
v9 = _errno_location();
v10 = "2can't open source file";
v11 = strerror(*v9);
LABEL_12:
logprintf("2%s: %s", v10, v11);
return;
}
v4 = open(a2, 577);
if ( v4 >= 0 )
{
while ( 1 )
{
v5 = read(v3, v2, 0x10000uLL);
v6 = v5;
if ( v5 == -1LL )
break;
write(v4, v2, v5);
if ( v6 != 0x10000 )
goto LABEL_9;
}
v7 = _errno_location();
v8 = strerror(*v7);
logprintf("2%s: %s", "error reading from source file", v8);
LABEL_9:
close(v3);
close(v4);
free(v2);
}
else
{
v12 = _errno_location();
v13 = strerror(*v12);
logprintf("2%s: %s", "2can't open destination file", v13);
close(v3);
}
}

original_code:
void cp_file(const char *src, const char *dest) {
 int src_fd, dest_fd;
 char *buf;
 size_t size;
 if (!test_file(src)) {
  logprintf("1file %s doesn't exist, so can't copy", src);
  return;
 }
 buf = malloc(65536);
 if (buf == ((void *)0)) {
  logprintf("2%s: %s", "2can't allocate buffer", strerror((*__errno_location ())));
  return;
 }
 src_fd = open(src, 00);
 if (src_fd < 0) {
  logprintf("2%s: %s", "2can't open source file", strerror((*__errno_location ())));
  return;
 }
 dest_fd = open(dest, 01|0100|01000);
 if (dest_fd < 0) {
  logprintf("2%s: %s", "2can't open destination file", strerror((*__errno_location ())));
  close(src_fd);
  return;
 }
 do {
  size = read(src_fd, buf, 65536);
  if (size == -1) {
   logprintf("2%s: %s", "error reading from source file", strerror((*__errno_location ())));
   break;
  }
  write(dest_fd, buf, size);
  if (size == -1) {
   logprintf("2%s: %s", "error writing to destination file", strerror((*__errno_location ())));
   break;
  }
 } while (size == 65536);
 close(src_fd);
 close(dest_fd);
 free(buf);
}

canonical_original_code:
void cp_file(char *src, char *dest) {
 int src_fd; int dest_fd;
 char *buf;
 unsigned long size;
 if (!test_file(src)) {
  logprintf("1file %s doesn't exist, so can't copy", src);
  return;
 }
 buf = malloc(65536);
 if (buf == ((void *)0)) {
  logprintf("2%s: %s", "2can't allocate buffer", strerror((*__errno_location ())));
  return;
 }
 src_fd = open(src, 00);
 if (src_fd < 0) {
  logprintf("2%s: %s", "2can't open source file", strerror((*__errno_location ())));
  return;
 }
 dest_fd = open(dest, 01|0100|01000);
 if (dest_fd < 0) {
  logprintf("2%s: %s", "2can't open destination file", strerror((*__errno_location ())));
  close(src_fd);
  return;
 }
 do {
  size = read(src_fd, buf, 65536);
  if (size == -1) {
   logprintf("2%s: %s", "error reading from source file", strerror((*__errno_location ())));
   break;
  }
  write(dest_fd, buf, size);
  if (size == -1) {
   logprintf("2%s: %s", "error writing to destination file", strerror((*__errno_location ())));
   break;
  }
 } while (size == 65536);
 close(src_fd);
 close(dest_fd);
 free(buf);
}

variable_types:
src
char *

variable_types:
dest
char *

variable_types:
buf
char *

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall system_logged(char *command)
{
char *v1; // rax
char *v2; // r12
int v3; // eax
__int64 v4; // rdx
__int64 result; // rax
char v6[4096]; // [rsp+0h] [rbp-2018h] BYREF
char s[4120]; // [rsp+1000h] [rbp-1018h] BYREF

if ( !command )
_assert_fail("cmd != NULL", "lib.c", 0xACu, "system_logged");
strncpy(v6, command, 0x1000uLL);
v6[4095] = 0;
v1 = strchr(v6, 32);
if ( v1 )
*v1 = 0;
v2 = basename(v6);
v3 = system(command);
v4 = v3 & 0x7F;
if ( (v3 & 0x7F) != 0 )
{
if ( (char)(v4 + 1) <= 1 )
{
result = logprintf("2something evil happened to command %s", v2);
}
else if ( (v3 & 0x80u) == 0 )
{
result = logprintf("2command %s died from signal %d (but no core was produced)", v2, v4);
}
else
{
logprintf("2command %s died from signal %d and dumped core\n", v2, v4);
snprintf(s, 0x1000uLL, "/var/core-%s", v2);
cp_file(s, "/mnt/media/nsboot/logs");
result = logprintf("0the core dump was copied to /mnt/media/nsboot/logs/core-%s", v2);
}
}
else
{
result = (unsigned int)(v3 >> 8);
if ( (_BYTE)result )
result = logprintf("2command %s died with code %d\n", v2, (unsigned __int8)result);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *command)
{
char *v1; // rax
char *v2; // r12
int v3; // eax
__int64 v4; // rdx
__int64 result; // rax
char v6[4096]; // [rsp+0h] [rbp-2018h] BYREF
char s[4120]; // [rsp+1000h] [rbp-1018h] BYREF

if ( !command )
_assert_fail("cmd != NULL", "lib.c", 0xACu, "system_logged");
strncpy(v6, command, 0x1000uLL);
v6[4095] = 0;
v1 = strchr(v6, 32);
if ( v1 )
*v1 = 0;
v2 = basename(v6);
v3 = system(command);
v4 = v3 & 0x7F;
if ( (v3 & 0x7F) != 0 )
{
if ( (char)(v4 + 1) <= 1 )
{
result = logprintf("2something evil happened to command %s", v2);
}
else if ( (v3 & 0x80u) == 0 )
{
result = logprintf("2command %s died from signal %d (but no core was produced)", v2, v4);
}
else
{
logprintf("2command %s died from signal %d and dumped core\n", v2, v4);
snprintf(s, 0x1000uLL, "/var/core-%s", v2);
func5(s, "/mnt/media/nsboot/logs");
result = logprintf("0the core dump was copied to /mnt/media/nsboot/logs/core-%s", v2);
}
}
else
{
result = (unsigned int)(v3 >> 8);
if ( (_BYTE)result )
result = logprintf("2command %s died with code %d\n", v2, (unsigned __int8)result);
}
return result;
}

original_code:
void system_logged(char *cmd) {
 pid_t code;
 uint8_t exit_status;
 int sig_num;
 char argv_zero[4096];
 char core_path[4096];
 char *exe_name;
 char *space;
 ((void) sizeof ((cmd != ((void *)0)) ? 1 : 0), __extension__ ({ if (cmd != ((void *)0)) ; else __assert_fail ("cmd != NULL", "lib.c", 172, __extension__ __PRETTY_FUNCTION__); }));
 strncpy(argv_zero, cmd, sizeof(argv_zero));
 argv_zero[4096 -1] = '\0';
 space = strchr(argv_zero, ' ');
 if (space != ((void *)0))
  *space = '\0';
 exe_name = basename(argv_zero);
 code = system(cmd);
 if ((((code) & 0x7f) == 0)) {
  exit_status = (((code) & 0xff00) >> 8);
  if (exit_status) {
   logprintf("2command %s died with code %d\n",
    exe_name, exit_status);
   return;
  }
 } else if ((((signed char) (((code) & 0x7f) + 1) >> 1) > 0)) {
  sig_num = ((code) & 0x7f);
  if (((code) & 0x80)) {
   logprintf("2command %s died from signal %d and dumped core\n",
    exe_name, sig_num);
   snprintf(core_path, sizeof(core_path), "/var/core-%s",
    exe_name);
   cp_file(core_path, "/mnt/media/nsboot/logs");
   logprintf("0the core dump was copied to /mnt/media/nsboot/logs/core-%s",
    exe_name);
   return;
  } else {
   logprintf("2command %s died from signal %d (but no core was produced)",
    exe_name, sig_num);
   return;
  }
 } else {
  logprintf("2something evil happened to command %s", exe_name);
 }
}

canonical_original_code:
void system_logged(char *cmd) {
 int code;
 unsigned char exit_status;
 int sig_num;
 char argv_zero[4096];
 char core_path[4096];
 char *exe_name;
 char *space;
 ((void) sizeof ((cmd != ((void *)0)) ? 1 : 0), __extension__ ({ if (cmd != ((void *)0)) ; else __assert_fail ("cmd != NULL", "lib.c", 172, __extension__ __PRETTY_FUNCTION__); }));
 strncpy(argv_zero, cmd, sizeof(argv_zero));
 argv_zero[4096 -1] = '\0';
 space = strchr(argv_zero, ' ');
 if (space != ((void *)0))
  *space = '\0';
 exe_name = basename(argv_zero);
 code = system(cmd);
 if ((((code) & 0x7f) == 0)) {
  exit_status = (((code) & 0xff00) >> 8);
  if (exit_status) {
   logprintf("2command %s died with code %d\n",
    exe_name, exit_status);
   return;
  }
 } else if ((((char) (((code) & 0x7f) + 1) >> 1) > 0)) {
  sig_num = ((code) & 0x7f);
  if (((code) & 0x80)) {
   logprintf("2command %s died from signal %d and dumped core\n",
    exe_name, sig_num);
   snprintf(core_path, sizeof(core_path), "/var/core-%s",
    exe_name);
   cp_file(core_path, "/mnt/media/nsboot/logs");
   logprintf("0the core dump was copied to /mnt/media/nsboot/logs/core-%s",
    exe_name);
   return;
  } else {
   logprintf("2command %s died from signal %d (but no core was produced)",
    exe_name, sig_num);
   return;
  }
 } else {
  logprintf("2something evil happened to command %s", exe_name);
 }
}

variable_types:
cmd
char *

variable_types: code int

variable_types:
space
char *


sysprintf

decompiled_code:
void sysprintf(char *format, ...)
{
size_t v1; // rbp
char *v2; // rax
char *v3; // r12
int *v4; // rax
char *v5; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
v1 = vsnprintf(0LL, 0LL, format, arg) + 1LL;
v2 = (char *)malloc(v1);
v3 = v2;
if ( v2 )
{
va_end(arg);
va_start(arg, format);
vsnprintf(v2, v1, format, arg);
system_logged(v3);
free(v3);
}
else
{
v4 = _errno_location();
v5 = strerror(*v4);
logprintf("2%s: %s", "command buffer allocation failed", v5);
}
}

canonical_decompiled_code:
void func7(char *format, ...)
{
size_t v1; // rbp
char *v2; // rax
char *v3; // r12
int *v4; // rax
char *v5; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
v1 = vsnprintf(0LL, 0LL, format, arg) + 1LL;
v2 = (char *)malloc(v1);
v3 = v2;
if ( v2 )
{
va_end(arg);
va_start(arg, format);
vsnprintf(v2, v1, format, arg);
func6(v3);
free(v3);
}
else
{
v4 = _errno_location();
v5 = strerror(*v4);
logprintf("2%s: %s", "command buffer allocation failed", v5);
}
}

original_code:
void sysprintf(const char *fmt, ...) {
 va_list args;
 char *buf;
 size_t size;
 __builtin_va_start(args,fmt);
 size = vsnprintf(((void *)0), 0, fmt, args);
 __builtin_va_end(args);
 buf = malloc(size + 1);
 if (buf == ((void *)0)) {
  logprintf("2%s: %s", "command buffer allocation failed", strerror((*__errno_location ())));
  return;
 }
 __builtin_va_start(args,fmt);
 vsnprintf(buf, size + 1, fmt, args);
 __builtin_va_end(args);
 system_logged(buf);
 free(buf);
}

canonical_original_code:
void sysprintf(char *fmt, ...) {
 __builtin_va_list args;
 char *buf;
 unsigned long size;
 __builtin_va_start(args,fmt);
 size = vsnprintf(((void *)0), 0, fmt, args);
 __builtin_va_end(args);
 buf = malloc(size + 1);
 if (buf == ((void *)0)) {
  logprintf("2%s: %s", "command buffer allocation failed", strerror((*__errno_location ())));
  return;
 }
 __builtin_va_start(args,fmt);
 vsnprintf(buf, size + 1, fmt, args);
 __builtin_va_end(args);
 system_logged(buf);
 free(buf);
}

variable_types:
fmt
char *


decompiled_code:
__int64 __fastcall wipe_lv_set(const char *a1)
{
char v2[4104]; // [rsp+0h] [rbp-1008h] BYREF

logprintf("0wiping volumes starting with %s", a1);
sprintf(v2, "%s-system", a1);
wipe_lv(v2);
sprintf(v2, "%s-data", a1);
wipe_lv(v2);
sprintf(v2, "%s-cache", a1);
return wipe_lv(v2);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
char v2[4104]; // [rsp+0h] [rbp-1008h] BYREF

logprintf("0wiping volumes starting with %s", a1);
sprintf(v2, "%s-system", a1);
wipe_lv(v2);
sprintf(v2, "%s-data", a1);
wipe_lv(v2);
sprintf(v2, "%s-cache", a1);
return wipe_lv(v2);
}

original_code:
void wipe_lv_set(const char *lv_set) {
 char lv[4096];
 logprintf("0wiping volumes starting with %s", lv_set);
 sprintf(lv, "%s-system", lv_set);
 wipe_lv(lv);
 sprintf(lv, "%s-data", lv_set);
 wipe_lv(lv);
 sprintf(lv, "%s-cache", lv_set);
 wipe_lv(lv);
}

canonical_original_code:
void wipe_lv_set(char *lv_set) {
 char lv[4096];
 logprintf("0wiping volumes starting with %s", lv_set);
 sprintf(lv, "%s-system", lv_set);
 wipe_lv(lv);
 sprintf(lv, "%s-data", lv_set);
 wipe_lv(lv);
 sprintf(lv, "%s-cache", lv_set);
 wipe_lv(lv);
}

variable_types:
lv
char [4096]


decompiled_code:
__int64 __fastcall umount_lv_set(const char *a1)
{
char v2[4104]; // [rsp+0h] [rbp-1008h] BYREF

logprintf("0unmounting volumes starting with %s", a1);
sprintf(v2, "%s-system", a1);
umount_lv(v2);
sprintf(v2, "%s-data", a1);
umount_lv(v2);
sprintf(v2, "%s-cache", a1);
return umount_lv(v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
char v2[4104]; // [rsp+0h] [rbp-1008h] BYREF

logprintf("0unmounting volumes starting with %s", a1);
sprintf(v2, "%s-system", a1);
umount_lv(v2);
sprintf(v2, "%s-data", a1);
umount_lv(v2);
sprintf(v2, "%s-cache", a1);
return umount_lv(v2);
}

original_code:
void umount_lv_set(const char *lv_set) {
 char lv[4096];
 logprintf("0unmounting volumes starting with %s", lv_set);
 sprintf(lv, "%s-system", lv_set);
 umount_lv(lv);
 sprintf(lv, "%s-data", lv_set);
 umount_lv(lv);
 sprintf(lv, "%s-cache", lv_set);
 umount_lv(lv);
}

canonical_original_code:
void umount_lv_set(char *lv_set) {
 char lv[4096];
 logprintf("0unmounting volumes starting with %s", lv_set);
 sprintf(lv, "%s-system", lv_set);
 umount_lv(lv);
 sprintf(lv, "%s-data", lv_set);
 umount_lv(lv);
 sprintf(lv, "%s-cache", lv_set);
 umount_lv(lv);
}