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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ std_err();
int strlen(char *);
int /*<<< orphan*/ usage(char *);
int /*<<< orphan*/ write_output_file(char *, int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ xtx_crypt(int *, int);
int main(int argc, char *argv[]) {
  uint8_t decrypt = 0;
  uint8_t encrypt = 0;
  uint32_t buffer_size = 0;
  FILE *pFile;
  printf("\n");
  printf("     Gangsters Organized Crime xtx decryption tool by Fredric "
         "Baeckstrom  \n");
  printf("  ======================================================= version %s "
         "===\n\n",
         "1.0.0");
  if (argc < 4) {
    usage(argv[0]);
    return (-1);
  }
  argc -= 2;
  for (int i = 1; i < argc; i++) {
    if (((argv[i][0] != '-') && (argv[i][0] != '/')) ||
        (strlen(argv[i]) != 2)) {
      printf("\nError: recheck your options, %s is not valid\n", argv[i]);
      exit(1);
    }
    switch (argv[i][1]) {
    case 'd':
      decrypt = 1;
      break;
    case 'e':
      encrypt = 1;
      break;
    default: {
      printf("\nError: wrong command-line argument (%s)\n\n", argv[i]);
      exit(1);
      break;
    }
    }
  }
  char *file_input = argv[argc];
  char *file_output = argv[argc + 1];
  printf("- Open input file:    %s\n", file_input);
  pFile = fopen(file_input, "rb");
  if (!pFile)
    std_err();
  fseek(pFile, 0L, SEEK_END);
  buffer_size = ftell(pFile);
  fseek(pFile, 0L, SEEK_SET);
  char *buffer = (char *)malloc(buffer_size);
  memset(buffer, 0, buffer_size);
  fread(buffer, 1, buffer_size, pFile);
  fclose(pFile);
  printf("- Data size: 0x%08x  (%u)\n", buffer_size, buffer_size);
  if (decrypt) {
    xtx_crypt((uint8_t *)buffer, buffer_size);
    write_output_file((char *)file_output, 0, (char *)buffer, buffer_size);
    printf("\n- Writing data to file, done.\n");
    free(buffer);
  } else if (encrypt) {
    xtx_crypt((uint8_t *)buffer, buffer_size);
    write_output_file((char *)file_output, 0, (char *)buffer, buffer_size);
    printf("\n- Writing data to file, done.\n");
    free(buffer);
  }
}


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)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe0e(%rip),%rdi
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x4,-0x8(%rbp)
jge    126e <main+0x7e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10e0 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14e2 <main+0x2f2>
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1379 <main+0x189>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     12ba <main+0xca>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    12d4 <main+0xe4>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <strlen@plt>
cmp    $0x2,%eax
je     12f8 <main+0x108>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x4c(%rbp)
sub    $0x64,%eax
je     132a <main+0x13a>
jmp    1319 <main+0x129>
mov    -0x4c(%rbp),%eax
sub    $0x65,%eax
je     1336 <main+0x146>
jmp    1342 <main+0x152>
movl   $0x1,-0x14(%rbp)
jmp    1366 <main+0x176>
movl   $0x1,-0x18(%rbp)
jmp    1366 <main+0x176>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    136b <main+0x17b>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    127e <main+0x8e>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    0xd56(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    13d6 <main+0x1e6>
mov    $0x0,%al
call   1110 <std_err@plt>
mov    -0x28(%rbp),%rdi
mov    0x2c07(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10d0 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <ftell@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2bd5(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10d0 <fseek@plt>
mov    -0x1c(%rbp),%edi
call   10c0 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x48(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x1c(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xcc1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
je     149e <main+0x2ae>
mov    -0x48(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1090 <xtx_crypt@plt>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
xor    %esi,%esi
call   10a0 <write_output_file@plt>
lea    0xca6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
jmp    14e2 <main+0x2f2>
cmpl   $0x0,-0x18(%rbp)
je     14dd <main+0x2ed>
mov    -0x48(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1090 <xtx_crypt@plt>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
xor    %esi,%esi
call   10a0 <write_output_file@plt>
lea    0xc62(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
jmp    14e2 <main+0x2f2>
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
mov    %rsi,%rbx
mov    %edi,%r14d
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xeb1(%rip),%rdi
call   1050 <puts@plt>
lea    0xdc2(%rip),%rdi
lea    0xe06(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1090 <printf@plt>
cmp    $0x3,%r14d
jg     1267 <main+0x57>
mov    (%rbx),%rdi
call   1100 <usage@plt>
mov    $0xffffffff,%r15d
jmp    13df <main+0x1cf>
mov    %r14,(%rsp)
lea    -0x2(%r14),%r15d
mov    $0x1,%r13d
xor    %r14d,%r14d
jmp    128c <main+0x7c>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13
mov    %r12d,%ebp
cmp    %r13,%r15
je     12d5 <main+0xc5>
mov    (%rbx,%r13,8),%rsi
movzbl (%rsi),%eax
or     $0x2,%al
cmp    $0x2f,%al
jne    13f1 <main+0x1e1>
mov    %rsi,%rdi
call   1080 <strlen@plt>
mov    (%rbx,%r13,8),%rsi
cmp    $0x2,%eax
jne    13f1 <main+0x1e1>
movsbl 0x1(%rsi),%eax
mov    $0x1,%r12d
cmp    $0x64,%eax
je     1280 <main+0x70>
cmp    $0x65,%eax
jne    13fa <main+0x1ea>
mov    $0x1,%r14d
mov    %ebp,%r12d
jmp    1280 <main+0x70>
movslq %r15d,%rax
mov    (%rbx,%rax,8),%r15
mov    (%rsp),%rax
add    $0xffffffff,%eax
mov    (%rbx,%rax,8),%rax
mov    %rax,(%rsp)
lea    0xdb9(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xdc2(%rip),%rsi
mov    %r15,%rdi
call   1110 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    131a <main+0x10a>
xor    %eax,%eax
call   1130 <std_err@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
call   10f0 <fseek@plt>
mov    %rbx,%rdi
call   10d0 <ftell@plt>
mov    %eax,%r13d
mov    0x2c96(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10f0 <fseek@plt>
mov    %r13d,%edi
call   10e0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %r13d,%edx
call   10a0 <memset@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    %rbx,%rcx
call   1060 <fread@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
lea    0xd40(%rip),%rdi
mov    %r13d,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1090 <printf@plt>
test   %r12d,%r12d
je     13a7 <main+0x197>
mov    %rbp,%rdi
mov    %r13d,%esi
call   10b0 <xtx_crypt@plt>
jmp    13ba <main+0x1aa>
test   %r14d,%r14d
je     13df <main+0x1cf>
mov    %rbp,%rdi
mov    %r13d,%esi
call   10b0 <xtx_crypt@plt>
xor    %r15d,%r15d
mov    (%rsp),%rdi
xor    %esi,%esi
mov    %rbp,%rdx
mov    %r13d,%ecx
call   10c0 <write_output_file@plt>
lea    0xd5c(%rip),%rdi
call   1050 <puts@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc59(%rip),%rdi
jmp    1401 <main+0x1f1>
lea    0xc7f(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [76 x i8] c" Gangsters Organized Crime xtx decryption tool by Fredric Baeckstrom \0A\00"
@.str.2 = [75 x i8] c" ======================================================= version %s ===\0A\0A\00"
@.str.3 = [6 x i8] c"1.0.0\00"
@.str.4 = [47 x i8] c"\0AError: recheck your options, %s is not valid\0A\00"
@.str.5 = [43 x i8] c"\0AError: wrong command-line argument (%s)\0A\0A\00"
@.str.6 = [26 x i8] c"- Open input file: %s\0A\00"
@.str.7 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.8 = [27 x i8] c"- Data size: 0x%08x (%u)\0A\00"
@.str.9 = [32 x i8] c"\0A- Writing data to file, done.\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 i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 4
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 @usage(i8* %22)
store i32 -1, i32* %3
br label %164
24: ; preds = %2
%25 = load i32, i32* %4
%26 = sub nsw i32 %25, 2
store i32 %26, i32* %4
store i32 1, i32* %10
br label %27
27: ; preds = %87, %24
%28 = load i32, i32* %10
%29 = load i32, i32* %4
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %90
31: ; preds = %27
%32 = load i8**, i8*** %5
%33 = load i32, i32* %10
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
%36 = load i8*, i8** %35
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 45
br i1 %40, label %41, label %51
41: ; preds = %31
%42 = load i8**, i8*** %5
%43 = load i32, i32* %10
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
%46 = load i8*, i8** %45
%47 = getelementptr inbounds i8, i8* %46, i64 0
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 47
br i1 %50, label %59, label %51
51: ; preds = %41, %31
%52 = load i8**, i8*** %5
%53 = load i32, i32* %10
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = call i32 @strlen(i8* %56)
%58 = icmp ne i32 %57, 2
br i1 %58, label %59, label %67
59: ; preds = %51, %41
%60 = load i8**, i8*** %5
%61 = load i32, i32* %10
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8*, i8** %60, i64 %62
%64 = load i8*, i8** %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i8* %64)
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %51
%68 = load i8**, i8*** %5
%69 = load i32, i32* %10
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %68, i64 %70
%72 = load i8*, i8** %71
%73 = getelementptr inbounds i8, i8* %72, i64 1
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
switch i32 %75, label %78 [
i32 100, label %76
i32 101, label %77
]
76: ; preds = %67
store i32 1, i32* %6
br label %86
77: ; preds = %67
store i32 1, i32* %7
br label %86
78: ; preds = %67
%79 = load i8**, i8*** %5
%80 = load i32, i32* %10
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8*, i8** %79, i64 %81
%83 = load i8*, i8** %82
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %83)
%85 = call i32 @exit(i32 1)
unreachable
86: ; preds = %77, %76
br label %87
87: ; preds = %86
%88 = load i32, i32* %10
%89 = add nsw i32 %88, 1
store i32 %89, i32* %10
br label %27
90: ; preds = %27
%91 = load i8**, i8*** %5
%92 = load i32, i32* %4
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8*, i8** %91, i64 %93
%95 = load i8*, i8** %94
store i8* %95, i8** %11
%96 = load i8**, i8*** %5
%97 = load i32, i32* %4
%98 = add nsw i32 %97, 1
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i8*, i8** %96, i64 %99
%101 = load i8*, i8** %100
store i8* %101, i8** %12
%102 = load i8*, i8** %11
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %102)
%104 = load i8*, i8** %11
%105 = call i32* @fopen(i8* %104, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i32* %105, i32** %9
%106 = load i32*, i32** %9
%107 = icmp ne i32* %106, null
br i1 %107, label %110, label %108
108: ; preds = %90
%109 = call i32 (...) @std_err()
br label %110
110: ; preds = %108, %90
%111 = load i32*, i32** %9
%112 = load i32, i32* @SEEK_END
%113 = call i32 @fseek(i32* %111, i64 0, i32 %112)
%114 = load i32*, i32** %9
%115 = call i32 @ftell(i32* %114)
store i32 %115, i32* %8
%116 = load i32*, i32** %9
%117 = load i32, i32* @SEEK_SET
%118 = call i32 @fseek(i32* %116, i64 0, i32 %117)
%119 = load i32, i32* %8
%120 = call i64 @malloc(i32 %119)
%121 = inttoptr i64 %120 to i8*
store i8* %121, i8** %13
%122 = load i8*, i8** %13
%123 = load i32, i32* %8
%124 = call i32 @memset(i8* %122, i32 0, i32 %123)
%125 = load i8*, i8** %13
%126 = load i32, i32* %8
%127 = load i32*, i32** %9
%128 = call i32 @fread(i8* %125, i32 1, i32 %126, i32* %127)
%129 = load i32*, i32** %9
%130 = call i32 @fclose(i32* %129)
%131 = load i32, i32* %8
%132 = load i32, i32* %8
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i32 %131, i32 %132)
%134 = load i32, i32* %6
%135 = icmp ne i32 %134, 0
br i1 %135, label %136, label %148
136: ; preds = %110
%137 = load i8*, i8** %13
%138 = bitcast i8* %137 to i32*
%139 = load i32, i32* %8
%140 = call i32 @xtx_crypt(i32* %138, i32 %139)
%141 = load i8*, i8** %12
%142 = load i8*, i8** %13
%143 = load i32, i32* %8
%144 = call i32 @write_output_file(i8* %141, i32 0, i8* %142, i32 %143)
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0))
%146 = load i8*, i8** %13
%147 = call i32 @free(i8* %146)
br label %164
148: ; preds = %110
%149 = load i32, i32* %7
%150 = icmp ne i32 %149, 0
br i1 %150, label %151, label %163
151: ; preds = %148
%152 = load i8*, i8** %13
%153 = bitcast i8* %152 to i32*
%154 = load i32, i32* %8
%155 = call i32 @xtx_crypt(i32* %153, i32 %154)
%156 = load i8*, i8** %12
%157 = load i8*, i8** %13
%158 = load i32, i32* %8
%159 = call i32 @write_output_file(i8* %156, i32 0, i8* %157, i32 %158)
%160 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0))
%161 = load i8*, i8** %13
%162 = call i32 @free(i8* %161)
br label %163
163: ; preds = %151, %148
br label %164
164: ; preds = %19, %163, %136
%165 = load i32, i32* %3
ret i32 %165
}

LLVM IR (-O2):
@.str.2 = [75 x i8] c" ======================================================= version %s ===\0A\0A\00"
@.str.3 = [6 x i8] c"1.0.0\00"
@.str.4 = [47 x i8] c"\0AError: recheck your options, %s is not valid\0A\00"
@.str.5 = [43 x i8] c"\0AError: wrong command-line argument (%s)\0A\0A\00"
@.str.6 = [26 x i8] c"- Open input file: %s\0A\00"
@.str.7 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.8 = [27 x i8] c"- Data size: 0x%08x (%u)\0A\00"
@str = [75 x i8] c" Gangsters Organized Crime xtx decryption tool by Fredric Baeckstrom \00"
@str.11 = [31 x i8] c"\0A- Writing data to file, done.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @putchar(i32 10)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%6 = icmp slt i32 %0, 4
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 @usage(i8* %8)
br label %81
10: ; preds = %2
%11 = add nsw i32 %0, -2
%12 = zext i32 %11 to i64
br label %24
13: ; preds = %47
%14 = sext i32 %11 to i64
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
%16 = load i8*, i8** %15
%17 = add nsw i32 %0, -1
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %16)
%22 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %52, label %54
24: ; preds = %10, %47
%25 = phi i64 [ 1, %10 ], [ %50, %47 ]
%26 = phi i32 [ 0, %10 ], [ %49, %47 ]
%27 = phi i32 [ 0, %10 ], [ %48, %47 ]
%28 = getelementptr inbounds i8*, i8** %1, i64 %25
%29 = load i8*, i8** %28
%30 = load i8, i8* %29
switch i8 %30, label %35 [
i8 45, label %31
i8 47, label %31
]
31: ; preds = %24, %24
%32 = tail call i32 @strlen(i8* %29)
%33 = icmp eq i32 %32, 2
%34 = load i8*, i8** %28
br i1 %33, label %39, label %35
35: ; preds = %24, %31
%36 = phi i8* [ %34, %31 ], [ %29, %24 ]
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i8* %36)
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %31
%40 = getelementptr inbounds i8, i8* %34, i64 1
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
switch i32 %42, label %44 [
i32 100, label %47
i32 101, label %43
]
43: ; preds = %39
br label %47
44: ; preds = %39
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %34)
%46 = tail call i32 @exit(i32 1)
unreachable
47: ; preds = %39, %43
%48 = phi i32 [ 1, %43 ], [ %27, %39 ]
%49 = phi i32 [ %26, %43 ], [ 1, %39 ]
%50 = add nuw nsw i64 %25, 1
%51 = icmp eq i64 %50, %12
br i1 %51, label %13, label %24
52: ; preds = %13
%53 = tail call i32 (...) @std_err()
br label %54
54: ; preds = %52, %13
%55 = load i32, i32* @SEEK_END
%56 = tail call i32 @fseek(i32* %22, i64 0, i32 %55)
%57 = tail call i32 @ftell(i32* %22)
%58 = load i32, i32* @SEEK_SET
%59 = tail call i32 @fseek(i32* %22, i64 0, i32 %58)
%60 = tail call i64 @malloc(i32 %57)
%61 = inttoptr i64 %60 to i8*
%62 = tail call i32 @memset(i8* %61, i32 0, i32 %57)
%63 = tail call i32 @fread(i8* %61, i32 1, i32 %57, i32* %22)
%64 = tail call i32 @fclose(i32* %22)
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i32 %57, i32 %57)
%66 = icmp eq i32 %49, 0
br i1 %66, label %73, label %67
67: ; preds = %54
%68 = inttoptr i64 %60 to i32*
%69 = tail call i32 @xtx_crypt(i32* %68, i32 %57)
%70 = tail call i32 @write_output_file(i8* %20, i32 0, i8* %61, i32 %57)
%71 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.11, i64 0, i64 0))
%72 = tail call i32 @free(i8* %61)
br label %81
73: ; preds = %54
%74 = icmp eq i32 %48, 0
br i1 %74, label %81, label %75
75: ; preds = %73
%76 = inttoptr i64 %60 to i32*
%77 = tail call i32 @xtx_crypt(i32* %76, i32 %57)
%78 = tail call i32 @write_output_file(i8* %20, i32 0, i8* %61, i32 %57)
%79 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.11, i64 0, i64 0))
%80 = tail call i32 @free(i8* %61)
br label %81
81: ; preds = %67, %75, %73, %7
%82 = phi i32 [ -1, %7 ], [ 0, %73 ], [ 0, %75 ], [ 0, %67 ]
ret i32 %82
}