#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fileExists(char *);
scalar_t__ getuid();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  char *arg = argv[1];
  if (argc == 2) {
    if ((arg[1]) == 'v') {
      printf("TAD G730 MMFI 1.0.0\n");
      exit(EXIT_SUCCESS);
    }
  }
  if (getuid() != 0) {
    printf("This binary can only be executed with the help of su\n");
    printf("Invoke \"adb shell su -c restore\" to restore backup files\n");
    printf("Without su, you can only check the version of the binary\n");
    printf("Invoke \"adb shell restore -v\" to check version\n");
    exit(EXIT_FAILURE);
  }
  if (!fileExists("/system/framework/framework.odex.bak") ||
      !fileExists("/system/fonts/Roboto-Regular.ttf.bak")) {
    printf("There's no backup file to be restored\n");
    exit(EXIT_FAILURE);
  }
  system("mount -o rw,remount /system\nrm /system/framework/framework.odex\nmv "
         "/system/framework/framework.odex.bak "
         "/system/framework/framework.odex\nchmod 644 "
         "/system/framework/framework.odex\nrm "
         "/system/fonts/Roboto-Regular.ttf\nmv "
         "/system/fonts/Roboto-Regular.ttf.bak "
         "/system/fonts/Roboto-Regular.ttf\nchmod 644 "
         "/system/fonts/Roboto-Regular.ttf\nreboot");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11ac <main+0x5c>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x76,%eax
jne    11a7 <main+0x57>
lea    0xe6c(%rip),%rdi
call   1060 <printf@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11ac <main+0x5c>
mov    $0x0,%al
call   1040 <getuid@plt>
cmp    $0x0,%rax
je     11fb <main+0xab>
lea    0xe51(%rip),%rdi
call   1060 <printf@plt>
lea    0xe7b(%rip),%rdi
call   1060 <printf@plt>
lea    0xea9(%rip),%rdi
call   1060 <printf@plt>
lea    0xed7(%rip),%rdi
call   1060 <printf@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xeed(%rip),%rdi
call   1030 <fileExists@plt>
cmp    $0x0,%eax
je     1225 <main+0xd5>
lea    0xefd(%rip),%rdi
call   1030 <fileExists@plt>
cmp    $0x0,%eax
jne    123f <main+0xef>
lea    0xf0d(%rip),%rdi
call   1060 <printf@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xf1a(%rip),%rdi
call   1050 <system@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x2,%edi
jne    116e <main+0x1e>
mov    0x8(%rsi),%rax
cmpb   $0x76,0x1(%rax)
jne    116e <main+0x1e>
lea    0x1132(%rip),%rdi
call   1030 <puts@plt>
jmp    11ed <main+0x9d>
xor    %eax,%eax
call   1050 <getuid@plt>
test   %rax,%rax
jne    11a3 <main+0x53>
lea    0xe7f(%rip),%rdi
call   1040 <fileExists@plt>
test   %eax,%eax
je     119a <main+0x4a>
lea    0xe94(%rip),%rdi
call   1040 <fileExists@plt>
test   %eax,%eax
jne    11e1 <main+0x91>
lea    0xffc(%rip),%rdi
jmp    11ce <main+0x7e>
lea    0x1019(%rip),%rdi
call   1030 <puts@plt>
lea    0x1042(%rip),%rdi
call   1030 <puts@plt>
lea    0x106f(%rip),%rdi
call   1030 <puts@plt>
lea    0x109c(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xe62(%rip),%rdi
call   1060 <system@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"TAD G730 MMFI 1.0.0\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [54 x i8] c"This binary can only be executed with the help of su\0A\00"
@.str.2 = [58 x i8] c"Invoke \22adb shell su -c restore\22 to restore backup files\0A\00"
@.str.3 = [58 x i8] c"Without su, you can only check the version of the binary\0A\00"
@.str.4 = [48 x i8] c"Invoke \22adb shell restore -v\22 to check version\0A\00"
@EXIT_FAILURE = global i32 0
@.str.5 = [37 x i8] c"/system/framework/framework.odex.bak\00"
@.str.6 = [37 x i8] c"/system/fonts/Roboto-Regular.ttf.bak\00"
@.str.7 = [39 x i8] c"There's no backup file to be restored\0A\00"
@.str.8 = [339 x i8] c"mount -o rw,remount /system\0Arm /system/framework/framework.odex\0Amv /system/framework/framework.odex.bak /system/framework/framework.odex\0Achmod 644 /system/framework/framework.odex\0Arm /system/fonts/Roboto-Regular.ttf\0Amv /system/fonts/Roboto-Regular.ttf.bak /system/fonts/Roboto-Regular.ttf\0Achmod 644 /system/fonts/Roboto-Regular.ttf\0Areboot\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
store i8* %9, i8** %6
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %23
12: ; preds = %2
%13 = load i8*, i8** %6
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 118
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_SUCCESS
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %12
br label %23
23: ; preds = %22, %2
%24 = call i64 (...) @getuid()
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %23
%34 = call i32 @fileExists(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = call i32 @fileExists(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
%38 = icmp ne i32 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %36, %33
%40 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %36
%44 = call i32 @system(i8* getelementptr inbounds ([339 x i8], [339 x i8]* @.str.8, i64 0, i64 0))
%45 = load i32, i32* @EXIT_SUCCESS
%46 = call i32 @exit(i32 %45)
unreachable
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@.str.5 = [37 x i8] c"/system/framework/framework.odex.bak\00"
@.str.6 = [37 x i8] c"/system/fonts/Roboto-Regular.ttf.bak\00"
@.str.8 = [339 x i8] c"mount -o rw,remount /system\0Arm /system/framework/framework.odex\0Amv /system/framework/framework.odex.bak /system/framework/framework.odex\0Achmod 644 /system/framework/framework.odex\0Arm /system/fonts/Roboto-Regular.ttf\0Amv /system/fonts/Roboto-Regular.ttf.bak /system/fonts/Roboto-Regular.ttf\0Achmod 644 /system/fonts/Roboto-Regular.ttf\0Areboot\00"
@str = [38 x i8] c"There's no backup file to be restored\00"
@str.9 = [53 x i8] c"This binary can only be executed with the help of su\00"
@str.10 = [57 x i8] c"Invoke \22adb shell su -c restore\22 to restore backup files\00"
@str.11 = [57 x i8] c"Without su, you can only check the version of the binary\00"
@str.12 = [47 x i8] c"Invoke \22adb shell restore -v\22 to check version\00"
@str.13 = [20 x i8] c"TAD G730 MMFI 1.0.0\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %14
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = getelementptr inbounds i8, i8* %6, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 118
br i1 %9, label %10, label %14
10: ; preds = %4
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.13, i64 0, i64 0))
%12 = load i32, i32* @EXIT_SUCCESS
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %4, %2
%15 = tail call i64 (...) @getuid()
%16 = icmp eq i64 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %14
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.9, i64 0, i64 0))
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.10, i64 0, i64 0))
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.11, i64 0, i64 0))
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.12, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %14
%25 = tail call i32 @fileExists(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp eq i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = tail call i32 @fileExists(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %27, %24
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = tail call i32 @exit(i32 %32)
unreachable
34: ; preds = %27
%35 = tail call i32 @system(i8* getelementptr inbounds ([339 x i8], [339 x i8]* @.str.8, i64 0, i64 0))
%36 = load i32, i32* @EXIT_SUCCESS
%37 = tail call i32 @exit(i32 %36)
unreachable
}