#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, unsigned long,
                          int /*<<< orphan*/ *);
unsigned char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ uncompress(unsigned char *, unsigned long *, unsigned char *,
                              unsigned int);
int main(int argc, char *argv[]) {
  FILE *f;
  unsigned char *fm;
  unsigned int res_size;
  unsigned int cprg_size;
  unsigned int cprg_crc32;
  unsigned char *om;
  unsigned long dest_len;
  int sz;
  if (argc < 3) {
    printf("psfex - Extracts an executable from a PSF file\n");
    printf("psfex [.psf] [output]\n");
    return -1;
  }
  f = fopen(argv[1], "rb");
  if (f == NULL) {
    printf("Could not open file.\n");
    return -1;
  }
  fseek(f, 0, SEEK_END);
  sz = ftell(f);
  fseek(f, 0, SEEK_SET);
  fm = malloc(sz);
  fread(fm, sizeof(char), sz, f);
  fclose(f);
  if (fm[0] == 'P' && fm[1] == 'S' && fm[2] == 'F') {
    printf("PSF file.\n");
  } else {
    printf("Not a PSF file. Aborting.\n");
    return -1;
  }
  res_size = fm[4] | (fm[5] << 8) | (fm[6] << 16) | (fm[7] << 24);
  cprg_size = fm[8] | (fm[9] << 8) | (fm[10] << 16) | (fm[11] << 24);
  cprg_crc32 = fm[12] | (fm[13] << 8) | (fm[14] << 16) | (fm[15] << 24);
  printf("Reserved area size: %d bytes\n", res_size);
  printf("Compressed program size: %d bytes\n", cprg_size);
  printf("Compressed program CRC32: 0x%08x\n", cprg_crc32);
  om = malloc(0x200000);
  dest_len = 0x200000;
  uncompress(om, &dest_len, &fm[16 + res_size], cprg_size);
  printf("Real destination length: %ld\n", dest_len);
  f = fopen(argv[2], "wb");
  if (f == NULL) {
    printf("Could not open %s for writing. Aborting.\n", argv[2]);
    return -1;
  }
  fwrite(om, sizeof(char), dest_len, f);
  fclose(f);
  free(om);
  free(fm);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11e8 <main+0x48>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    146f <main+0x2cf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe50(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1225 <main+0x85>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    146f <main+0x2cf>
mov    -0x18(%rbp),%rdi
mov    0x2db8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1080 <ftell@plt>
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d88(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x44(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x44(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x50,%eax
jne    12c8 <main+0x128>
mov    -0x20(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x53,%eax
jne    12c8 <main+0x128>
mov    -0x20(%rbp),%rax
movzbl 0x2(%rax),%eax
cmp    $0x46,%eax
jne    12c8 <main+0x128>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    12e2 <main+0x142>
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    146f <main+0x2cf>
mov    -0x20(%rbp),%rax
movzbl 0x4(%rax),%eax
mov    -0x20(%rbp),%rcx
movzbl 0x5(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x20(%rbp),%rcx
movzbl 0x6(%rcx),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x20(%rbp),%rcx
movzbl 0x7(%rcx),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
movzbl 0x8(%rax),%eax
mov    -0x20(%rbp),%rcx
movzbl 0x9(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x20(%rbp),%rcx
movzbl 0xa(%rcx),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x20(%rbp),%rcx
movzbl 0xb(%rcx),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movzbl 0xc(%rax),%eax
mov    -0x20(%rbp),%rcx
movzbl 0xd(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x20(%rbp),%rcx
movzbl 0xe(%rcx),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x20(%rbp),%rcx
movzbl 0xf(%rcx),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%esi
lea    0xd04(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xd11(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x2c(%rbp),%esi
lea    0xd23(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x200000,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
movq   $0x200000,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%eax
add    $0x10,%eax
mov    %eax,%eax
add    %rax,%rdx
mov    -0x28(%rbp),%ecx
lea    -0x40(%rbp),%rsi
call   1060 <uncompress@plt>
mov    -0x40(%rbp),%rsi
lea    0xcfe(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd06(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1437 <main+0x297>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xce6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    146f <main+0x2cf>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     11d8 <main+0x28>
lea    0xf23(%rip),%rdi
call   1040 <puts@plt>
lea    0xf46(%rip),%rdi
jmp    134c <main+0x19c>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe1a(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1345 <main+0x195>
mov    %rax,%rbp
mov    0x2dea(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %rbp,%rdi
call   1090 <ftell@plt>
mov    %eax,%ebx
mov    0x2dbd(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %ebx,%edi
call   10a0 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %rbp,%rcx
call   1050 <fread@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
cmpb   $0x50,(%r15)
jne    133c <main+0x18c>
cmpb   $0x53,0x1(%r15)
jne    133c <main+0x18c>
cmpb   $0x46,0x2(%r15)
jne    133c <main+0x18c>
lea    0xe59(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%r15),%r13d
mov    0x8(%r15),%r12d
mov    0xc(%r15),%ebx
lea    0xd79(%rip),%rdi
xor    %ebp,%ebp
mov    %r13d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd84(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd96(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x200000,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
movq   $0x200000,(%rsp)
add    $0x10,%r13d
mov    %r15,%rdx
add    %r13,%rdx
mov    %rsp,%rsi
mov    %rax,%rdi
mov    %r12d,%ecx
call   1070 <uncompress@plt>
mov    (%rsp),%rsi
lea    0xd77(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x10(%r14),%rdi
lea    0xd83(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1367 <main+0x1b7>
mov    %rax,%r12
mov    (%rsp),%rdx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rcx
call   10d0 <fwrite@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    1356 <main+0x1a6>
lea    0xd6e(%rip),%rdi
jmp    134c <main+0x19c>
lea    0xd89(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%r14),%rsi
lea    0xd15(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1351 <main+0x1a1>

LLVM IR (-O0):
@.str = [48 x i8] c"psfex - Extracts an executable from a PSF file\0A\00"
@.str.1 = [23 x i8] c"psfex [.psf] [output]\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [22 x i8] c"Could not open file.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [11 x i8] c"PSF file.\0A\00"
@.str.5 = [27 x i8] c"Not a PSF file. Aborting.\0A\00"
@.str.6 = [30 x i8] c"Reserved area size: %d bytes\0A\00"
@.str.7 = [35 x i8] c"Compressed program size: %d bytes\0A\00"
@.str.8 = [34 x i8] c"Compressed program CRC32: 0x%08x\0A\00"
@.str.9 = [30 x i8] c"Real destination length: %ld\0A\00"
@.str.10 = [3 x i8] c"wb\00"
@.str.11 = [42 x i8] c"Could not open %s for writing. Aborting.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %172
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %172
28: ; preds = %19
%29 = load i32*, i32** %6
%30 = load i32, i32* @SEEK_END
%31 = call i32 @fseek(i32* %29, i32 0, i32 %30)
%32 = load i32*, i32** %6
%33 = call i32 @ftell(i32* %32)
store i32 %33, i32* %13
%34 = load i32*, i32** %6
%35 = load i32, i32* @SEEK_SET
%36 = call i32 @fseek(i32* %34, i32 0, i32 %35)
%37 = load i32, i32* %13
%38 = call i8* @malloc(i32 %37)
store i8* %38, i8** %7
%39 = load i8*, i8** %7
%40 = load i32, i32* %13
%41 = load i32*, i32** %6
%42 = call i32 @fread(i8* %39, i32 1, i32 %40, i32* %41)
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
%45 = load i8*, i8** %7
%46 = getelementptr inbounds i8, i8* %45, i64 0
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = icmp eq i32 %48, 80
br i1 %49, label %50, label %64
50: ; preds = %28
%51 = load i8*, i8** %7
%52 = getelementptr inbounds i8, i8* %51, i64 1
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = icmp eq i32 %54, 83
br i1 %55, label %56, label %64
56: ; preds = %50
%57 = load i8*, i8** %7
%58 = getelementptr inbounds i8, i8* %57, i64 2
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = icmp eq i32 %60, 70
br i1 %61, label %62, label %64
62: ; preds = %56
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %66
64: ; preds = %56, %50, %28
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %172
66: ; preds = %62
%67 = load i8*, i8** %7
%68 = getelementptr inbounds i8, i8* %67, i64 4
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = load i8*, i8** %7
%72 = getelementptr inbounds i8, i8* %71, i64 5
%73 = load i8, i8* %72
%74 = zext i8 %73 to i32
%75 = shl i32 %74, 8
%76 = or i32 %70, %75
%77 = load i8*, i8** %7
%78 = getelementptr inbounds i8, i8* %77, i64 6
%79 = load i8, i8* %78
%80 = zext i8 %79 to i32
%81 = shl i32 %80, 16
%82 = or i32 %76, %81
%83 = load i8*, i8** %7
%84 = getelementptr inbounds i8, i8* %83, i64 7
%85 = load i8, i8* %84
%86 = zext i8 %85 to i32
%87 = shl i32 %86, 24
%88 = or i32 %82, %87
store i32 %88, i32* %8
%89 = load i8*, i8** %7
%90 = getelementptr inbounds i8, i8* %89, i64 8
%91 = load i8, i8* %90
%92 = zext i8 %91 to i32
%93 = load i8*, i8** %7
%94 = getelementptr inbounds i8, i8* %93, i64 9
%95 = load i8, i8* %94
%96 = zext i8 %95 to i32
%97 = shl i32 %96, 8
%98 = or i32 %92, %97
%99 = load i8*, i8** %7
%100 = getelementptr inbounds i8, i8* %99, i64 10
%101 = load i8, i8* %100
%102 = zext i8 %101 to i32
%103 = shl i32 %102, 16
%104 = or i32 %98, %103
%105 = load i8*, i8** %7
%106 = getelementptr inbounds i8, i8* %105, i64 11
%107 = load i8, i8* %106
%108 = zext i8 %107 to i32
%109 = shl i32 %108, 24
%110 = or i32 %104, %109
store i32 %110, i32* %9
%111 = load i8*, i8** %7
%112 = getelementptr inbounds i8, i8* %111, i64 12
%113 = load i8, i8* %112
%114 = zext i8 %113 to i32
%115 = load i8*, i8** %7
%116 = getelementptr inbounds i8, i8* %115, i64 13
%117 = load i8, i8* %116
%118 = zext i8 %117 to i32
%119 = shl i32 %118, 8
%120 = or i32 %114, %119
%121 = load i8*, i8** %7
%122 = getelementptr inbounds i8, i8* %121, i64 14
%123 = load i8, i8* %122
%124 = zext i8 %123 to i32
%125 = shl i32 %124, 16
%126 = or i32 %120, %125
%127 = load i8*, i8** %7
%128 = getelementptr inbounds i8, i8* %127, i64 15
%129 = load i8, i8* %128
%130 = zext i8 %129 to i32
%131 = shl i32 %130, 24
%132 = or i32 %126, %131
store i32 %132, i32* %10
%133 = load i32, i32* %8
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i32 %133)
%135 = load i32, i32* %9
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i32 %135)
%137 = load i32, i32* %10
%138 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i32 %137)
%139 = call i8* @malloc(i32 2097152)
store i8* %139, i8** %11
store i64 2097152, i64* %12
%140 = load i8*, i8** %11
%141 = load i8*, i8** %7
%142 = load i32, i32* %8
%143 = add i32 16, %142
%144 = zext i32 %143 to i64
%145 = getelementptr inbounds i8, i8* %141, i64 %144
%146 = load i32, i32* %9
%147 = call i32 @uncompress(i8* %140, i64* %12, i8* %145, i32 %146)
%148 = load i64, i64* %12
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i64 %148)
%150 = load i8**, i8*** %5
%151 = getelementptr inbounds i8*, i8** %150, i64 2
%152 = load i8*, i8** %151
%153 = call i32* @fopen(i8* %152, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
store i32* %153, i32** %6
%154 = load i32*, i32** %6
%155 = icmp eq i32* %154, null
br i1 %155, label %156, label %161
156: ; preds = %66
%157 = load i8**, i8*** %5
%158 = getelementptr inbounds i8*, i8** %157, i64 2
%159 = load i8*, i8** %158
%160 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.11, i64 0, i64 0), i8* %159)
store i32 -1, i32* %3
br label %172
161: ; preds = %66
%162 = load i8*, i8** %11
%163 = load i64, i64* %12
%164 = load i32*, i32** %6
%165 = call i32 @fwrite(i8* %162, i32 1, i64 %163, i32* %164)
%166 = load i32*, i32** %6
%167 = call i32 @fclose(i32* %166)
%168 = load i8*, i8** %11
%169 = call i32 @free(i8* %168)
%170 = load i8*, i8** %7
%171 = call i32 @free(i8* %170)
store i32 0, i32* %3
br label %172
172: ; preds = %161, %156, %64, %26, %16
%173 = load i32, i32* %3
ret i32 %173
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.6 = [30 x i8] c"Reserved area size: %d bytes\0A\00"
@.str.7 = [35 x i8] c"Compressed program size: %d bytes\0A\00"
@.str.8 = [34 x i8] c"Compressed program CRC32: 0x%08x\0A\00"
@.str.9 = [30 x i8] c"Real destination length: %ld\0A\00"
@.str.10 = [3 x i8] c"wb\00"
@.str.11 = [42 x i8] c"Could not open %s for writing. Aborting.\0A\00"
@str = [26 x i8] c"Not a PSF file. Aborting.\00"
@str.12 = [10 x i8] c"PSF file.\00"
@str.13 = [21 x i8] c"Could not open file.\00"
@str.14 = [47 x i8] c"psfex - Extracts an executable from a PSF file\00"
@str.15 = [22 x i8] c"psfex [.psf] [output]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.14, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.15, i64 0, i64 0))
br label %116
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.13, i64 0, i64 0))
br label %116
16: ; preds = %9
%17 = load i32, i32* @SEEK_END
%18 = tail call i32 @fseek(i32* %12, i32 0, i32 %17)
%19 = tail call i32 @ftell(i32* %12)
%20 = load i32, i32* @SEEK_SET
%21 = tail call i32 @fseek(i32* %12, i32 0, i32 %20)
%22 = tail call i8* @malloc(i32 %19)
%23 = tail call i32 @fread(i8* %22, i32 1, i32 %19, i32* %12)
%24 = tail call i32 @fclose(i32* %12)
%25 = load i8, i8* %22
%26 = icmp eq i8 %25, 80
br i1 %26, label %27, label %105
27: ; preds = %16
%28 = getelementptr inbounds i8, i8* %22, i64 1
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 83
br i1 %30, label %31, label %105
31: ; preds = %27
%32 = getelementptr inbounds i8, i8* %22, i64 2
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 70
br i1 %34, label %35, label %105
35: ; preds = %31
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.12, i64 0, i64 0))
%37 = getelementptr inbounds i8, i8* %22, i64 4
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = getelementptr inbounds i8, i8* %22, i64 5
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = shl nuw nsw i32 %42, 8
%44 = or i32 %43, %39
%45 = getelementptr inbounds i8, i8* %22, i64 6
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = shl nuw nsw i32 %47, 16
%49 = or i32 %44, %48
%50 = getelementptr inbounds i8, i8* %22, i64 7
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = shl nuw i32 %52, 24
%54 = or i32 %49, %53
%55 = getelementptr inbounds i8, i8* %22, i64 8
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = getelementptr inbounds i8, i8* %22, i64 9
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = shl nuw nsw i32 %60, 8
%62 = or i32 %61, %57
%63 = getelementptr inbounds i8, i8* %22, i64 10
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
%66 = shl nuw nsw i32 %65, 16
%67 = or i32 %62, %66
%68 = getelementptr inbounds i8, i8* %22, i64 11
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = shl nuw i32 %70, 24
%72 = or i32 %67, %71
%73 = getelementptr inbounds i8, i8* %22, i64 12
%74 = load i8, i8* %73
%75 = zext i8 %74 to i32
%76 = getelementptr inbounds i8, i8* %22, i64 13
%77 = load i8, i8* %76
%78 = zext i8 %77 to i32
%79 = shl nuw nsw i32 %78, 8
%80 = or i32 %79, %75
%81 = getelementptr inbounds i8, i8* %22, i64 14
%82 = load i8, i8* %81
%83 = zext i8 %82 to i32
%84 = shl nuw nsw i32 %83, 16
%85 = or i32 %80, %84
%86 = getelementptr inbounds i8, i8* %22, i64 15
%87 = load i8, i8* %86
%88 = zext i8 %87 to i32
%89 = shl nuw i32 %88, 24
%90 = or i32 %85, %89
%91 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i32 %54)
%92 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i32 %72)
%93 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i32 %90)
%94 = tail call dereferenceable_or_null(2097152) i8* @malloc(i32 2097152)
store i64 2097152, i64* %3
%95 = add i32 %54, 16
%96 = zext i32 %95 to i64
%97 = getelementptr inbounds i8, i8* %22, i64 %96
%98 = call i32 @uncompress(i8* %94, i64* %3, i8* %97, i32 %72)
%99 = load i64, i64* %3
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i64 %99)
%101 = getelementptr inbounds i8*, i8** %1, i64 2
%102 = load i8*, i8** %101
%103 = call i32* @fopen(i8* %102, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%104 = icmp eq i32* %103, null
br i1 %104, label %107, label %110
105: ; preds = %31, %27, %16
%106 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %116
107: ; preds = %35
%108 = load i8*, i8** %101
%109 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.11, i64 0, i64 0), i8* %108)
br label %116
110: ; preds = %35
%111 = load i64, i64* %3
%112 = call i32 @fwrite(i8* %94, i32 1, i64 %111, i32* %103)
%113 = call i32 @fclose(i32* %103)
%114 = call i32 @free(i8* %94)
%115 = call i32 @free(i8* %22)
br label %116
116: ; preds = %110, %107, %105, %14, %6
%117 = phi i32 [ -1, %6 ], [ -1, %14 ], [ -1, %107 ], [ 0, %110 ], [ -1, %105 ]
ret i32 %117
}