#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*/ exportDir;

/* Variables and functions */
scalar_t__ CheckExtension(char *, char *);
int /*<<< orphan*/ GetFilenameWithoutExt(char *, int, char *);
int Hd2Unpack(char *, char *, char *);
int Hd3Unpack(char *, char *, char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  printf("White Cloud - Dark Cloud's HD2/HD3 unpacker\n"
         "Developed by Luciano Ciccariello (Xeeynamo)\n\n");
  if (argc == 3) {
    int hd2Pos;
    int hd3Pos;
    int datPos;
    hd2Pos = CheckExtension(argv[1], ".HD2") == 0   ? 1
             : CheckExtension(argv[2], ".HD2") == 0 ? 2
                                                    : 0;
    hd3Pos = CheckExtension(argv[1], ".HD3") == 0   ? 1
             : CheckExtension(argv[2], ".HD3") == 0 ? 2
                                                    : 0;
    datPos = CheckExtension(argv[1], ".DAT") == 0   ? 1
             : CheckExtension(argv[2], ".DAT") == 0 ? 2
                                                    : 0;
    if (hd3Pos != 0) {
      if (hd3Pos != 0 && datPos != 0 && hd3Pos != datPos) {
        char exportDir[260];
        GetFilenameWithoutExt(exportDir, sizeof(exportDir), argv[hd3Pos]);
        return Hd3Unpack(argv[datPos], argv[hd3Pos], exportDir);
      }
    } else {
      if (hd2Pos != 0 && datPos != 0 && hd2Pos != datPos) {
        char exportDir[260];
        GetFilenameWithoutExt(exportDir, sizeof(exportDir), argv[hd2Pos]);
        return Hd2Unpack(argv[datPos], argv[hd2Pos], exportDir);
      }
    }
  }
  printf("Usage:"
         "\twhitecloud <data.dat> (<data.hd3> | <data.hd2)\n"
         "\twhitecloud (<data.hd3> | <data.hd2) <data.dat>\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x3,-0x8(%rbp)
jne    1390 <main+0x240>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xecc(%rip),%rsi
call   1050 <CheckExtension@plt>
cmp    $0x0,%rax
jne    11ad <main+0x5d>
mov    $0x1,%eax
mov    %eax,-0x234(%rbp)
jmp    11d8 <main+0x88>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe9e(%rip),%rsi
call   1050 <CheckExtension@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x2,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x234(%rbp)
mov    -0x234(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6f(%rip),%rsi
call   1050 <CheckExtension@plt>
cmp    $0x0,%rax
jne    120f <main+0xbf>
mov    $0x1,%eax
mov    %eax,-0x238(%rbp)
jmp    123a <main+0xea>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe41(%rip),%rsi
call   1050 <CheckExtension@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x2,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x238(%rbp)
mov    -0x238(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe12(%rip),%rsi
call   1050 <CheckExtension@plt>
cmp    $0x0,%rax
jne    1271 <main+0x121>
mov    $0x1,%eax
mov    %eax,-0x23c(%rbp)
jmp    129c <main+0x14c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xde4(%rip),%rsi
call   1050 <CheckExtension@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x2,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x23c(%rbp)
mov    -0x23c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     131d <main+0x1cd>
cmpl   $0x0,-0x18(%rbp)
je     1318 <main+0x1c8>
cmpl   $0x0,-0x1c(%rbp)
je     1318 <main+0x1c8>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1318 <main+0x1c8>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    $0x104,%esi
call   1060 <GetFilenameWithoutExt@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    -0x120(%rbp),%rdx
call   1030 <Hd3Unpack@plt>
mov    %eax,-0x4(%rbp)
jmp    13a3 <main+0x253>
jmp    138b <main+0x23b>
cmpl   $0x0,-0x14(%rbp)
je     1386 <main+0x236>
cmpl   $0x0,-0x1c(%rbp)
je     1386 <main+0x236>
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1386 <main+0x236>
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    $0x104,%esi
call   1060 <GetFilenameWithoutExt@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    -0x230(%rbp),%rdx
call   1070 <Hd2Unpack@plt>
mov    %eax,-0x4(%rbp)
jmp    13a3 <main+0x253>
jmp    138b <main+0x23b>
jmp    1390 <main+0x240>
lea    0xcd2(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x3,%ebp
jne    128b <main+0x13b>
mov    0x8(%r15),%rdi
lea    0xe7e(%rip),%rsi
call   1050 <CheckExtension@plt>
mov    $0x1,%ebp
mov    $0x1,%r14d
test   %rax,%rax
je     11b4 <main+0x64>
mov    0x10(%r15),%rdi
lea    0xe5e(%rip),%rsi
call   1050 <CheckExtension@plt>
xor    %r14d,%r14d
test   %rax,%rax
sete   %r14b
add    %r14d,%r14d
mov    0x8(%r15),%rdi
lea    0xe46(%rip),%rsi
call   1050 <CheckExtension@plt>
test   %rax,%rax
je     11e4 <main+0x94>
mov    0x10(%r15),%rdi
lea    0xe31(%rip),%rsi
call   1050 <CheckExtension@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
add    %ebp,%ebp
mov    0x8(%r15),%rdi
lea    0xe1b(%rip),%rsi
call   1050 <CheckExtension@plt>
test   %rax,%rax
je     1249 <main+0xf9>
mov    0x10(%r15),%rdi
lea    0xe06(%rip),%rsi
call   1050 <CheckExtension@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
add    %ebx,%ebx
test   %ebp,%ebp
je     1252 <main+0x102>
test   %ebx,%ebx
je     128b <main+0x13b>
cmp    %ebx,%ebp
je     128b <main+0x13b>
mov    %ebp,%ebp
mov    (%r15,%rbp,8),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x104,%esi
call   1060 <GetFilenameWithoutExt@plt>
mov    %ebx,%eax
mov    (%r15,%rax,8),%rdi
mov    (%r15,%rbp,8),%rsi
mov    %r14,%rdx
call   1040 <Hd3Unpack@plt>
jmp    129c <main+0x14c>
mov    $0x1,%ebx
test   %ebp,%ebp
jne    1217 <main+0xc7>
test   %r14d,%r14d
je     128b <main+0x13b>
test   %ebx,%ebx
je     128b <main+0x13b>
cmp    %ebx,%r14d
je     128b <main+0x13b>
mov    %r14d,%ebp
mov    (%r15,%rbp,8),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x104,%esi
call   1060 <GetFilenameWithoutExt@plt>
mov    %ebx,%eax
mov    (%r15,%rax,8),%rdi
mov    (%r15,%rbp,8),%rsi
mov    %r14,%rdx
call   1070 <Hd2Unpack@plt>
jmp    129c <main+0x14c>
lea    0xdd6(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [90 x i8] c"White Cloud - Dark Cloud's HD2/HD3 unpacker\0ADeveloped by Luciano Ciccariello (Xeeynamo)\0A\0A\00"
@.str.1 = [5 x i8] c".HD2\00"
@.str.2 = [5 x i8] c".HD3\00"
@.str.3 = [5 x i8] c".DAT\00"
@.str.4 = [103 x i8] c"Usage:\09whitecloud <data.dat> (<data.hd3> | <data.hd2)\0A\09whitecloud (<data.hd3> | <data.hd2) <data.dat>\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 [260 x i8]
%10 = alloca [260 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 @printf(i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 3
br i1 %13, label %14, label %128
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @CheckExtension(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %14
br label %29
21: ; preds = %14
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i64 @CheckExtension(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 2, i32 0
br label %29
29: ; preds = %21, %20
%30 = phi i32 [ 1, %20 ], [ %28, %21 ]
store i32 %30, i32* %6
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i64 @CheckExtension(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %29
br label %45
37: ; preds = %29
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i64 @CheckExtension(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
%43 = zext i1 %42 to i64
%44 = select i1 %42, i32 2, i32 0
br label %45
45: ; preds = %37, %36
%46 = phi i32 [ 1, %36 ], [ %44, %37 ]
store i32 %46, i32* %7
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i64 @CheckExtension(i8* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %45
br label %61
53: ; preds = %45
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 2
%56 = load i8*, i8** %55
%57 = call i64 @CheckExtension(i8* %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%58 = icmp eq i64 %57, 0
%59 = zext i1 %58 to i64
%60 = select i1 %58, i32 2, i32 0
br label %61
61: ; preds = %53, %52
%62 = phi i32 [ 1, %52 ], [ %60, %53 ]
store i32 %62, i32* %8
%63 = load i32, i32* %7
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %96
65: ; preds = %61
%66 = load i32, i32* %7
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %95
68: ; preds = %65
%69 = load i32, i32* %8
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %95
71: ; preds = %68
%72 = load i32, i32* %7
%73 = load i32, i32* %8
%74 = icmp ne i32 %72, %73
br i1 %74, label %75, label %95
75: ; preds = %71
%76 = getelementptr inbounds [260 x i8], [260 x i8]* %9, i64 0, i64 0
%77 = load i8**, i8*** %5
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8*, i8** %77, i64 %79
%81 = load i8*, i8** %80
%82 = call i32 @GetFilenameWithoutExt(i8* %76, i32 260, i8* %81)
%83 = load i8**, i8*** %5
%84 = load i32, i32* %8
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8*, i8** %83, i64 %85
%87 = load i8*, i8** %86
%88 = load i8**, i8*** %5
%89 = load i32, i32* %7
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i8*, i8** %88, i64 %90
%92 = load i8*, i8** %91
%93 = getelementptr inbounds [260 x i8], [260 x i8]* %9, i64 0, i64 0
%94 = call i32 @Hd3Unpack(i8* %87, i8* %92, i8* %93)
store i32 %94, i32* %3
br label %130
95: ; preds = %71, %68, %65
br label %127
96: ; preds = %61
%97 = load i32, i32* %6
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %126
99: ; preds = %96
%100 = load i32, i32* %8
%101 = icmp ne i32 %100, 0
br i1 %101, label %102, label %126
102: ; preds = %99
%103 = load i32, i32* %6
%104 = load i32, i32* %8
%105 = icmp ne i32 %103, %104
br i1 %105, label %106, label %126
106: ; preds = %102
%107 = getelementptr inbounds [260 x i8], [260 x i8]* %10, i64 0, i64 0
%108 = load i8**, i8*** %5
%109 = load i32, i32* %6
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i8*, i8** %108, i64 %110
%112 = load i8*, i8** %111
%113 = call i32 @GetFilenameWithoutExt(i8* %107, i32 260, i8* %112)
%114 = load i8**, i8*** %5
%115 = load i32, i32* %8
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i8*, i8** %114, i64 %116
%118 = load i8*, i8** %117
%119 = load i8**, i8*** %5
%120 = load i32, i32* %6
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds i8*, i8** %119, i64 %121
%123 = load i8*, i8** %122
%124 = getelementptr inbounds [260 x i8], [260 x i8]* %10, i64 0, i64 0
%125 = call i32 @Hd2Unpack(i8* %118, i8* %123, i8* %124)
store i32 %125, i32* %3
br label %130
126: ; preds = %102, %99, %96
br label %127
127: ; preds = %126, %95
br label %128
128: ; preds = %127, %2
%129 = call i32 @printf(i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %130
130: ; preds = %128, %106, %75
%131 = load i32, i32* %3
ret i32 %131
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c".HD2\00"
@.str.2 = [5 x i8] c".HD3\00"
@.str.3 = [5 x i8] c".DAT\00"
@str = [89 x i8] c"White Cloud - Dark Cloud's HD2/HD3 unpacker\0ADeveloped by Luciano Ciccariello (Xeeynamo)\0A\00"
@str.5 = [102 x i8] c"Usage:\09whitecloud <data.dat> (<data.hd3> | <data.hd2)\0A\09whitecloud (<data.hd3> | <data.hd2) <data.dat>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [260 x i8]
%4 = alloca [260 x i8]
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([89 x i8], [89 x i8]* @str, i64 0, i64 0))
%6 = icmp eq i32 %0, 3
br i1 %6, label %7, label %75
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @CheckExtension(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i64 @CheckExtension(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
%17 = select i1 %16, i32 2, i32 0
br label %18
18: ; preds = %7, %12
%19 = phi i32 [ %17, %12 ], [ 1, %7 ]
%20 = load i8*, i8** %8
%21 = tail call i64 @CheckExtension(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %18
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = tail call i64 @CheckExtension(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
%28 = select i1 %27, i32 2, i32 0
br label %29
29: ; preds = %18, %23
%30 = phi i32 [ %28, %23 ], [ 1, %18 ]
%31 = load i8*, i8** %8
%32 = tail call i64 @CheckExtension(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %40, label %34
34: ; preds = %29
%35 = getelementptr inbounds i8*, i8** %1, i64 2
%36 = load i8*, i8** %35
%37 = tail call i64 @CheckExtension(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
%39 = select i1 %38, i32 2, i32 0
br label %40
40: ; preds = %29, %34
%41 = phi i32 [ %39, %34 ], [ 1, %29 ]
%42 = icmp eq i32 %30, 0
br i1 %42, label %58, label %43
43: ; preds = %40
%44 = icmp eq i32 %41, 0
%45 = icmp eq i32 %30, %41
%46 = select i1 %44, i1 true, i1 %45
br i1 %46, label %75, label %47
47: ; preds = %43
%48 = getelementptr inbounds [260 x i8], [260 x i8]* %3, i64 0, i64 0
%49 = zext i32 %30 to i64
%50 = getelementptr inbounds i8*, i8** %1, i64 %49
%51 = load i8*, i8** %50
%52 = call i32 @GetFilenameWithoutExt(i8* %48, i32 260, i8* %51)
%53 = zext i32 %41 to i64
%54 = getelementptr inbounds i8*, i8** %1, i64 %53
%55 = load i8*, i8** %54
%56 = load i8*, i8** %50
%57 = call i32 @Hd3Unpack(i8* %55, i8* %56, i8* %48)
br label %77
58: ; preds = %40
%59 = icmp eq i32 %19, 0
%60 = icmp eq i32 %41, 0
%61 = select i1 %59, i1 true, i1 %60
%62 = icmp eq i32 %19, %41
%63 = select i1 %61, i1 true, i1 %62
br i1 %63, label %75, label %64
64: ; preds = %58
%65 = getelementptr inbounds [260 x i8], [260 x i8]* %4, i64 0, i64 0
%66 = zext i32 %19 to i64
%67 = getelementptr inbounds i8*, i8** %1, i64 %66
%68 = load i8*, i8** %67
%69 = call i32 @GetFilenameWithoutExt(i8* %65, i32 260, i8* %68)
%70 = zext i32 %41 to i64
%71 = getelementptr inbounds i8*, i8** %1, i64 %70
%72 = load i8*, i8** %71
%73 = load i8*, i8** %67
%74 = call i32 @Hd2Unpack(i8* %72, i8* %73, i8* %65)
br label %77
75: ; preds = %43, %58, %2
%76 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([102 x i8], [102 x i8]* @str.5, i64 0, i64 0))
br label %77
77: ; preds = %47, %64, %75
%78 = phi i32 [ 1, %75 ], [ %57, %47 ], [ %74, %64 ]
ret i32 %78
}