#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*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
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;
  unsigned long address2;
  unsigned char regular_check[8] = "ANDROID!";
  char boot_image[512], backup_image[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.1 beta\n\n");
  if (argc < 2 || argc > 5)
    arg_error = 1;
  else {
    if ((argc == 2 || argc == 3) &&
        (strcmp(argv[1], "-b") == 0 || strcmp(argv[1], "--backup") == 0)) {
      printf("Dumping boot image...\n");
      system("dump_image boot /tmp/original_boot.img");
      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");
        system("dump_image boot /tmp/original_boot.img");
        strcpy(boot_image, "/tmp/original_boot.img");
        delete_ind = -1;
      } 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)) {
        char command[512];
        printf("Flashing new image...\n");
        system("erase_image boot");
        strcpy(command, "flash_image boot ");
        strcat(command, 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");
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x630,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0xe42(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe3f(%rip),%rdi
call   1060 <printf@plt>
lea    0xe7a(%rip),%rdi
call   1060 <printf@plt>
lea    0xeb5(%rip),%rdi
call   1060 <printf@plt>
lea    0xef0(%rip),%rdi
call   1060 <printf@plt>
lea    0xf2b(%rip),%rdi
call   1060 <printf@plt>
lea    0xf66(%rip),%rdi
call   1060 <printf@plt>
lea    0xfa2(%rip),%rdi
call   1060 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
jl     122a <main+0x9a>
cmpl   $0x5,-0x8(%rbp)
jle    1236 <main+0xa6>
movl   $0x1,-0x14(%rbp)
jmp    154e <main+0x3be>
cmpl   $0x2,-0x8(%rbp)
je     124a <main+0xba>
cmpl   $0x3,-0x8(%rbp)
jne    1373 <main+0x1e3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xf6d(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1286 <main+0xf6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xf52(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1373 <main+0x1e3>
lea    0xf45(%rip),%rdi
call   1060 <printf@plt>
lea    0xf50(%rip),%rdi
call   1050 <system@plt>
lea    -0x230(%rbp),%rdi
lea    0xf4d(%rip),%rsi
call   1040 <strcpy@plt>
cmpl   $0x2,-0x8(%rbp)
jne    12d3 <main+0x143>
lea    -0x430(%rbp),%rdi
lea    0xf47(%rip),%rsi
call   1040 <strcpy@plt>
jmp    12e7 <main+0x157>
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1040 <strcpy@plt>
lea    -0x230(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
lea    -0x28(%rbp),%r8
call   1030 <scan_file_for_data@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1327 <main+0x197>
lea    0xf14(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15e3 <main+0x453>
lea    -0x230(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10b0 <find_gzip_recovery_ramdisk@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1350 <main+0x1c0>
movl   $0x1,-0x4(%rbp)
jmp    15e3 <main+0x453>
lea    -0x230(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x430(%rbp),%rdx
call   1080 <backup_recovery_ramdisk@plt>
movl   $0x0,-0x4(%rbp)
jmp    15e3 <main+0x453>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xee5(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     13af <main+0x21f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xeca(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    13e6 <main+0x256>
lea    0xe1c(%rip),%rdi
call   1060 <printf@plt>
lea    0xe27(%rip),%rdi
call   1050 <system@plt>
lea    -0x230(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0xffffffff,-0x18(%rbp)
jmp    13fa <main+0x26a>
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
lea    -0x230(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
lea    -0x28(%rbp),%r8
call   1030 <scan_file_for_data@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     143a <main+0x2aa>
lea    0xe01(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15e3 <main+0x453>
lea    -0x230(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10b0 <find_gzip_recovery_ramdisk@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1463 <main+0x2d3>
movl   $0x1,-0x4(%rbp)
jmp    15e3 <main+0x453>
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rcx
call   1090 <write_new_ramdisk@plt>
cmpl   $0x0,-0x18(%rbp)
je     14a5 <main+0x315>
lea    0xddd(%rip),%rdi
call   1060 <printf@plt>
lea    0xdf9(%rip),%rdi
call   1050 <system@plt>
cmpl   $0x5,-0x8(%rbp)
jne    1542 <main+0x3b2>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xdf7(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     14eb <main+0x35b>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xddc(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1542 <main+0x3b2>
lea    0xdce(%rip),%rdi
call   1060 <printf@plt>
lea    0xdd9(%rip),%rdi
call   1050 <system@plt>
lea    -0x630(%rbp),%rdi
lea    0xdd7(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x630(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   10a0 <strcat@plt>
lea    -0x630(%rbp),%rdi
call   1050 <system@plt>
lea    0xdbd(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    15e3 <main+0x453>
cmpl   $0x0,-0x14(%rbp)
je     15dc <main+0x44c>
lea    0xdac(%rip),%rdi
call   1060 <printf@plt>
lea    0xdbd(%rip),%rdi
call   1060 <printf@plt>
lea    0xdba(%rip),%rdi
call   1060 <printf@plt>
lea    0xde7(%rip),%rdi
call   1060 <printf@plt>
lea    0xe0e(%rip),%rdi
call   1060 <printf@plt>
lea    0xe20(%rip),%rdi
call   1060 <printf@plt>
lea    0xe55(%rip),%rdi
call   1060 <printf@plt>
lea    0xe8a(%rip),%rdi
call   1060 <printf@plt>
lea    0xebb(%rip),%rdi
call   1060 <printf@plt>
lea    0xeea(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    15e3 <main+0x453>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x630,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
movabs $0x2144494f52444e41,%rax
49 44 21
mov    %rax,0x8(%rsp)
lea    0xee9(%rip),%rdi
call   1050 <puts@plt>
lea    0xf23(%rip),%rdi
call   1050 <puts@plt>
lea    0xf5d(%rip),%rdi
call   1050 <puts@plt>
lea    0xf97(%rip),%rdi
call   1050 <puts@plt>
lea    0xfd1(%rip),%rdi
call   1050 <puts@plt>
lea    0x100b(%rip),%rdi
call   1050 <puts@plt>
lea    0x1046(%rip),%rdi
call   1050 <puts@plt>
lea    -0x6(%rbx),%eax
cmp    $0xfffffffc,%eax
jae    128c <main+0xfc>
lea    0x10e3(%rip),%rdi
call   1050 <puts@plt>
lea    0x10f3(%rip),%rdi
call   1050 <puts@plt>
lea    0x10ef(%rip),%rdi
call   1050 <puts@plt>
lea    0x111b(%rip),%rdi
call   1050 <puts@plt>
lea    0x1141(%rip),%rdi
call   1050 <puts@plt>
lea    0x1152(%rip),%rdi
call   1050 <puts@plt>
lea    0x1186(%rip),%rdi
call   1050 <puts@plt>
lea    0x11ba(%rip),%rdi
call   1050 <puts@plt>
lea    0x11ea(%rip),%rdi
call   1050 <puts@plt>
lea    0x1218(%rip),%rdi
call   1050 <puts@plt>
xor    %ebp,%ebp
jmp    1491 <main+0x301>
mov    %ebx,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    12c8 <main+0x138>
mov    0x8(%r14),%rdi
lea    0xd5f(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     141b <main+0x28b>
mov    0x8(%r14),%rdi
lea    0xd49(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     141b <main+0x28b>
mov    0x8(%r14),%rdi
lea    0xd7a(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12fb <main+0x16b>
mov    0x8(%r14),%rdi
lea    0xd68(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12fb <main+0x16b>
mov    0x8(%r14),%rsi
mov    $0x1,%r15b
jmp    131d <main+0x18d>
lea    0xfa3(%rip),%rdi
call   1050 <puts@plt>
lea    0xcfe(%rip),%rdi
call   1060 <system@plt>
lea    0xd02(%rip),%rsi
xor    %r15d,%r15d
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <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    1480 <main+0x2f0>
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
call   10b0 <find_gzip_recovery_ramdisk@plt>
test   %eax,%eax
js     148c <main+0x2fc>
mov    (%rsp),%rdx
mov    0x10(%r14),%rsi
mov    0x18(%r14),%rcx
lea    0x10(%rsp),%rdi
call   1090 <write_new_ramdisk@plt>
test   %r15b,%r15b
jne    1391 <main+0x201>
lea    0xefe(%rip),%rdi
call   1050 <puts@plt>
lea    0xccb(%rip),%rdi
call   1060 <system@plt>
xor    %ebp,%ebp
cmp    $0x5,%ebx
jne    1491 <main+0x301>
mov    0x20(%r14),%rdi
lea    0xccc(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     13ca <main+0x23a>
mov    0x20(%r14),%rdi
lea    0xcba(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1491 <main+0x301>
lea    0xe87(%rip),%rdi
call   1050 <puts@plt>
lea    0xca1(%rip),%rdi
call   1060 <system@plt>
lea    0xca6(%rip),%rsi
lea    0x210(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    0x18(%r14),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
lea    0xe5a(%rip),%rdi
call   1050 <puts@plt>
jmp    1491 <main+0x301>
lea    0xe83(%rip),%rdi
call   1050 <puts@plt>
lea    0xbde(%rip),%rdi
call   1060 <system@plt>
lea    0xbe2(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1040 <strcpy@plt>
cmp    $0x2,%ebx
jne    1452 <main+0x2c2>
lea    0xbe3(%rip),%rsi
jmp    1456 <main+0x2c6>
mov    0x10(%r14),%rsi
lea    0x210(%rsp),%rdi
call   1040 <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     14a1 <main+0x311>
lea    0xe34(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
call   10b0 <find_gzip_recovery_ramdisk@plt>
test   %eax,%eax
js     148c <main+0x2fc>
mov    (%rsp),%rsi
lea    0x10(%rsp),%rdi
lea    0x210(%rsp),%rdx
call   1080 <backup_recovery_ramdisk@plt>
jmp    1285 <main+0xf5>

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.1 beta\0A\0A\00"
@.str.7 = [3 x i8] c"-b\00"
@.str.8 = [9 x i8] c"--backup\00"
@.str.9 = [23 x i8] c"Dumping boot image...\0A\00"
@.str.10 = [39 x i8] c"dump_image boot /tmp/original_boot.img\00"
@.str.11 = [23 x i8] c"/tmp/original_boot.img\00"
@.str.12 = [26 x i8] c"/tmp/recovery_ramdisk.img\00"
@.str.13 = [61 x i8] c"This is not a properly formatted Samsung boot image!\0AFailed\0A\00"
@.str.14 = [3 x i8] c"-d\00"
@.str.15 = [7 x i8] c"--dump\00"
@.str.16 = [40 x i8] c"Deleting dumped boot image from /cache\0A\00"
@.str.17 = [28 x i8] c"rm /cache/original_boot.img\00"
@.str.18 = [3 x i8] c"-f\00"
@.str.19 = [8 x i8] c"--flash\00"
@.str.20 = [23 x i8] c"Flashing new image...\0A\00"
@.str.21 = [17 x i8] c"erase_image boot\00"
@.str.22 = [18 x i8] c"flash_image boot \00"
@.str.23 = [17 x i8] c"Flash complete.\0A\00"
@.str.24 = [29 x i8] c"Invalid arguments supplied.\0A\00"
@.str.25 = [9 x i8] c"Usage:\0A\0A\00"
@.str.26 = [57 x i8] c"Backup existing recovery ramdisk (requires dump_image):\0A\00"
@.str.27 = [51 x i8] c"injecttwrp --backup [optionalbackuplocation.img]\0A\0A\00"
@.str.28 = [30 x i8] c"Inject new recovery ramdisk:\0A\00"
@.str.29 = [65 x i8] c"injecttwrp originalboot.img ramdisk-recovery.img outputboot.img\0A\00"
@.str.30 = [65 x i8] c"injecttwrp --dump ramdisk-recovery.img outputboot.img [--flash]\0A\00"
@.str.31 = [61 x i8] c"--dump will use dump_image to dump your existing boot image\0A\00"
@.str.32 = [59 x i8] c"--flash will use flash_image to flash the new boot image\0A\0A\00"
@.str.33 = [75 x i8] c"NOTE: dump_image, erase_image, and flash_image must already be installed!\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 i64
%10 = alloca [8 x i8]
%11 = alloca [512 x i8]
%12 = alloca [512 x i8]
%13 = 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
%14 = bitcast [8 x i8]* %10 to i8*
%15 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.5, i64 0, i64 0))
%21 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 2
br i1 %23, label %27, label %24
24: ; preds = %2
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 5
br i1 %26, label %27, label %28
27: ; preds = %24, %2
store i32 1, i32* %6
br label %162
28: ; preds = %24
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 2
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 3
br i1 %33, label %34, label %81
34: ; preds = %31, %28
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %46, label %40
40: ; preds = %34
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %81
46: ; preds = %40, %34
%47 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%48 = call i32 @system(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.10, i64 0, i64 0))
%49 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%50 = call i32 @strcpy(i8* %49, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0))
%51 = load i32, i32* %4
%52 = icmp eq i32 %51, 2
br i1 %52, label %53, label %56
53: ; preds = %46
%54 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%55 = call i32 @strcpy(i8* %54, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0))
br label %62
56: ; preds = %46
%57 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 2
%60 = load i8*, i8** %59
%61 = call i32 @strcpy(i8* %57, i8* %60)
br label %62
62: ; preds = %56, %53
%63 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%64 = bitcast [8 x i8]* %10 to i8**
%65 = call i32 @scan_file_for_data(i8* %63, i8** %64, i32 8, i32 0, i64* %9)
store i32 %65, i32* %8
%66 = load i32, i32* %8
%67 = icmp sge i32 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %62
%69 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.13, i64 0, i64 0))
store i32 1, i32* %3
br label %177
70: ; preds = %62
%71 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%72 = call i32 @find_gzip_recovery_ramdisk(i8* %71, i64* %9)
store i32 %72, i32* %8
%73 = load i32, i32* %8
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %70
store i32 1, i32* %3
br label %177
76: ; preds = %70
%77 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%78 = load i64, i64* %9
%79 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%80 = call i32 @backup_recovery_ramdisk(i8* %77, i64 %78, i8* %79)
store i32 0, i32* %3
br label %177
81: ; preds = %40, %31
%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 ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0))
%86 = icmp eq i64 %85, 0
br i1 %86, label %93, label %87
87: ; preds = %81
%88 = load i8**, i8*** %5
%89 = getelementptr inbounds i8*, i8** %88, i64 1
%90 = load i8*, i8** %89
%91 = call i64 @strcmp(i8* %90, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0))
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %98
93: ; preds = %87, %81
%94 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%95 = call i32 @system(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.10, i64 0, i64 0))
%96 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%97 = call i32 @strcpy(i8* %96, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0))
store i32 -1, i32* %7
br label %104
98: ; preds = %87
%99 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%100 = load i8**, i8*** %5
%101 = getelementptr inbounds i8*, i8** %100, i64 1
%102 = load i8*, i8** %101
%103 = call i32 @strcpy(i8* %99, i8* %102)
br label %104
104: ; preds = %98, %93
%105 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%106 = bitcast [8 x i8]* %10 to i8**
%107 = call i32 @scan_file_for_data(i8* %105, i8** %106, i32 8, i32 0, i64* %9)
store i32 %107, i32* %8
%108 = load i32, i32* %8
%109 = icmp sge i32 %108, 0
br i1 %109, label %110, label %112
110: ; preds = %104
%111 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.13, i64 0, i64 0))
store i32 1, i32* %3
br label %177
112: ; preds = %104
%113 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%114 = call i32 @find_gzip_recovery_ramdisk(i8* %113, i64* %9)
store i32 %114, i32* %8
%115 = load i32, i32* %8
%116 = icmp slt i32 %115, 0
br i1 %116, label %117, label %118
117: ; preds = %112
store i32 1, i32* %3
br label %177
118: ; preds = %112
%119 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%120 = load i8**, i8*** %5
%121 = getelementptr inbounds i8*, i8** %120, i64 2
%122 = load i8*, i8** %121
%123 = load i64, i64* %9
%124 = load i8**, i8*** %5
%125 = getelementptr inbounds i8*, i8** %124, i64 3
%126 = load i8*, i8** %125
%127 = call i32 @write_new_ramdisk(i8* %119, i8* %122, i64 %123, i8* %126)
%128 = load i32, i32* %7
%129 = icmp ne i32 %128, 0
br i1 %129, label %130, label %133
130: ; preds = %118
%131 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.16, i64 0, i64 0))
%132 = call i32 @system(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.17, i64 0, i64 0))
br label %133
133: ; preds = %130, %118
%134 = load i32, i32* %4
%135 = icmp eq i32 %134, 5
br i1 %135, label %136, label %161
136: ; preds = %133
%137 = load i8**, i8*** %5
%138 = getelementptr inbounds i8*, i8** %137, i64 4
%139 = load i8*, i8** %138
%140 = call i64 @strcmp(i8* %139, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.18, i64 0, i64 0))
%141 = icmp eq i64 %140, 0
br i1 %141, label %148, label %142
142: ; preds = %136
%143 = load i8**, i8*** %5
%144 = getelementptr inbounds i8*, i8** %143, i64 4
%145 = load i8*, i8** %144
%146 = call i64 @strcmp(i8* %145, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.19, i64 0, i64 0))
%147 = icmp eq i64 %146, 0
br i1 %147, label %148, label %161
148: ; preds = %142, %136
%149 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.20, i64 0, i64 0))
%150 = call i32 @system(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.21, i64 0, i64 0))
%151 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%152 = call i32 @strcpy(i8* %151, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.22, i64 0, i64 0))
%153 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%154 = load i8**, i8*** %5
%155 = getelementptr inbounds i8*, i8** %154, i64 3
%156 = load i8*, i8** %155
%157 = call i32 @strcat(i8* %153, i8* %156)
%158 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%159 = call i32 @system(i8* %158)
%160 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.23, i64 0, i64 0))
br label %161
161: ; preds = %148, %142, %133
store i32 0, i32* %3
br label %177
162: ; preds = %27
%163 = load i32, i32* %6
%164 = icmp ne i32 %163, 0
br i1 %164, label %165, label %176
165: ; preds = %162
%166 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.24, i64 0, i64 0))
%167 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.25, i64 0, i64 0))
%168 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.26, i64 0, i64 0))
%169 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.27, i64 0, i64 0))
%170 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.28, i64 0, i64 0))
%171 = call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.29, i64 0, i64 0))
%172 = call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.30, i64 0, i64 0))
%173 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.31, i64 0, i64 0))
%174 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.32, i64 0, i64 0))
%175 = call i32 @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.33, i64 0, i64 0))
store i32 0, i32* %3
br label %177
176: ; preds = %162
store i32 0, i32* %3
br label %177
177: ; preds = %176, %165, %161, %117, %110, %76, %75, %68
%178 = load i32, i32* %3
ret i32 %178
}

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