#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ backup_recovery_ramdisk(char *, unsigned long, char *);
int find_gzip_recovery_ramdisk(char *, unsigned long *);
int /*<<< orphan*/ printf(char *);
int scan_file_for_data(char *, unsigned char **, int, int /*<<< orphan*/,
                       unsigned long *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ write_new_ramdisk(char *, char *, unsigned long, char *);
int main(int argc, char **argv) {
  int arg_error = 0, delete_ind = 0, return_val, index, len;
  unsigned long address2;
  unsigned char regular_check[8] = "ANDROID!";
  char boot_image[512], backup_image[512], boot_block_device[512], command[512];
  printf("-- InjectTWRP Recovery Ramdisk Injection Tool for Samsung devices. "
         "--\n");
  printf("--                  by Dees_Troy and Team Win                      "
         "--\n");
  printf("--                       http://teamw.in                           "
         "--\n");
  printf("--                Bringing some win to Samsung!                    "
         "--\n");
  printf("--        This tool comes with no warranties whatsoever!           "
         "--\n");
  printf("--        Use at your own risk and always keep a backup!           "
         "--\n\n");
  printf("Version 0.2 beta\n\n");
  if (argc < 2 || argc > 6)
    arg_error = 1;
  else {
    strcpy(boot_block_device, "boot");
    for (index = 1; index < argc; index++) {
      len = strlen(argv[index]);
      if (len > 3 && strncmp(argv[index], "bd=", 3) == 0) {
        strcpy(boot_block_device, argv[index] + 3);
        index = argc;
      }
    }
    if ((argc >= 2 && argc <= 4) &&
        (strcmp(argv[1], "-b") == 0 || strcmp(argv[1], "--backup") == 0)) {
      printf("Dumping boot image...\n");
      sprintf(command, "dump_image %s /tmp/original_boot.img",
              boot_block_device);
      system(command);
      strcpy(boot_image, "/tmp/original_boot.img");
      if (argc == 2)
        strcpy(backup_image, "/tmp/recovery_ramdisk.img");
      else
        strcpy(backup_image, argv[2]);
      return_val =
          scan_file_for_data(boot_image, &regular_check, 8, 0, &address2);
      if (return_val >= 0) {
        printf(
            "This is not a properly formatted Samsung boot image!\nFailed\n");
        return 1;
      }
      return_val = find_gzip_recovery_ramdisk(boot_image, &address2);
      if (return_val < 0) {
        return 1;
      }
      backup_recovery_ramdisk(boot_image, address2, backup_image);
      return 0;
    } else {
      if (strcmp(argv[1], "-d") == 0 || strcmp(argv[1], "--dump") == 0) {
        printf("Dumping boot image...\n");
        sprintf(command, "dump_image %s /tmp/original_boot.img",
                boot_block_device);
        system(command);
        strcpy(boot_image, "/tmp/original_boot.img");
      } else
        strcpy(boot_image, argv[1]);
      return_val =
          scan_file_for_data(boot_image, &regular_check, 8, 0, &address2);
      if (return_val >= 0) {
        printf(
            "This is not a properly formatted Samsung boot image!\nFailed\n");
        return 1;
      }
      return_val = find_gzip_recovery_ramdisk(boot_image, &address2);
      if (return_val < 0) {
        return 1;
      }
      write_new_ramdisk(boot_image, argv[2], address2, argv[3]);
      if (delete_ind) {
        printf("Deleting dumped boot image from /cache\n");
        system("rm /cache/original_boot.img");
      }
      if (argc >= 5 &&
          (strcmp(argv[4], "-f") == 0 || strcmp(argv[4], "--flash") == 0)) {
        printf("Flashing new image...\n");
        sprintf(command, "erase_image %s", boot_block_device);
        system(command);
        sprintf(command, "flash_image %s %s", boot_block_device, argv[3]);
        system(command);
        printf("Flash complete.\n");
      }
      return 0;
    }
  }
  if (arg_error) {
    printf("Invalid arguments supplied.\n");
    printf("Usage:\n\n");
    printf("Backup existing recovery ramdisk (requires dump_image):\n");
    printf("injecttwrp --backup [optionalbackuplocation.img]\n\n");
    printf("Inject new recovery ramdisk:\n");
    printf("injecttwrp originalboot.img ramdisk-recovery.img outputboot.img\n");
    printf("injecttwrp --dump ramdisk-recovery.img outputboot.img [--flash]\n");
    printf("--dump will use dump_image to dump your existing boot image\n");
    printf("--flash will use flash_image to flash the new boot image\n\n");
    printf("NOTE: dump_image, erase_image, and flash_image must already be "
           "installed!\n\n");
    printf("If needed you can add bd=/dev/block/mmcblk0p5 to indicate the "
           "location\n");
    printf("of the boot partition on emmc devices as the final parameter.\n");
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0xe22(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe1f(%rip),%rdi
call   1080 <printf@plt>
lea    0xe5a(%rip),%rdi
call   1080 <printf@plt>
lea    0xe95(%rip),%rdi
call   1080 <printf@plt>
lea    0xed0(%rip),%rdi
call   1080 <printf@plt>
lea    0xf0b(%rip),%rdi
call   1080 <printf@plt>
lea    0xf46(%rip),%rdi
call   1080 <printf@plt>
lea    0xf82(%rip),%rdi
call   1080 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
jl     124a <main+0x9a>
cmpl   $0x6,-0x8(%rbp)
jle    1256 <main+0xa6>
movl   $0x1,-0x14(%rbp)
jmp    1658 <main+0x4a8>
lea    -0x640(%rbp),%rdi
lea    0xf62(%rip),%rsi
call   1050 <strcpy@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12f6 <main+0x146>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jle    12e3 <main+0x133>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xf1e(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12e3 <main+0x133>
lea    -0x640(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
add    $0x3,%rsi
call   1050 <strcpy@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    12e8 <main+0x138>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1270 <main+0xc0>
cmpl   $0x2,-0x8(%rbp)
jl     144f <main+0x29f>
cmpl   $0x4,-0x8(%rbp)
jg     144f <main+0x29f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xeb6(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1346 <main+0x196>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe9b(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    144f <main+0x29f>
lea    0xe8e(%rip),%rdi
call   1080 <printf@plt>
lea    -0x840(%rbp),%rdi
lea    -0x640(%rbp),%rdx
lea    0xe8b(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
lea    -0x840(%rbp),%rdi
call   1070 <system@plt>
lea    -0x240(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1050 <strcpy@plt>
cmpl   $0x2,-0x8(%rbp)
jne    13af <main+0x1ff>
lea    -0x440(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1050 <strcpy@plt>
jmp    13c3 <main+0x213>
lea    -0x440(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1050 <strcpy@plt>
lea    -0x240(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
lea    -0x30(%rbp),%r8
call   1030 <scan_file_for_data@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1403 <main+0x253>
lea    0xe3f(%rip),%rdi
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1705 <main+0x555>
lea    -0x240(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   10d0 <find_gzip_recovery_ramdisk@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    142c <main+0x27c>
movl   $0x1,-0x4(%rbp)
jmp    1705 <main+0x555>
lea    -0x240(%rbp),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x440(%rbp),%rdx
call   10a0 <backup_recovery_ramdisk@plt>
movl   $0x0,-0x4(%rbp)
jmp    1705 <main+0x555>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe10(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     148b <main+0x2db>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf5(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    14d7 <main+0x327>
lea    0xd49(%rip),%rdi
call   1080 <printf@plt>
lea    -0x840(%rbp),%rdi
lea    -0x640(%rbp),%rdx
lea    0xd46(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
lea    -0x840(%rbp),%rdi
call   1070 <system@plt>
lea    -0x240(%rbp),%rdi
lea    0xd33(%rip),%rsi
call   1050 <strcpy@plt>
jmp    14eb <main+0x33b>
lea    -0x240(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1050 <strcpy@plt>
lea    -0x240(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
lea    -0x30(%rbp),%r8
call   1030 <scan_file_for_data@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     152b <main+0x37b>
lea    0xd17(%rip),%rdi
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1705 <main+0x555>
lea    -0x240(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   10d0 <find_gzip_recovery_ramdisk@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1554 <main+0x3a4>
movl   $0x1,-0x4(%rbp)
jmp    1705 <main+0x555>
lea    -0x240(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rcx
call   10b0 <write_new_ramdisk@plt>
cmpl   $0x0,-0x18(%rbp)
je     1596 <main+0x3e6>
lea    0xcf3(%rip),%rdi
call   1080 <printf@plt>
lea    0xd0f(%rip),%rdi
call   1070 <system@plt>
cmpl   $0x5,-0x8(%rbp)
jl     164c <main+0x49c>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xd0d(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     15dc <main+0x42c>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xcf2(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    164c <main+0x49c>
lea    0xce4(%rip),%rdi
call   1080 <printf@plt>
lea    -0x840(%rbp),%rdi
lea    -0x640(%rbp),%rdx
lea    0xce1(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
lea    -0x840(%rbp),%rdi
call   1070 <system@plt>
lea    -0x840(%rbp),%rdi
lea    -0x640(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rcx
lea    0xcc0(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
lea    -0x840(%rbp),%rdi
call   1070 <system@plt>
lea    0xcb8(%rip),%rdi
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1705 <main+0x555>
cmpl   $0x0,-0x14(%rbp)
je     16fe <main+0x54e>
lea    0xca7(%rip),%rdi
call   1080 <printf@plt>
lea    0xcb8(%rip),%rdi
call   1080 <printf@plt>
lea    0xcb5(%rip),%rdi
call   1080 <printf@plt>
lea    0xce2(%rip),%rdi
call   1080 <printf@plt>
lea    0xd09(%rip),%rdi
call   1080 <printf@plt>
lea    0xd1b(%rip),%rdi
call   1080 <printf@plt>
lea    0xd50(%rip),%rdi
call   1080 <printf@plt>
lea    0xd85(%rip),%rdi
call   1080 <printf@plt>
lea    0xdb6(%rip),%rdi
call   1080 <printf@plt>
lea    0xde5(%rip),%rdi
call   1080 <printf@plt>
lea    0xe25(%rip),%rdi
call   1080 <printf@plt>
lea    0xe61(%rip),%rdi
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1705 <main+0x555>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rsi,%r13
mov    %edi,%r14d
movabs $0x2144494f52444e41,%rax
49 44 21
mov    %rax,0x8(%rsp)
lea    0xead(%rip),%rdi
call   1060 <puts@plt>
lea    0xee7(%rip),%rdi
call   1060 <puts@plt>
lea    0xf21(%rip),%rdi
call   1060 <puts@plt>
lea    0xf5b(%rip),%rdi
call   1060 <puts@plt>
lea    0xf95(%rip),%rdi
call   1060 <puts@plt>
lea    0xfcf(%rip),%rdi
call   1060 <puts@plt>
lea    0x100a(%rip),%rdi
call   1060 <puts@plt>
lea    -0x7(%r14),%eax
cmp    $0xfffffffb,%eax
jae    12ce <main+0x11e>
lea    0x107b(%rip),%rdi
call   1060 <puts@plt>
lea    0x108b(%rip),%rdi
call   1060 <puts@plt>
lea    0x1087(%rip),%rdi
call   1060 <puts@plt>
lea    0x10b3(%rip),%rdi
call   1060 <puts@plt>
lea    0x10d9(%rip),%rdi
call   1060 <puts@plt>
lea    0x10ea(%rip),%rdi
call   1060 <puts@plt>
lea    0x111e(%rip),%rdi
call   1060 <puts@plt>
lea    0x1152(%rip),%rdi
call   1060 <puts@plt>
lea    0x1182(%rip),%rdi
call   1060 <puts@plt>
lea    0x11b0(%rip),%rdi
call   1060 <puts@plt>
lea    0x11ef(%rip),%rdi
call   1060 <puts@plt>
lea    0x122a(%rip),%rdi
call   1060 <puts@plt>
xor    %ebp,%ebp
jmp    157b <main+0x3cb>
lea    0xd2b(%rip),%rsi
lea    0x210(%rsp),%r15
mov    %r15,%rdi
call   1050 <strcpy@plt>
mov    $0x1,%ebp
lea    0xd14(%rip),%r12
jmp    1308 <main+0x158>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebp
cmp    %r14d,%ebp
jge    1347 <main+0x197>
movslq %ebp,%rbx
mov    0x0(%r13,%rbx,8),%rdi
call   1070 <strlen@plt>
cmp    $0x4,%eax
jl     1300 <main+0x150>
mov    0x0(%r13,%rbx,8),%rdi
mov    %r12,%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1300 <main+0x150>
mov    0x0(%r13,%rbx,8),%rsi
add    $0x3,%rsi
mov    %r15,%rdi
call   1050 <strcpy@plt>
mov    %r14d,%ebp
jmp    1300 <main+0x150>
cmp    $0x4,%r14d
jg     137f <main+0x1cf>
mov    0x8(%r13),%rdi
lea    0xcb1(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     14e7 <main+0x337>
mov    0x8(%r13),%rdi
lea    0xc9b(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     14e7 <main+0x337>
mov    0x8(%r13),%rdi
lea    0xcca(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     13af <main+0x1ff>
mov    0x8(%r13),%rdi
lea    0xcb8(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     13af <main+0x1ff>
mov    0x8(%r13),%rsi
jmp    13eb <main+0x23b>
lea    0xeb1(%rip),%rdi
call   1060 <puts@plt>
lea    0xc53(%rip),%rsi
lea    0x410(%rsp),%rbp
lea    0x210(%rsp),%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   10c0 <sprintf@plt>
mov    %rbp,%rdi
call   1080 <system@plt>
lea    0xc38(%rip),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strcpy@plt>
lea    0x8(%rsp),%rsi
mov    %rsp,%r8
mov    %rbp,%rdi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1030 <scan_file_for_data@plt>
test   %eax,%eax
jns    156a <main+0x3ba>
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
call   10d0 <find_gzip_recovery_ramdisk@plt>
test   %eax,%eax
js     1576 <main+0x3c6>
mov    (%rsp),%rdx
mov    0x10(%r13),%rsi
mov    0x18(%r13),%rcx
lea    0x10(%rsp),%rdi
call   10b0 <write_new_ramdisk@plt>
xor    %ebp,%ebp
cmp    $0x5,%r14d
jl     157b <main+0x3cb>
mov    0x20(%r13),%rdi
lea    0xc05(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     147c <main+0x2cc>
mov    0x20(%r13),%rdi
lea    0xbf3(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    157b <main+0x3cb>
lea    0xdbe(%rip),%rdi
call   1060 <puts@plt>
lea    0xbda(%rip),%rsi
xor    %ebp,%ebp
lea    0x410(%rsp),%r14
lea    0x210(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   10c0 <sprintf@plt>
mov    %r14,%rdi
call   1080 <system@plt>
mov    0x18(%r13),%rcx
lea    0xbb7(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   10c0 <sprintf@plt>
mov    %r14,%rdi
call   1080 <system@plt>
lea    0xd7a(%rip),%rdi
call   1060 <puts@plt>
jmp    157b <main+0x3cb>
lea    0xd79(%rip),%rdi
call   1060 <puts@plt>
lea    0xb1b(%rip),%rsi
lea    0x410(%rsp),%rbp
lea    0x210(%rsp),%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   10c0 <sprintf@plt>
mov    %rbp,%rdi
call   1080 <system@plt>
lea    0xb00(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1050 <strcpy@plt>
cmp    $0x2,%r14d
jne    153c <main+0x38c>
lea    0xb00(%rip),%rsi
jmp    1540 <main+0x390>
mov    0x10(%r13),%rsi
lea    0x610(%rsp),%rdi
call   1050 <strcpy@plt>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %rsp,%r8
mov    $0x8,%edx
xor    %ecx,%ecx
call   1030 <scan_file_for_data@plt>
test   %eax,%eax
js     158f <main+0x3df>
lea    0xd0c(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
call   10d0 <find_gzip_recovery_ramdisk@plt>
test   %eax,%eax
js     1576 <main+0x3c6>
mov    (%rsp),%rsi
lea    0x10(%rsp),%rdi
lea    0x610(%rsp),%rdx
call   10a0 <backup_recovery_ramdisk@plt>
jmp    12c7 <main+0x117>

LLVM IR (-O0):
@__const.main.regular_check = [8 x i8] c"ANDROID!"
@.str = [71 x i8] c"-- InjectTWRP Recovery Ramdisk Injection Tool for Samsung devices. --\0A\00"
@.str.1 = [71 x i8] c"-- by Dees_Troy and Team Win --\0A\00"
@.str.2 = [71 x i8] c"-- http://teamw.in --\0A\00"
@.str.3 = [71 x i8] c"-- Bringing some win to Samsung! --\0A\00"
@.str.4 = [71 x i8] c"-- This tool comes with no warranties whatsoever! --\0A\00"
@.str.5 = [72 x i8] c"-- Use at your own risk and always keep a backup! --\0A\0A\00"
@.str.6 = [19 x i8] c"Version 0.2 beta\0A\0A\00"
@.str.7 = [5 x i8] c"boot\00"
@.str.8 = [4 x i8] c"bd=\00"
@.str.9 = [3 x i8] c"-b\00"
@.str.10 = [9 x i8] c"--backup\00"
@.str.11 = [23 x i8] c"Dumping boot image...\0A\00"
@.str.12 = [37 x i8] c"dump_image %s /tmp/original_boot.img\00"
@.str.13 = [23 x i8] c"/tmp/original_boot.img\00"
@.str.14 = [26 x i8] c"/tmp/recovery_ramdisk.img\00"
@.str.15 = [61 x i8] c"This is not a properly formatted Samsung boot image!\0AFailed\0A\00"
@.str.16 = [3 x i8] c"-d\00"
@.str.17 = [7 x i8] c"--dump\00"
@.str.18 = [40 x i8] c"Deleting dumped boot image from /cache\0A\00"
@.str.19 = [28 x i8] c"rm /cache/original_boot.img\00"
@.str.20 = [3 x i8] c"-f\00"
@.str.21 = [8 x i8] c"--flash\00"
@.str.22 = [23 x i8] c"Flashing new image...\0A\00"
@.str.23 = [15 x i8] c"erase_image %s\00"
@.str.24 = [18 x i8] c"flash_image %s %s\00"
@.str.25 = [17 x i8] c"Flash complete.\0A\00"
@.str.26 = [29 x i8] c"Invalid arguments supplied.\0A\00"
@.str.27 = [9 x i8] c"Usage:\0A\0A\00"
@.str.28 = [57 x i8] c"Backup existing recovery ramdisk (requires dump_image):\0A\00"
@.str.29 = [51 x i8] c"injecttwrp --backup [optionalbackuplocation.img]\0A\0A\00"
@.str.30 = [30 x i8] c"Inject new recovery ramdisk:\0A\00"
@.str.31 = [65 x i8] c"injecttwrp originalboot.img ramdisk-recovery.img outputboot.img\0A\00"
@.str.32 = [65 x i8] c"injecttwrp --dump ramdisk-recovery.img outputboot.img [--flash]\0A\00"
@.str.33 = [61 x i8] c"--dump will use dump_image to dump your existing boot image\0A\00"
@.str.34 = [59 x i8] c"--flash will use flash_image to flash the new boot image\0A\0A\00"
@.str.35 = [76 x i8] c"NOTE: dump_image, erase_image, and flash_image must already be installed!\0A\0A\00"
@.str.36 = [72 x i8] c"If needed you can add bd=/dev/block/mmcblk0p5 to indicate the location\0A\00"
@.str.37 = [63 x i8] c"of the boot partition on emmc devices as the final parameter.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca [8 x i8]
%13 = alloca [512 x i8]
%14 = alloca [512 x i8]
%15 = alloca [512 x i8]
%16 = alloca [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
%17 = bitcast [8 x i8]* %12 to i8*
%18 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.5, i64 0, i64 0))
%24 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 2
br i1 %26, label %30, label %27
27: ; preds = %2
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 6
br i1 %29, label %30, label %31
30: ; preds = %27, %2
store i32 1, i32* %6
br label %214
31: ; preds = %27
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%33 = call i32 @strcpy(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %9
br label %34
34: ; preds = %66, %31
%35 = load i32, i32* %9
%36 = load i32, i32* %4
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %69
38: ; preds = %34
%39 = load i8**, i8*** %5
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = call i32 @strlen(i8* %43)
store i32 %44, i32* %10
%45 = load i32, i32* %10
%46 = icmp sgt i32 %45, 3
br i1 %46, label %47, label %65
47: ; preds = %38
%48 = load i8**, i8*** %5
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = call i64 @strncmp(i8* %52, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 3)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %65
55: ; preds = %47
%56 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%57 = load i8**, i8*** %5
%58 = load i32, i32* %9
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
%61 = load i8*, i8** %60
%62 = getelementptr inbounds i8, i8* %61, i64 3
%63 = call i32 @strcpy(i8* %56, i8* %62)
%64 = load i32, i32* %4
store i32 %64, i32* %9
br label %65
65: ; preds = %55, %47, %38
br label %66
66: ; preds = %65
%67 = load i32, i32* %9
%68 = add nsw i32 %67, 1
store i32 %68, i32* %9
br label %34
69: ; preds = %34
%70 = load i32, i32* %4
%71 = icmp sge i32 %70, 2
br i1 %71, label %72, label %126
72: ; preds = %69
%73 = load i32, i32* %4
%74 = icmp sle i32 %73, 4
br i1 %74, label %75, label %126
75: ; preds = %72
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 1
%78 = load i8*, i8** %77
%79 = call i64 @strcmp(i8* %78, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%80 = icmp eq i64 %79, 0
br i1 %80, label %87, label %81
81: ; preds = %75
%82 = load i8**, i8*** %5
%83 = getelementptr inbounds i8*, i8** %82, i64 1
%84 = load i8*, i8** %83
%85 = call i64 @strcmp(i8* %84, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
%86 = icmp eq i64 %85, 0
br i1 %86, label %87, label %126
87: ; preds = %81, %75
%88 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0))
%89 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%90 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%91 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %89, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.12, i64 0, i64 0), i8* %90)
%92 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%93 = call i32 @system(i8* %92)
%94 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%95 = call i32 @strcpy(i8* %94, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0))
%96 = load i32, i32* %4
%97 = icmp eq i32 %96, 2
br i1 %97, label %98, label %101
98: ; preds = %87
%99 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%100 = call i32 @strcpy(i8* %99, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.14, i64 0, i64 0))
br label %107
101: ; preds = %87
%102 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%103 = load i8**, i8*** %5
%104 = getelementptr inbounds i8*, i8** %103, i64 2
%105 = load i8*, i8** %104
%106 = call i32 @strcpy(i8* %102, i8* %105)
br label %107
107: ; preds = %101, %98
%108 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%109 = bitcast [8 x i8]* %12 to i8**
%110 = call i32 @scan_file_for_data(i8* %108, i8** %109, i32 8, i32 0, i64* %11)
store i32 %110, i32* %8
%111 = load i32, i32* %8
%112 = icmp sge i32 %111, 0
br i1 %112, label %113, label %115
113: ; preds = %107
%114 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.15, i64 0, i64 0))
store i32 1, i32* %3
br label %231
115: ; preds = %107
%116 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%117 = call i32 @find_gzip_recovery_ramdisk(i8* %116, i64* %11)
store i32 %117, i32* %8
%118 = load i32, i32* %8
%119 = icmp slt i32 %118, 0
br i1 %119, label %120, label %121
120: ; preds = %115
store i32 1, i32* %3
br label %231
121: ; preds = %115
%122 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%123 = load i64, i64* %11
%124 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%125 = call i32 @backup_recovery_ramdisk(i8* %122, i64 %123, i8* %124)
store i32 0, i32* %3
br label %231
126: ; preds = %81, %72, %69
%127 = load i8**, i8*** %5
%128 = getelementptr inbounds i8*, i8** %127, i64 1
%129 = load i8*, i8** %128
%130 = call i64 @strcmp(i8* %129, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0))
%131 = icmp eq i64 %130, 0
br i1 %131, label %138, label %132
132: ; preds = %126
%133 = load i8**, i8*** %5
%134 = getelementptr inbounds i8*, i8** %133, i64 1
%135 = load i8*, i8** %134
%136 = call i64 @strcmp(i8* %135, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.17, i64 0, i64 0))
%137 = icmp eq i64 %136, 0
br i1 %137, label %138, label %147
138: ; preds = %132, %126
%139 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0))
%140 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%141 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%142 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %140, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.12, i64 0, i64 0), i8* %141)
%143 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%144 = call i32 @system(i8* %143)
%145 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%146 = call i32 @strcpy(i8* %145, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0))
br label %153
147: ; preds = %132
%148 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%149 = load i8**, i8*** %5
%150 = getelementptr inbounds i8*, i8** %149, i64 1
%151 = load i8*, i8** %150
%152 = call i32 @strcpy(i8* %148, i8* %151)
br label %153
153: ; preds = %147, %138
%154 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%155 = bitcast [8 x i8]* %12 to i8**
%156 = call i32 @scan_file_for_data(i8* %154, i8** %155, i32 8, i32 0, i64* %11)
store i32 %156, i32* %8
%157 = load i32, i32* %8
%158 = icmp sge i32 %157, 0
br i1 %158, label %159, label %161
159: ; preds = %153
%160 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.15, i64 0, i64 0))
store i32 1, i32* %3
br label %231
161: ; preds = %153
%162 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%163 = call i32 @find_gzip_recovery_ramdisk(i8* %162, i64* %11)
store i32 %163, i32* %8
%164 = load i32, i32* %8
%165 = icmp slt i32 %164, 0
br i1 %165, label %166, label %167
166: ; preds = %161
store i32 1, i32* %3
br label %231
167: ; preds = %161
%168 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%169 = load i8**, i8*** %5
%170 = getelementptr inbounds i8*, i8** %169, i64 2
%171 = load i8*, i8** %170
%172 = load i64, i64* %11
%173 = load i8**, i8*** %5
%174 = getelementptr inbounds i8*, i8** %173, i64 3
%175 = load i8*, i8** %174
%176 = call i32 @write_new_ramdisk(i8* %168, i8* %171, i64 %172, i8* %175)
%177 = load i32, i32* %7
%178 = icmp ne i32 %177, 0
br i1 %178, label %179, label %182
179: ; preds = %167
%180 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.18, i64 0, i64 0))
%181 = call i32 @system(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.19, i64 0, i64 0))
br label %182
182: ; preds = %179, %167
%183 = load i32, i32* %4
%184 = icmp sge i32 %183, 5
br i1 %184, label %185, label %213
185: ; preds = %182
%186 = load i8**, i8*** %5
%187 = getelementptr inbounds i8*, i8** %186, i64 4
%188 = load i8*, i8** %187
%189 = call i64 @strcmp(i8* %188, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.20, i64 0, i64 0))
%190 = icmp eq i64 %189, 0
br i1 %190, label %197, label %191
191: ; preds = %185
%192 = load i8**, i8*** %5
%193 = getelementptr inbounds i8*, i8** %192, i64 4
%194 = load i8*, i8** %193
%195 = call i64 @strcmp(i8* %194, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.21, i64 0, i64 0))
%196 = icmp eq i64 %195, 0
br i1 %196, label %197, label %213
197: ; preds = %191, %185
%198 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.22, i64 0, i64 0))
%199 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%200 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%201 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %199, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.23, i64 0, i64 0), i8* %200)
%202 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%203 = call i32 @system(i8* %202)
%204 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%205 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%206 = load i8**, i8*** %5
%207 = getelementptr inbounds i8*, i8** %206, i64 3
%208 = load i8*, i8** %207
%209 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %204, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.24, i64 0, i64 0), i8* %205, i8* %208)
%210 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%211 = call i32 @system(i8* %210)
%212 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.25, i64 0, i64 0))
br label %213
213: ; preds = %197, %191, %182
store i32 0, i32* %3
br label %231
214: ; preds = %30
%215 = load i32, i32* %6
%216 = icmp ne i32 %215, 0
br i1 %216, label %217, label %230
217: ; preds = %214
%218 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.26, i64 0, i64 0))
%219 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.27, i64 0, i64 0))
%220 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.28, i64 0, i64 0))
%221 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.29, i64 0, i64 0))
%222 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.30, i64 0, i64 0))
%223 = call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.31, i64 0, i64 0))
%224 = call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.32, i64 0, i64 0))
%225 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.33, i64 0, i64 0))
%226 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.34, i64 0, i64 0))
%227 = call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.35, i64 0, i64 0))
%228 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.36, i64 0, i64 0))
%229 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.37, i64 0, i64 0))
store i32 0, i32* %3
br label %231
230: ; preds = %214
store i32 0, i32* %3
br label %231
231: ; preds = %230, %217, %213, %166, %159, %121, %120, %113
%232 = load i32, i32* %3
ret i32 %232
}

