#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 PATH_MAX;
int /*<<< orphan*/ exit(int);
int fb2png(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  char fn[PATH_MAX];
  int ret;
  if (argc == 2 && argv[1][0] != '-') {
    if (strlen(argv[1]) >= PATH_MAX) {
      printf("Output path is too long!\n");
      exit(-1);
    }
    sprintf(fn, "%s", argv[1]);
  } else if (argc == 1) {
    sprintf(fn, "%s", "fbdump.png");
  } else {
    printf("Android Screenshooter - fb2png\n"
           "Author: Kyan He <kyan.ql.he@gmail.com>\n"
           "Modified by  Phil3759 & McKael @xda\n"
           "Base version 0.0.2 ---> v0.0.5  <2013>\n"
           "Usage: fb2png [path/to/output.png]\n"
           "    The default output path is /data/local/fbdump.png\n");
    exit(0);
  }
  if (0 == (ret = fb2png(fn)))
    printf("Saved image to %s\n", fn);
  exit(ret);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1201 <main+0xb1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     1201 <main+0xb1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    0x2e2c(%rip),%rcx
cmp    (%rcx),%eax
jl     11e4 <main+0x94>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe23(%rip),%rsi
call   1050 <sprintf@plt>
jmp    1241 <main+0xf1>
cmpl   $0x1,-0x8(%rbp)
jne    1227 <main+0xd7>
mov    -0x30(%rbp),%rdi
lea    0xe04(%rip),%rsi
lea    0xe00(%rip),%rdx
call   1050 <sprintf@plt>
jmp    123c <main+0xec>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
jmp    1241 <main+0xf1>
mov    -0x30(%rbp),%rdi
call   1070 <fb2png@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jne    126b <main+0x11b>
mov    -0x30(%rbp),%rsi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e7f(%rip),%r15
mov    (%r15),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x1,%edi
je     11ae <main+0x4e>
cmp    $0x2,%edi
jne    119b <main+0x3b>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
cmpb   $0x2d,(%rdi)
jne    11c4 <main+0x64>
lea    0xe71(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>
movabs $0x702e706d75646266,%rax
70 2e 70
mov    %rax,(%rbx)
movl   $0x676e70,0x7(%rbx)
jmp    11da <main+0x7a>
call   1050 <strlen@plt>
cmp    (%r15),%eax
jge    1202 <main+0xa2>
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1080 <fb2png@plt>
mov    %eax,%r14d
test   %eax,%eax
jne    11fa <main+0x9a>
lea    0xe10(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%edi
call   1070 <exit@plt>
lea    0xef4(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [26 x i8] c"Output path is too long!\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [11 x i8] c"fbdump.png\00"
@.str.3 = [235 x i8] c"Android Screenshooter - fb2png\0AAuthor: Kyan He <kyan.ql.he@gmail.com>\0AModified by Phil3759 & McKael @xda\0ABase version 0.0.2 ---> v0.0.5 <2013>\0AUsage: fb2png [path/to/output.png]\0A The default output path is /data/local/fbdump.png\0A\00"
@.str.4 = [19 x i8] c"Saved image to %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %38
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 45
br i1 %22, label %23, label %38
23: ; preds = %15
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @strlen(i8* %26)
%28 = load i32, i32* @PATH_MAX
%29 = icmp sge i32 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %23
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %23
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %36)
br label %47
38: ; preds = %15, %2
%39 = load i32, i32* %4
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %46
43: ; preds = %38
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([235 x i8], [235 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %41
br label %47
47: ; preds = %46, %33
%48 = call i32 @fb2png(i8* %12)
store i32 %48, i32* %8
%49 = icmp eq i32 0, %48
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %12)
br label %52
52: ; preds = %50, %47
%53 = load i32, i32* %8
%54 = call i32 @exit(i32 %53)
unreachable
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str.2 = [11 x i8] c"fbdump.png\00"
@.str.4 = [19 x i8] c"Saved image to %s\0A\00"
@str = [234 x i8] c"Android Screenshooter - fb2png\0AAuthor: Kyan He <kyan.ql.he@gmail.com>\0AModified by Phil3759 & McKael @xda\0ABase version 0.0.2 ---> v0.0.5 <2013>\0AUsage: fb2png [path/to/output.png]\0A The default output path is /data/local/fbdump.png\00"
@str.5 = [25 x i8] c"Output path is too long!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
switch i32 %0, label %22 [
i32 2, label %6
i32 1, label %21
]
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 45
br i1 %10, label %22, label %11
11: ; preds = %6
%12 = tail call i32 @strlen(i8* %8)
%13 = load i32, i32* @PATH_MAX
%14 = icmp slt i32 %12, %13
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.5, i64 0, i64 0))
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %11
%19 = load i8*, i8** %7
%20 = call i8* @strcpy(i8* %5, i8* dereferenceable(1) %19)
br label %25
21: ; preds = %2
br label %25
22: ; preds = %6, %2
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([234 x i8], [234 x i8]* @str, i64 0, i64 0))
%24 = tail call i32 @exit(i32 0)
unreachable
25: ; preds = %21, %18
%26 = call i32 @fb2png(i8* %5)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %5)
br label %30
30: ; preds = %28, %25
%31 = call i32 @exit(i32 %26)
unreachable
}