#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*/ extract_text(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  printf("PSB Text Extractor Tool v.00\nAuthor: Flat "
         "(http://github.com/Flat)\n\n");
  int option, err = 0;
  int iflag = 0, oflag = 0;
  char *input_file = NULL;
  char *output_file = NULL;
  static char usage[] = "\nusage: %s -i input_file -o output_file\n";
  while ((option = getopt(argc, argv, "i:o:")) != -1)
    switch (option) {
    case 'i':
      input_file = optarg;
      iflag = 1;
      break;
    case 'o':
      oflag = 1;
      output_file = optarg;
      break;
    case '?':
      err = 1;
      break;
    }
  if (iflag == 0) {
    fprintf(stderr, "%s: missing -i option\n", argv[0]);
    fprintf(stderr, usage, argv[0]);
    return 1;
  } else if (oflag == 0) {
    fprintf(stderr, "%s: missing -o option\n", argv[0]);
    fprintf(stderr, usage, argv[0]);
    return 1;
  } else if (err) {
    fprintf(stderr, usage, argv[0]);
    return 1;
  }
  extract_text(input_file, output_file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xeb0(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     121c <main+0xdc>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x3f,%eax
je     1210 <main+0xd0>
jmp    11ba <main+0x7a>
mov    -0x34(%rbp),%eax
sub    $0x69,%eax
je     11dc <main+0x9c>
jmp    11cb <main+0x8b>
mov    -0x34(%rbp),%eax
sub    $0x6f,%eax
je     11f6 <main+0xb6>
jmp    1217 <main+0xd7>
mov    0x2e15(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x1c(%rbp)
jmp    1217 <main+0xd7>
movl   $0x1,-0x20(%rbp)
mov    0x2df4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    1217 <main+0xd7>
movl   $0x1,-0x18(%rbp)
jmp    1187 <main+0x47>
cmpl   $0x0,-0x1c(%rbp)
jne    126a <main+0x12a>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe0d(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0x2df7(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1308 <main+0x1c8>
cmpl   $0x0,-0x20(%rbp)
jne    12b8 <main+0x178>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdd6(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0x2da9(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1308 <main+0x1c8>
cmpl   $0x0,-0x18(%rbp)
je     12ea <main+0x1aa>
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0x2d77(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1308 <main+0x1c8>
jmp    12ef <main+0x1af>
jmp    12f4 <main+0x1b4>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <extract_text@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xed9(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
mov    $0x1,%r13b
lea    0xe94(%rip),%r12
xor    %r15d,%r15d
xor    %eax,%eax
mov    %rax,0x10(%rsp)
xor    %eax,%eax
mov    %rax,0x8(%rsp)
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1060 <getopt@plt>
cmp    $0x68,%eax
jg     11b0 <main+0x70>
cmp    $0xffffffff,%eax
je     11e8 <main+0xa8>
cmp    $0x3f,%eax
jne    1180 <main+0x40>
xor    %r13d,%r13d
jmp    1180 <main+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x6f,%eax
je     11d1 <main+0x91>
cmp    $0x69,%eax
jne    1180 <main+0x40>
mov    0x2e37(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
mov    $0x1,%r14d
jmp    1180 <main+0x40>
mov    0x2e20(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
mov    $0x1,%r15d
jmp    1180 <main+0x40>
test   %r14d,%r14d
je     120b <main+0xcb>
test   %r15d,%r15d
je     1221 <main+0xe1>
test   $0x1,%r13b
je     123f <main+0xff>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
call   1040 <extract_text@plt>
xor    %eax,%eax
jmp    125c <main+0x11c>
mov    0x2dc6(%rip),%rbp
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xde6(%rip),%rsi
jmp    1235 <main+0xf5>
mov    0x2db0(%rip),%rbp
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xde7(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
jmp    1248 <main+0x108>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0x2dfe(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [69 x i8] c"PSB Text Extractor Tool v.00\0AAuthor: Flat (http://github.com/Flat)\0A\0A\00"
@main.usage = internal global [41 x i8] c"\0Ausage: %s -i input_file -o output_file\0A\00"
@.str.1 = [5 x i8] c"i:o:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.2 = [23 x i8] c"%s: missing -i option\0A\00"
@.str.3 = [23 x i8] c"%s: missing -o option\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 i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i8* null, i8** %10
store i8* null, i8** %11
br label %13
13: ; preds = %25, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 %16, i32* %6
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %26
18: ; preds = %13
%19 = load i32, i32* %6
switch i32 %19, label %25 [
i32 105, label %20
i32 111, label %22
i32 63, label %24
]
20: ; preds = %18
%21 = load i8*, i8** @optarg
store i8* %21, i8** %10
store i32 1, i32* %8
br label %25
22: ; preds = %18
store i32 1, i32* %9
%23 = load i8*, i8** @optarg
store i8* %23, i8** %11
br label %25
24: ; preds = %18
store i32 1, i32* %7
br label %25
25: ; preds = %18, %24, %22, %20
br label %13
26: ; preds = %13
%27 = load i32, i32* %8
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %40
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @stderr
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = load i8*, i8** %37
%39 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @main.usage, i64 0, i64 0), i8* %38)
store i32 1, i32* %3
br label %69
40: ; preds = %26
%41 = load i32, i32* %9
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %54
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 0
%47 = load i8*, i8** %46
%48 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = load i32, i32* @stderr
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 0
%52 = load i8*, i8** %51
%53 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @main.usage, i64 0, i64 0), i8* %52)
store i32 1, i32* %3
br label %69
54: ; preds = %40
%55 = load i32, i32* %7
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %63
57: ; preds = %54
%58 = load i32, i32* @stderr
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @main.usage, i64 0, i64 0), i8* %61)
store i32 1, i32* %3
br label %69
63: ; preds = %54
br label %64
64: ; preds = %63
br label %65
65: ; preds = %64
%66 = load i8*, i8** %10
%67 = load i8*, i8** %11
%68 = call i32 @extract_text(i8* %66, i8* %67)
store i32 0, i32* %3
br label %69
69: ; preds = %65, %57, %43, %29
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@main.usage = internal global [41 x i8] c"\0Ausage: %s -i input_file -o output_file\0A\00"
@.str.1 = [5 x i8] c"i:o:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.2 = [23 x i8] c"%s: missing -i option\0A\00"
@.str.3 = [23 x i8] c"%s: missing -o option\0A\00"
@str = [68 x i8] c"PSB Text Extractor Tool v.00\0AAuthor: Flat (http://github.com/Flat)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @str, i64 0, i64 0))
br label %4
4: ; preds = %18, %2
%5 = phi i1 [ true, %2 ], [ false, %18 ]
%6 = phi i32 [ 0, %2 ], [ %11, %18 ]
%7 = phi i32 [ 0, %2 ], [ %16, %18 ]
%8 = phi i8* [ null, %2 ], [ %13, %18 ]
%9 = phi i8* [ null, %2 ], [ %17, %18 ]
br label %10
10: ; preds = %4, %20
%11 = phi i32 [ %6, %4 ], [ 1, %20 ]
%12 = phi i32 [ %7, %4 ], [ %16, %20 ]
%13 = phi i8* [ %8, %4 ], [ %21, %20 ]
%14 = phi i8* [ %9, %4 ], [ %17, %20 ]
br label %15
15: ; preds = %10, %22
%16 = phi i32 [ %12, %10 ], [ 1, %22 ]
%17 = phi i8* [ %14, %10 ], [ %23, %22 ]
br label %18
18: ; preds = %15, %18
%19 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
switch i32 %19, label %18 [
i32 -1, label %24
i32 105, label %20
i32 111, label %22
i32 63, label %4
]
20: ; preds = %18
%21 = load i8*, i8** @optarg
br label %10
22: ; preds = %18
%23 = load i8*, i8** @optarg
br label %15
24: ; preds = %18
%25 = icmp eq i32 %11, 0
br i1 %25, label %26, label %33
26: ; preds = %24
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %1
%29 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %1
%32 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @main.usage, i64 0, i64 0), i8* %31)
br label %49
33: ; preds = %24
%34 = icmp eq i32 %16, 0
br i1 %34, label %35, label %42
35: ; preds = %33
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %1
%38 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @stderr
%40 = load i8*, i8** %1
%41 = tail call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @main.usage, i64 0, i64 0), i8* %40)
br label %49
42: ; preds = %33
br i1 %5, label %47, label %43
43: ; preds = %42
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %1
%46 = tail call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @main.usage, i64 0, i64 0), i8* %45)
br label %49
47: ; preds = %42
%48 = tail call i32 @extract_text(i8* %13, i8* %17)
br label %49
49: ; preds = %47, %43, %35, %26
%50 = phi i32 [ 1, %26 ], [ 1, %35 ], [ 1, %43 ], [ 0, %47 ]
ret i32 %50
}