LLVM IR (-O2):
@.str.7 = [5 x i8] c"boot\00"
@.str.8 = [4 x i8] c"bd=\00"
@.str.9 = [3 x i8] c"-b\00"
@.str.10 = [9 x i8] c"--backup\00"
@.str.12 = [37 x i8] c"dump_image %s /tmp/original_boot.img\00"
@.str.13 = [23 x i8] c"/tmp/original_boot.img\00"
@.str.14 = [26 x i8] c"/tmp/recovery_ramdisk.img\00"
@.str.16 = [3 x i8] c"-d\00"
@.str.17 = [7 x i8] c"--dump\00"
@.str.20 = [3 x i8] c"-f\00"
@.str.21 = [8 x i8] c"--flash\00"
@.str.23 = [15 x i8] c"erase_image %s\00"
@.str.24 = [18 x i8] c"flash_image %s %s\00"
@str = [70 x i8] c"-- InjectTWRP Recovery Ramdisk Injection Tool for Samsung devices. --\00"
@str.38 = [70 x i8] c"-- by Dees_Troy and Team Win --\00"
@str.39 = [70 x i8] c"-- http://teamw.in --\00"
@str.40 = [70 x i8] c"-- Bringing some win to Samsung! --\00"
@str.41 = [70 x i8] c"-- This tool comes with no warranties whatsoever! --\00"
@str.42 = [71 x i8] c"-- Use at your own risk and always keep a backup! --\0A\00"
@str.43 = [18 x i8] c"Version 0.2 beta\0A\00"
@str.44 = [22 x i8] c"Flashing new image...\00"
@str.45 = [16 x i8] c"Flash complete.\00"
@str.48 = [22 x i8] c"Dumping boot image...\00"
@str.49 = [60 x i8] c"This is not a properly formatted Samsung boot image!\0AFailed\00"
@str.50 = [28 x i8] c"Invalid arguments supplied.\00"
@str.51 = [8 x i8] c"Usage:\0A\00"
@str.52 = [56 x i8] c"Backup existing recovery ramdisk (requires dump_image):\00"
@str.53 = [50 x i8] c"injecttwrp --backup [optionalbackuplocation.img]\0A\00"
@str.54 = [29 x i8] c"Inject new recovery ramdisk:\00"
@str.55 = [64 x i8] c"injecttwrp originalboot.img ramdisk-recovery.img outputboot.img\00"
@str.56 = [64 x i8] c"injecttwrp --dump ramdisk-recovery.img outputboot.img [--flash]\00"
@str.57 = [60 x i8] c"--dump will use dump_image to dump your existing boot image\00"
@str.58 = [58 x i8] c"--flash will use flash_image to flash the new boot image\0A\00"
@str.59 = [75 x i8] c"NOTE: dump_image, erase_image, and flash_image must already be installed!\0A\00"
@str.60 = [71 x i8] c"If needed you can add bd=/dev/block/mmcblk0p5 to indicate the location\00"
@str.61 = [62 x i8] c"of the boot partition on emmc devices as the final parameter.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca [512 x i8]
%6 = alloca [512 x i8]
%7 = alloca [512 x i8]
%8 = alloca [512 x i8]
%9 = bitcast i64* %3 to i8*
%10 = bitcast i64* %4 to i8*
store i64 2397121506699398721, i64* %4
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.38, i64 0, i64 0))
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.39, i64 0, i64 0))
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.40, i64 0, i64 0))
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.41, i64 0, i64 0))
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str.42, i64 0, i64 0))
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.43, i64 0, i64 0))
%22 = add i32 %0, -7
%23 = icmp ult i32 %22, -5
br i1 %23, label %130, label %24
24: ; preds = %2
%25 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %26
26: ; preds = %24, %41
%27 = phi i32 [ %43, %41 ], [ 1, %24 ]
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %1, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 @strlen(i8* %30)
%32 = icmp sgt i32 %31, 3
br i1 %32, label %33, label %41
33: ; preds = %26
%34 = load i8*, i8** %29
%35 = call i64 @strncmp(i8* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 3)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i8*, i8** %29
%39 = getelementptr inbounds i8, i8* %38, i64 3
%40 = call i32 @strcpy(i8* %13, i8* %39)
br label %41
41: ; preds = %26, %33, %37
%42 = phi i32 [ %0, %37 ], [ %27, %33 ], [ %27, %26 ]
%43 = add nsw i32 %42, 1
%44 = icmp slt i32 %43, %0
br i1 %44, label %26, label %45
45: ; preds = %41
%46 = icmp slt i32 %0, 5
br i1 %46, label %47, label %79
47: ; preds = %45
%48 = getelementptr inbounds i8*, i8** %1, i64 1
%49 = load i8*, i8** %48
%50 = call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %56, label %52
52: ; preds = %47
%53 = load i8*, i8** %48
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %79
56: ; preds = %52, %47
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.48, i64 0, i64 0))
%58 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.12, i64 0, i64 0), i8* %13)
%59 = call i32 @system(i8* %14)
%60 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0))
%61 = icmp eq i32 %0, 2
br i1 %61, label %65, label %62
62: ; preds = %56
%63 = getelementptr inbounds i8*, i8** %1, i64 2
%64 = load i8*, i8** %63
br label %65
65: ; preds = %56, %62
%66 = phi i8* [ %64, %62 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.14, i64 0, i64 0), %56 ]
%67 = call i32 @strcpy(i8* %12, i8* %66)
%68 = bitcast i64* %4 to i8**
%69 = call i32 @scan_file_for_data(i8* %11, i8** %68, i32 8, i32 0, i64* %3)
%70 = icmp sgt i32 %69, -1
br i1 %70, label %71, label %73
71: ; preds = %65
%72 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.49, i64 0, i64 0))
br label %143
73: ; preds = %65
%74 = call i32 @find_gzip_recovery_ramdisk(i8* %11, i64* %3)
%75 = icmp slt i32 %74, 0
br i1 %75, label %143, label %76
76: ; preds = %73
%77 = load i64, i64* %3
%78 = call i32 @backup_recovery_ramdisk(i8* %11, i64 %77, i8* %12)
br label %143
79: ; preds = %52, %45
%80 = getelementptr inbounds i8*, i8** %1, i64 1
%81 = load i8*, i8** %80
%82 = call i64 @strcmp(i8* %81, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0))
%83 = icmp eq i64 %82, 0
br i1 %83, label %88, label %84
84: ; preds = %79
%85 = load i8*, i8** %80
%86 = call i64 @strcmp(i8* %85, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.17, i64 0, i64 0))
%87 = icmp eq i64 %86, 0
br i1 %87, label %88, label %92
88: ; preds = %84, %79
%89 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.48, i64 0, i64 0))
%90 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.12, i64 0, i64 0), i8* %13)
%91 = call i32 @system(i8* %14)
br label %94
92: ; preds = %84
%93 = load i8*, i8** %80
br label %94
94: ; preds = %92, %88
%95 = phi i8* [ %93, %92 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0), %88 ]
%96 = call i32 @strcpy(i8* %11, i8* %95)
%97 = bitcast i64* %4 to i8**
%98 = call i32 @scan_file_for_data(i8* %11, i8** %97, i32 8, i32 0, i64* %3)
%99 = icmp sgt i32 %98, -1
br i1 %99, label %100, label %102
100: ; preds = %94
%101 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.49, i64 0, i64 0))
br label %143
102: ; preds = %94
%103 = call i32 @find_gzip_recovery_ramdisk(i8* %11, i64* %3)
%104 = icmp slt i32 %103, 0
br i1 %104, label %143, label %105
105: ; preds = %102
%106 = getelementptr inbounds i8*, i8** %1, i64 2
%107 = load i8*, i8** %106
%108 = load i64, i64* %3
%109 = getelementptr inbounds i8*, i8** %1, i64 3
%110 = load i8*, i8** %109
%111 = call i32 @write_new_ramdisk(i8* %11, i8* %107, i64 %108, i8* %110)
%112 = icmp sgt i32 %0, 4
br i1 %112, label %113, label %143
113: ; preds = %105
%114 = getelementptr inbounds i8*, i8** %1, i64 4
%115 = load i8*, i8** %114
%116 = call i64 @strcmp(i8* %115, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.20, i64 0, i64 0))
%117 = icmp eq i64 %116, 0
br i1 %117, label %122, label %118
118: ; preds = %113
%119 = load i8*, i8** %114
%120 = call i64 @strcmp(i8* %119, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.21, i64 0, i64 0))
%121 = icmp eq i64 %120, 0
br i1 %121, label %122, label %143
122: ; preds = %118, %113
%123 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.44, i64 0, i64 0))
%124 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.23, i64 0, i64 0), i8* %13)
%125 = call i32 @system(i8* %14)
%126 = load i8*, i8** %109
%127 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.24, i64 0, i64 0), i8* %13, i8* %126)
%128 = call i32 @system(i8* %14)
%129 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.45, i64 0, i64 0))
br label %143
130: ; preds = %2
%131 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.50, i64 0, i64 0))
%132 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.51, i64 0, i64 0))
%133 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.52, i64 0, i64 0))
%134 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.53, i64 0, i64 0))
%135 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.54, i64 0, i64 0))
%136 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.55, i64 0, i64 0))
%137 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.56, i64 0, i64 0))
%138 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.57, i64 0, i64 0))
%139 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.58, i64 0, i64 0))
%140 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @str.59, i64 0, i64 0))
%141 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str.60, i64 0, i64 0))
%142 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str.61, i64 0, i64 0))
br label %143
143: ; preds = %105, %118, %122, %102, %73, %130, %100, %76, %71
%144 = phi i32 [ 0, %130 ], [ 1, %71 ], [ 0, %76 ], [ 1, %100 ], [ 1, %73 ], [ 1, %102 ], [ 0, %122 ], [ 0, %118 ], [ 0, %105 ]
ret i32 %144
}