#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*/ *decrypt_tsc(char *);
int /*<<< orphan*/ do_script(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("Usage: tscomp <tsc file> <output file>\n");
    return 0;
  }
  FILE *infile, *outfile;
  if ((infile = decrypt_tsc(argv[1])) == NULL) {
    printf("Failed to open decrypted file.\n");
    return 1;
  }
  if ((outfile = fopen(argv[2], "wb")) == NULL) {
    printf("Failed to open output file.\n");
    return 1;
  }
  do_script(infile, outfile);
  fclose(infile);
  fclose(outfile);
  return 0;
}


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)
cmpl   $0x3,-0x8(%rbp)
je     1188 <main+0x38>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    121b <main+0xcb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <decrypt_tsc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11bb <main+0x6b>
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    121b <main+0xcb>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe7e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11f5 <main+0xa5>
lea    0xe67(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    121b <main+0xcb>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <do_script@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x3,%edi
jne    11a3 <main+0x53>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1050 <decrypt_tsc@plt>
test   %rax,%rax
je     11b3 <main+0x63>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
lea    0xe87(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11bc <main+0x6c>
mov    %rax,%r14
mov    %r15,%rdi
mov    %rax,%rsi
call   1060 <do_script@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    11af <main+0x5f>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    11cd <main+0x7d>
lea    0xe65(%rip),%rdi
jmp    11c3 <main+0x73>
lea    0xe40(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Usage: tscomp <tsc file> <output file>\0A\00"
@.str.1 = [32 x i8] c"Failed to open decrypted file.\0A\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [29 x i8] c"Failed to open output file.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %36
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @decrypt_tsc(i8* %15)
store i32* %16, i32** %6
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %36
20: ; preds = %12
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %7
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %36
28: ; preds = %20
%29 = load i32*, i32** %6
%30 = load i32*, i32** %7
%31 = call i32 @do_script(i32* %29, i32* %30)
%32 = load i32*, i32** %6
%33 = call i32 @fclose(i32* %32)
%34 = load i32*, i32** %7
%35 = call i32 @fclose(i32* %34)
store i32 0, i32* %3
br label %36
36: ; preds = %28, %26, %18, %10
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"wb\00"
@str = [28 x i8] c"Failed to open output file.\00"
@str.4 = [31 x i8] c"Failed to open decrypted file.\00"
@str.5 = [39 x i8] c"Usage: tscomp <tsc file> <output file>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.5, i64 0, i64 0))
br label %24
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @decrypt_tsc(i8* %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.4, i64 0, i64 0))
br label %24
13: ; preds = %6
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %24
20: ; preds = %13
%21 = tail call i32 @do_script(i32* %9, i32* %16)
%22 = tail call i32 @fclose(i32* %9)
%23 = tail call i32 @fclose(i32* %16)
br label %24
24: ; preds = %11, %18, %20, %4
%25 = phi i32 [ 0, %4 ], [ 1, %11 ], [ 1, %18 ], [ 0, %20 ]
ret i32 %25
}