#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*/ exit(int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pack(char *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ unpack(char *, char *, char *);
int main(int argc, char *argv[]) {
  setbuf(stdout, NULL);
  fputs("\n"
        "Zanzarah PAK files unpacker/repacker "
        "0.1"
        "\n"
        "by Luigi Auriemma\n"
        "e-mail: aluigi@autistici.org\n"
        "web:    aluigi.org\n"
        "\n",
        stdout);
  if (argc < 5) {
    printf(
        "\n"
        "Usage: %s <command>\n"
        "\n"
        "Commands:\n"
        " u <input.PAK> <output_directory> <output_listfile>\n"
        " p <input_listfile> <input_directory> <output.PAK>\n"
        "\n"
        "Explanation:\n"
        " u must be used to unpack a PAK file and you must specify just the "
        "filename,\n"
        " the output directory in which will be extracted the files and the "
        "name of a\n"
        " text file that will contain the names of these files and other "
        "informations\n"
        " for rebuilding the PAK file later\n"
        "\n"
        " p instead is used to rebuild the PAK file, you must specify the "
        "listfile\n"
        " previously created, the directory in which are located all the "
        "extracted\n"
        " files and the name of the PAK file you want to create.\n"
        "\n"
        " Remember that if the files already exist they will be overwritten.\n"
        "\n",
        argv[0]);
    exit(1);
  }
  switch (argv[1][0]) {
  case 'u':
    unpack(argv[2], argv[3], argv[4]);
    break;
  case 'p':
    pack(argv[2], argv[3], argv[4]);
    break;
  default: {
    fputs("\nError: you must choose the option u or p, check the details at "
          "runtime\n\n",
          stdout);
    exit(1);
  }
  }
  fputs("\n- Finished\n", stdout);
  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)
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <setbuf@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdi
call   1060 <fputs@plt>
cmpl   $0x5,-0x8(%rbp)
jge    11c4 <main+0x64>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xeb9(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
sub    $0x70,%eax
je     1213 <main+0xb3>
jmp    11e0 <main+0x80>
mov    -0x14(%rbp),%eax
sub    $0x75,%eax
jne    1235 <main+0xd5>
jmp    11f1 <main+0x91>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
call   1070 <unpack@plt>
jmp    1254 <main+0xf4>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
call   1030 <pack@plt>
jmp    1254 <main+0xf4>
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
lea    0x10dc(%rip),%rdi
call   1060 <fputs@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%esi
lea    0x1107(%rip),%rdi
call   1060 <fputs@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e70(%rip),%r14
mov    (%r14),%edi
xor    %esi,%esi
call   1040 <setbuf@plt>
mov    (%r14),%esi
lea    0xe7c(%rip),%rdi
call   1060 <fputs@plt>
cmp    $0x4,%ebp
jle    11d9 <main+0x79>
mov    0x8(%rbx),%rax
movsbl (%rax),%eax
cmp    $0x70,%eax
je     11b2 <main+0x52>
cmp    $0x75,%eax
jne    11f2 <main+0x92>
mov    0x10(%rbx),%rdi
mov    0x18(%rbx),%rsi
mov    0x20(%rbx),%rdx
call   1070 <unpack@plt>
jmp    11c3 <main+0x63>
mov    0x10(%rbx),%rdi
mov    0x18(%rbx),%rsi
mov    0x20(%rbx),%rdx
call   1030 <pack@plt>
mov    (%r14),%esi
lea    0x119e(%rip),%rdi
call   1060 <fputs@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xe8b(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    (%r14),%esi
lea    0x1125(%rip),%rdi
call   1060 <fputs@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [110 x i8] c"\0AZanzarah PAK files unpacker/repacker 0.1\0Aby Luigi Auriemma\0Ae-mail: aluigi@autistici.org\0Aweb: aluigi.org\0A\0A\00"
@.str.1 = [691 x i8] c"\0AUsage: %s <command>\0A\0ACommands:\0A u <input.PAK> <output_directory> <output_listfile>\0A p <input_listfile> <input_directory> <output.PAK>\0A\0AExplanation:\0A u must be used to unpack a PAK file and you must specify just the filename,\0A the output directory in which will be extracted the files and the name of a\0A text file that will contain the names of these files and other informations\0A for rebuilding the PAK file later\0A\0A p instead is used to rebuild the PAK file, you must specify the listfile\0A previously created, the directory in which are located all the extracted\0A files and the name of the PAK file you want to create.\0A\0A Remember that if the files already exist they will be overwritten.\0A\0A\00"
@.str.2 = [74 x i8] c"\0AError: you must choose the option u or p, check the details at runtime\0A\0A\00"
@.str.3 = [13 x i8] c"\0A- Finished\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* @stdout
%7 = call i32 @setbuf(i32 %6, i32* null)
%8 = load i32, i32* @stdout
%9 = call i32 @fputs(i8* getelementptr inbounds ([110 x i8], [110 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 5
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @printf(i8* getelementptr inbounds ([691 x i8], [691 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
switch i32 %24, label %47 [
i32 117, label %25
i32 112, label %36
]
25: ; preds = %18
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 3
%31 = load i8*, i8** %30
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 4
%34 = load i8*, i8** %33
%35 = call i32 @unpack(i8* %28, i8* %31, i8* %34)
br label %51
36: ; preds = %18
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 3
%42 = load i8*, i8** %41
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 4
%45 = load i8*, i8** %44
%46 = call i32 @pack(i8* %39, i8* %42, i8* %45)
br label %51
47: ; preds = %18
%48 = load i32, i32* @stdout
%49 = call i32 @fputs(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0), i32 %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %36, %25
%52 = load i32, i32* @stdout
%53 = call i32 @fputs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %52)
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [110 x i8] c"\0AZanzarah PAK files unpacker/repacker 0.1\0Aby Luigi Auriemma\0Ae-mail: aluigi@autistici.org\0Aweb: aluigi.org\0A\0A\00"
@.str.1 = [691 x i8] c"\0AUsage: %s <command>\0A\0ACommands:\0A u <input.PAK> <output_directory> <output_listfile>\0A p <input_listfile> <input_directory> <output.PAK>\0A\0AExplanation:\0A u must be used to unpack a PAK file and you must specify just the filename,\0A the output directory in which will be extracted the files and the name of a\0A text file that will contain the names of these files and other informations\0A for rebuilding the PAK file later\0A\0A p instead is used to rebuild the PAK file, you must specify the listfile\0A previously created, the directory in which are located all the extracted\0A files and the name of the PAK file you want to create.\0A\0A Remember that if the files already exist they will be overwritten.\0A\0A\00"
@.str.2 = [74 x i8] c"\0AError: you must choose the option u or p, check the details at runtime\0A\0A\00"
@.str.3 = [13 x i8] c"\0A- Finished\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @stdout
%4 = tail call i32 @setbuf(i32 %3, i32* null)
%5 = load i32, i32* @stdout
%6 = tail call i32 @fputs(i8* getelementptr inbounds ([110 x i8], [110 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %0, 5
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([691 x i8], [691 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
switch i32 %16, label %33 [
i32 117, label %17
i32 112, label %25
]
17: ; preds = %12
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8*, i8** %1, i64 3
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8*, i8** %1, i64 4
%23 = load i8*, i8** %22
%24 = tail call i32 @unpack(i8* %19, i8* %21, i8* %23)
br label %37
25: ; preds = %12
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8*, i8** %1, i64 3
%29 = load i8*, i8** %28
%30 = getelementptr inbounds i8*, i8** %1, i64 4
%31 = load i8*, i8** %30
%32 = tail call i32 @pack(i8* %27, i8* %29, i8* %31)
br label %37
33: ; preds = %12
%34 = load i32, i32* @stdout
%35 = tail call i32 @fputs(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = tail call i32 @exit(i32 1)
unreachable
37: ; preds = %25, %17
%38 = load i32, i32* @stdout
%39 = tail call i32 @fputs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %38)
ret i32 0
}