#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*/ O_RDWR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ android_product_name_get(char *);
int check_bootloader_status();
scalar_t__ check_for_aboot_partition();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ *strstr(char *, char *);
int /*<<< orphan*/ write(int, char **, int);
int main(int argc, char *argv[]) {
  if (argv[1] == NULL) {
    fprintf(stderr, "Amazon FireTV Bootloader Unlock OpenSource Tool\n");
    fprintf(stderr, "By: rhcp011235\n");
    fprintf(stderr, "Usage: %s unlock|lock|check\n", argv[0]);
    exit(1);
  }
  char product_name[256];
  android_product_name_get(product_name);
  if (strstr(product_name, "51.1.0.0") != NULL)
    fprintf(stderr,
            "You can unlock your bootloder without downgrade. Congrats\n");
  if (strstr(product_name, "51.1.0.1") != NULL)
    fprintf(stderr,
            "You can unlock your bootloder without downgrade. Congrats\n");
  if (strstr(product_name, "51.1.0.2") != NULL)
    fprintf(stderr,
            "You can unlock your bootloder without downgrade. Congrats\n");
  if (strstr(product_name, "51.1.1.0") != NULL) {
    fprintf(stderr, "You need to downgrade to 51.1.0.2\n");
    exit(1);
  }
  if (strstr(product_name, "51.1.2.0") != NULL) {
    fprintf(stderr, "No Root Or Downgrade SORRY!\n");
    exit(1);
  }
  if (strstr(product_name, "51.1.3.0") != NULL) {
    fprintf(stderr, "No Root Or Downgrade SORRY!\n");
    exit(1);
  }
  if (strstr(product_name, "51.1.4.0") != NULL) {
    fprintf(stderr, "No Root Or Downgrade SORRY!\n");
    exit(1);
  }
  if (strstr(product_name, "51.1.4.1") != NULL) {
    fprintf(stderr, "No Root Or Downgrade SORRY!\n");
    exit(1);
  }
  if (strstr(product_name, "51.1.4.2") != NULL) {
    fprintf(stderr, "No Root Or Downgrade SORRY!\n");
    exit(1);
  }
  if (check_for_aboot_partition() == 0) {
    printf("No aboot partition is detected!\n");
    exit(1);
  }
  if (strcmp(argv[1], "check") == 0) {
    if (check_bootloader_status() == 0)
      printf("You have a locked bootloader\n");
    else if (check_bootloader_status() == 1)
      printf("You have an unlocked bootloader\n");
    else
      printf("Unknown error occured\n");
    exit(1);
  }
  if (strcmp(argv[1], "unlock") == 0 || strcmp(argv[1], "lock") == 0) {
    int file = open("/dev/block/platform/msm_sdcc.1/by-name/aboot", O_RDWR);
    char buffer[17];
    lseek(file, -512, SEEK_END);
    if (strcmp(argv[1], "unlock") == 0) {
      write(file, &"ANDROID-BOOT!\0\0\0\1\0\0\0",
            sizeof("ANDROID-BOOT!\0\0\0\1\0\0\0"));
    }
    if (strcmp(argv[1], "lock") == 0) {
      write(file, &"ANDROID-BOOT!\0\0\0\0\0\0\0",
            sizeof("ANDROID-BOOT!\0\0\0\0\0\0\0"));
    }
    if (check_bootloader_status() == 0) {
      printf("You have a locked bootloader\n");
    } else if (check_bootloader_status() == 1) {
      printf("You have a partially unlocked bootloader now\n");
    } else {
      printf("Unknown error occured\n");
    }
  } else {
    printf("An invalid argument was provided\n");
  }
  exit(1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    122e <main+0x7e>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x110(%rbp),%rdi
call   1070 <android_product_name_get@plt>
lea    -0x110(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     126e <main+0xbe>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     12a2 <main+0xf2>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     12d6 <main+0x126>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
lea    0xd98(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xdd0(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     1314 <main+0x164>
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x110(%rbp),%rdi
lea    0xdbe(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     1352 <main+0x1a2>
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
lea    0xda8(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x110(%rbp),%rdi
lea    0xda6(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     1390 <main+0x1e0>
mov    0x2c5a(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x110(%rbp),%rdi
lea    0xd71(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     13ce <main+0x21e>
mov    0x2c1c(%rip),%rax
mov    (%rax),%edi
lea    0xd2c(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x110(%rbp),%rdi
lea    0xd3c(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     140c <main+0x25c>
mov    0x2bde(%rip),%rax
mov    (%rax),%edi
lea    0xcee(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x110(%rbp),%rdi
lea    0xd07(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     144a <main+0x29a>
mov    0x2ba0(%rip),%rax
mov    (%rax),%edi
lea    0xcb0(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    $0x0,%al
call   10a0 <check_for_aboot_partition@plt>
cmp    $0x0,%rax
jne    1471 <main+0x2c1>
lea    0xcc8(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xccb(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    14ec <main+0x33c>
mov    $0x0,%al
call   1030 <check_bootloader_status@plt>
cmp    $0x0,%eax
jne    14b0 <main+0x300>
lea    0xcab(%rip),%rdi
call   1050 <printf@plt>
jmp    14e2 <main+0x332>
mov    $0x0,%al
call   1030 <check_bootloader_status@plt>
cmp    $0x1,%eax
jne    14d1 <main+0x321>
lea    0xca8(%rip),%rdi
call   1050 <printf@plt>
jmp    14dd <main+0x32d>
lea    0xcb8(%rip),%rdi
call   1050 <printf@plt>
jmp    14e2 <main+0x332>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcac(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1528 <main+0x378>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xc90(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    161e <main+0x46e>
mov    0x2ab9(%rip),%rax
mov    (%rax),%esi
lea    0xc76(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x114(%rbp)
mov    -0x114(%rbp),%edi
mov    0x2a90(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffe00,%esi
call   1060 <lseek@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xc3c(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1591 <main+0x3e1>
mov    -0x114(%rbp),%edi
lea    0xca4(%rip),%rsi
mov    $0x15,%edx
call   1040 <write@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xc09(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    15c6 <main+0x416>
mov    -0x114(%rbp),%edi
lea    0xc84(%rip),%rsi
mov    $0x15,%edx
call   1040 <write@plt>
mov    $0x0,%al
call   1030 <check_bootloader_status@plt>
cmp    $0x0,%eax
jne    15e7 <main+0x437>
lea    0xb74(%rip),%rdi
call   1050 <printf@plt>
jmp    1619 <main+0x469>
mov    $0x0,%al
call   1030 <check_bootloader_status@plt>
cmp    $0x1,%eax
jne    1608 <main+0x458>
lea    0xbdd(%rip),%rdi
call   1050 <printf@plt>
jmp    1614 <main+0x464>
lea    0xb81(%rip),%rdi
call   1050 <printf@plt>
jmp    1619 <main+0x469>
jmp    162a <main+0x47a>
lea    0xbe4(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%rbx
cmpq   $0x0,0x8(%rsi)
jne    120a <main+0x5a>
mov    0x2e06(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe2c(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xe4c(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xe48(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1070 <android_product_name_get@plt>
lea    0xe42(%rip),%rsi
mov    %rbp,%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
je     1240 <main+0x90>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xe5b(%rip),%rsi
mov    %rsp,%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
je     126b <main+0xbb>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xe39(%rip),%rsi
mov    %rsp,%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
je     1296 <main+0xe6>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
lea    0xdd8(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xe17(%rip),%rsi
mov    %rsp,%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
jne    1326 <main+0x176>
lea    0xe2f(%rip),%rsi
mov    %rsp,%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
jne    1338 <main+0x188>
lea    0xe41(%rip),%rsi
mov    %rsp,%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
jne    1338 <main+0x188>
lea    0xe36(%rip),%rsi
mov    %rsp,%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
jne    1338 <main+0x188>
lea    0xe2b(%rip),%rsi
mov    %rsp,%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
jne    1338 <main+0x188>
lea    0xe20(%rip),%rsi
mov    %rsp,%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
jne    1338 <main+0x188>
xor    %eax,%eax
call   10a0 <check_for_aboot_partition@plt>
test   %rax,%rax
jne    1359 <main+0x1a9>
lea    0xee4(%rip),%rdi
jmp    1476 <main+0x2c6>
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
lea    0xd87(%rip),%rsi
jmp    1348 <main+0x198>
mov    0x2c91(%rip),%rax
mov    (%rax),%edi
lea    0xda1(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x8(%rbx),%rdi
lea    0xdc6(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1393 <main+0x1e3>
xor    %eax,%eax
call   1040 <check_bootloader_status@plt>
test   %eax,%eax
je     1448 <main+0x298>
xor    %eax,%eax
call   1040 <check_bootloader_status@plt>
cmp    $0x1,%eax
lea    0xe3a(%rip),%rax
jmp    1462 <main+0x2b2>
mov    0x8(%rbx),%rdi
lea    0xd92(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     13c1 <main+0x211>
mov    0x8(%rbx),%rdi
lea    0xd7f(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    146f <main+0x2bf>
mov    0x2c20(%rip),%rax
mov    (%rax),%esi
lea    0xd66(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,%ebp
mov    0x2c01(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0xfffffe00,%esi
call   1060 <lseek@plt>
mov    0x8(%rbx),%rdi
lea    0xd38(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1415 <main+0x265>
lea    0xe1c(%rip),%rsi
mov    %ebp,%edi
mov    $0x15,%edx
call   1050 <write@plt>
mov    0x8(%rbx),%rdi
lea    0xd12(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    143d <main+0x28d>
lea    0xe09(%rip),%rsi
mov    %ebp,%edi
mov    $0x15,%edx
call   1050 <write@plt>
xor    %eax,%eax
call   1040 <check_bootloader_status@plt>
test   %eax,%eax
jne    1451 <main+0x2a1>
lea    0xd99(%rip),%rdi
jmp    1476 <main+0x2c6>
xor    %eax,%eax
call   1040 <check_bootloader_status@plt>
cmp    $0x1,%eax
lea    0xd23(%rip),%rax
lea    0xd49(%rip),%rdi
cmove  %rax,%rdi
jmp    1476 <main+0x2c6>
lea    0xcee(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [49 x i8] c"Amazon FireTV Bootloader Unlock OpenSource Tool\0A\00"
@.str.1 = [16 x i8] c"By: rhcp011235\0A\00"
@.str.2 = [29 x i8] c"Usage: %s unlock|lock|check\0A\00"
@.str.3 = [9 x i8] c"51.1.0.0\00"
@.str.4 = [59 x i8] c"You can unlock your bootloder without downgrade. Congrats\0A\00"
@.str.5 = [9 x i8] c"51.1.0.1\00"
@.str.6 = [9 x i8] c"51.1.0.2\00"
@.str.7 = [9 x i8] c"51.1.1.0\00"
@.str.8 = [35 x i8] c"You need to downgrade to 51.1.0.2\0A\00"
@.str.9 = [9 x i8] c"51.1.2.0\00"
@.str.10 = [29 x i8] c"No Root Or Downgrade SORRY!\0A\00"
@.str.11 = [9 x i8] c"51.1.3.0\00"
@.str.12 = [9 x i8] c"51.1.4.0\00"
@.str.13 = [9 x i8] c"51.1.4.1\00"
@.str.14 = [9 x i8] c"51.1.4.2\00"
@.str.15 = [33 x i8] c"No aboot partition is detected!\0A\00"
@.str.16 = [6 x i8] c"check\00"
@.str.17 = [30 x i8] c"You have a locked bootloader\0A\00"
@.str.18 = [33 x i8] c"You have an unlocked bootloader\0A\00"
@.str.19 = [23 x i8] c"Unknown error occured\0A\00"
@.str.20 = [7 x i8] c"unlock\00"
@.str.21 = [5 x i8] c"lock\00"
@.str.22 = [45 x i8] c"/dev/block/platform/msm_sdcc.1/by-name/aboot\00"
@O_RDWR = global i32 0
@SEEK_END = global i32 0
@.str.23 = [21 x i8] c"ANDROID-BOOT!\00\00\00\01\00\00\00\00"
@.str.24 = [21 x i8] c"ANDROID-BOOT!\00\00\00\00\00\00\00\00"
@.str.25 = [46 x i8] c"You have a partially unlocked bootloader now\0A\00"
@.str.26 = [34 x i8] c"An invalid argument was provided\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i32
%8 = alloca [17 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %24
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%26 = call i32 @android_product_name_get(i8* %25)
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%28 = call i32* @strstr(i8* %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %30, %24
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%35 = call i32* @strstr(i8* %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %37, %33
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%42 = call i32* @strstr(i8* %41, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0))
br label %47
47: ; preds = %44, %40
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%49 = call i32* @strstr(i8* %48, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%50 = icmp ne i32* %49, null
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %47
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%57 = call i32* @strstr(i8* %56, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
%58 = icmp ne i32* %57, null
br i1 %58, label %59, label %63
59: ; preds = %55
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %55
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%65 = call i32* @strstr(i8* %64, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0))
%66 = icmp ne i32* %65, null
br i1 %66, label %67, label %71
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %63
%72 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%73 = call i32* @strstr(i8* %72, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
%74 = icmp ne i32* %73, null
br i1 %74, label %75, label %79
75: ; preds = %71
%76 = load i32, i32* @stderr
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %71
%80 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%81 = call i32* @strstr(i8* %80, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.13, i64 0, i64 0))
%82 = icmp ne i32* %81, null
br i1 %82, label %83, label %87
83: ; preds = %79
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %79
%88 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%89 = call i32* @strstr(i8* %88, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.14, i64 0, i64 0))
%90 = icmp ne i32* %89, null
br i1 %90, label %91, label %95
91: ; preds = %87
%92 = load i32, i32* @stderr
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %87
%96 = call i64 (...) @check_for_aboot_partition()
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %101
98: ; preds = %95
%99 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.15, i64 0, i64 0))
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %95
%102 = load i8**, i8*** %5
%103 = getelementptr inbounds i8*, i8** %102, i64 1
%104 = load i8*, i8** %103
%105 = call i64 @strcmp(i8* %104, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0))
%106 = icmp eq i64 %105, 0
br i1 %106, label %107, label %122
107: ; preds = %101
%108 = call i32 (...) @check_bootloader_status()
%109 = icmp eq i32 %108, 0
br i1 %109, label %110, label %112
110: ; preds = %107
%111 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.17, i64 0, i64 0))
br label %120
112: ; preds = %107
%113 = call i32 (...) @check_bootloader_status()
%114 = icmp eq i32 %113, 1
br i1 %114, label %115, label %117
115: ; preds = %112
%116 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.18, i64 0, i64 0))
br label %119
117: ; preds = %112
%118 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.19, i64 0, i64 0))
br label %119
119: ; preds = %117, %115
br label %120
120: ; preds = %119, %110
%121 = call i32 @exit(i32 1)
unreachable
122: ; preds = %101
%123 = load i8**, i8*** %5
%124 = getelementptr inbounds i8*, i8** %123, i64 1
%125 = load i8*, i8** %124
%126 = call i64 @strcmp(i8* %125, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.20, i64 0, i64 0))
%127 = icmp eq i64 %126, 0
br i1 %127, label %134, label %128
128: ; preds = %122
%129 = load i8**, i8*** %5
%130 = getelementptr inbounds i8*, i8** %129, i64 1
%131 = load i8*, i8** %130
%132 = call i64 @strcmp(i8* %131, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.21, i64 0, i64 0))
%133 = icmp eq i64 %132, 0
br i1 %133, label %134, label %171
134: ; preds = %128, %122
%135 = load i32, i32* @O_RDWR
%136 = call i32 @open(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.22, i64 0, i64 0), i32 %135)
store i32 %136, i32* %7
%137 = load i32, i32* %7
%138 = load i32, i32* @SEEK_END
%139 = call i32 @lseek(i32 %137, i32 -512, i32 %138)
%140 = load i8**, i8*** %5
%141 = getelementptr inbounds i8*, i8** %140, i64 1
%142 = load i8*, i8** %141
%143 = call i64 @strcmp(i8* %142, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.20, i64 0, i64 0))
%144 = icmp eq i64 %143, 0
br i1 %144, label %145, label %148
145: ; preds = %134
%146 = load i32, i32* %7
%147 = call i32 @write(i32 %146, i8** bitcast ([21 x i8]* @.str.23 to i8**), i32 21)
br label %148
148: ; preds = %145, %134
%149 = load i8**, i8*** %5
%150 = getelementptr inbounds i8*, i8** %149, i64 1
%151 = load i8*, i8** %150
%152 = call i64 @strcmp(i8* %151, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.21, i64 0, i64 0))
%153 = icmp eq i64 %152, 0
br i1 %153, label %154, label %157
154: ; preds = %148
%155 = load i32, i32* %7
%156 = call i32 @write(i32 %155, i8** bitcast ([21 x i8]* @.str.24 to i8**), i32 21)
br label %157
157: ; preds = %154, %148
%158 = call i32 (...) @check_bootloader_status()
%159 = icmp eq i32 %158, 0
br i1 %159, label %160, label %162
160: ; preds = %157
%161 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.17, i64 0, i64 0))
br label %170
162: ; preds = %157
%163 = call i32 (...) @check_bootloader_status()
%164 = icmp eq i32 %163, 1
br i1 %164, label %165, label %167
165: ; preds = %162
%166 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.25, i64 0, i64 0))
br label %169
167: ; preds = %162
%168 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.19, i64 0, i64 0))
br label %169
169: ; preds = %167, %165
br label %170
170: ; preds = %169, %160
br label %173
171: ; preds = %128
%172 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.26, i64 0, i64 0))
br label %173
173: ; preds = %171, %170
%174 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [49 x i8] c"Amazon FireTV Bootloader Unlock OpenSource Tool\0A\00"
@.str.1 = [16 x i8] c"By: rhcp011235\0A\00"
@.str.2 = [29 x i8] c"Usage: %s unlock|lock|check\0A\00"
@.str.3 = [9 x i8] c"51.1.0.0\00"
@.str.4 = [59 x i8] c"You can unlock your bootloder without downgrade. Congrats\0A\00"
@.str.5 = [9 x i8] c"51.1.0.1\00"
@.str.6 = [9 x i8] c"51.1.0.2\00"
@.str.7 = [9 x i8] c"51.1.1.0\00"
@.str.8 = [35 x i8] c"You need to downgrade to 51.1.0.2\0A\00"
@.str.9 = [9 x i8] c"51.1.2.0\00"
@.str.10 = [29 x i8] c"No Root Or Downgrade SORRY!\0A\00"
@.str.11 = [9 x i8] c"51.1.3.0\00"
@.str.12 = [9 x i8] c"51.1.4.0\00"
@.str.13 = [9 x i8] c"51.1.4.1\00"
@.str.14 = [9 x i8] c"51.1.4.2\00"
@.str.16 = [6 x i8] c"check\00"
@.str.20 = [7 x i8] c"unlock\00"
@.str.21 = [5 x i8] c"lock\00"
@.str.22 = [45 x i8] c"/dev/block/platform/msm_sdcc.1/by-name/aboot\00"
@O_RDWR = global i32 0
@SEEK_END = global i32 0
@.str.23 = [21 x i8] c"ANDROID-BOOT!\00\00\00\01\00\00\00\00"
@.str.24 = [21 x i8] c"ANDROID-BOOT!\00\00\00\00\00\00\00\00"
@str = [33 x i8] c"An invalid argument was provided\00"
@str.28 = [45 x i8] c"You have a partially unlocked bootloader now\00"
@str.30 = [22 x i8] c"Unknown error occured\00"
@str.31 = [32 x i8] c"You have an unlocked bootloader\00"
@str.32 = [29 x i8] c"You have a locked bootloader\00"
@str.33 = [32 x i8] c"No aboot partition is detected!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %16
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %1
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%18 = call i32 @android_product_name_get(i8* %17)
%19 = call i32* @strstr(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0))
br label %24
24: ; preds = %21, %16
%25 = call i32* @strstr(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %27, %24
%31 = call i32* @strstr(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %33, %30
%37 = call i32* @strstr(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%38 = icmp eq i32* %37, null
br i1 %38, label %43, label %39
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %36
%44 = call i32* @strstr(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
%45 = icmp eq i32* %44, null
br i1 %45, label %50, label %46
46: ; preds = %43
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %43
%51 = call i32* @strstr(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0))
%52 = icmp eq i32* %51, null
br i1 %52, label %57, label %53
53: ; preds = %50
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %50
%58 = call i32* @strstr(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
%59 = icmp eq i32* %58, null
br i1 %59, label %64, label %60
60: ; preds = %57
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %57
%65 = call i32* @strstr(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.13, i64 0, i64 0))
%66 = icmp eq i32* %65, null
br i1 %66, label %71, label %67
67: ; preds = %64
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %64
%72 = call i32* @strstr(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.14, i64 0, i64 0))
%73 = icmp eq i32* %72, null
br i1 %73, label %78, label %74
74: ; preds = %71
%75 = load i32, i32* @stderr
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %71
%79 = call i64 (...) @check_for_aboot_partition()
%80 = icmp eq i64 %79, 0
br i1 %80, label %81, label %84
81: ; preds = %78
%82 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.33, i64 0, i64 0))
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %78
%85 = load i8*, i8** %4
%86 = call i64 @strcmp(i8* %85, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0))
%87 = icmp eq i64 %86, 0
br i1 %87, label %88, label %99
88: ; preds = %84
%89 = call i32 (...) @check_bootloader_status()
%90 = icmp eq i32 %89, 0
br i1 %90, label %95, label %91
91: ; preds = %88
%92 = call i32 (...) @check_bootloader_status()
%93 = icmp eq i32 %92, 1
%94 = select i1 %93, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @str.31, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @str.30, i64 0, i64 0)
br label %95
95: ; preds = %91, %88
%96 = phi i8* [ getelementptr inbounds ([29 x i8], [29 x i8]* @str.32, i64 0, i64 0), %88 ], [ %94, %91 ]
%97 = call i32 @puts(i8* dereferenceable(1) %96)
%98 = call i32 @exit(i32 1)
unreachable
99: ; preds = %84
%100 = load i8*, i8** %4
%101 = call i64 @strcmp(i8* %100, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.20, i64 0, i64 0))
%102 = icmp eq i64 %101, 0
br i1 %102, label %107, label %103
103: ; preds = %99
%104 = load i8*, i8** %4
%105 = call i64 @strcmp(i8* %104, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.21, i64 0, i64 0))
%106 = icmp eq i64 %105, 0
br i1 %106, label %107, label %130
107: ; preds = %103, %99
%108 = load i32, i32* @O_RDWR
%109 = call i32 @open(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.22, i64 0, i64 0), i32 %108)
%110 = load i32, i32* @SEEK_END
%111 = call i32 @lseek(i32 %109, i32 -512, i32 %110)
%112 = load i8*, i8** %4
%113 = call i64 @strcmp(i8* %112, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.20, i64 0, i64 0))
%114 = icmp eq i64 %113, 0
br i1 %114, label %115, label %117
115: ; preds = %107
%116 = call i32 @write(i32 %109, i8** bitcast ([21 x i8]* @.str.23 to i8**), i32 21)
br label %117
117: ; preds = %115, %107
%118 = load i8*, i8** %4
%119 = call i64 @strcmp(i8* %118, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.21, i64 0, i64 0))
%120 = icmp eq i64 %119, 0
br i1 %120, label %121, label %123
121: ; preds = %117
%122 = call i32 @write(i32 %109, i8** bitcast ([21 x i8]* @.str.24 to i8**), i32 21)
br label %123
123: ; preds = %121, %117
%124 = call i32 (...) @check_bootloader_status()
%125 = icmp eq i32 %124, 0
br i1 %125, label %130, label %126
126: ; preds = %123
%127 = call i32 (...) @check_bootloader_status()
%128 = icmp eq i32 %127, 1
%129 = select i1 %128, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @str.28, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @str.30, i64 0, i64 0)
br label %130
130: ; preds = %103, %126, %123
%131 = phi i8* [ getelementptr inbounds ([29 x i8], [29 x i8]* @str.32, i64 0, i64 0), %123 ], [ %129, %126 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0), %103 ]
%132 = call i32 @puts(i8* dereferenceable(1) %131)
%133 = call i32 @exit(i32 1)
unreachable
}