// File: blackle[P]LZMA-Vizualizer/LzmaSpec.cpp
// Function: main
int main(int argc, char** argv)
{
  int r = parse_args(argc, argv);
  if (r >= 0) return r;

  CInputStream inStream;
  inStream.File = fopen(options.infile.c_str(), "rb");
  if (inStream.File == 0)
    throw "Can't open input file";
  inStream.Init();

  CLzmaDecoder lzmaDecoder;

  Byte header[13];
  int i;
  for (i = 0; i < 13; i++)
    header[i] = inStream.ReadByte();

  lzmaDecoder.DecodeProperties(header);

  UInt64 unpackSize = 0;
  bool unpackSizeDefined = false;
  for (i = 0; i < 8; i++)
  {
    Byte b = header[5 + i];
    if (b != 0xFF)
      unpackSizeDefined = true;
    unpackSize |= (UInt64)b << (8 * i);
  }

  lzmaDecoder.markerIsMandatory = !unpackSizeDefined;

  lzmaDecoder.RangeDec.InStream = &inStream;

  lzmaDecoder.Create();

  int res = lzmaDecoder.Decode(unpackSizeDefined, unpackSize);

  if (res == LZMA_RES_ERROR)
    throw "LZMA decoding error";

  if (lzmaDecoder.RangeDec.Corrupted)
  {
    std::cerr << "Warning: LZMA stream is corrupted" << std::endl;
  }

  double maxPerplexity = *std::max_element(lzmaDecoder.Perplexities.begin(), lzmaDecoder.Perplexities.end());

  if (!options.kkpout.empty()) {
    return output_kkp(lzmaDecoder, maxPerplexity);
  } else if (options.pretty) {
    return output_console(lzmaDecoder, maxPerplexity);
  } else {
    return output_raw(lzmaDecoder, maxPerplexity);
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xfd0, %rsp            # imm = 0xFD0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x3100
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jl 0x2d79
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x30da
leaq 0xd400(%rip), %rdi      # 0x10180
callq 0x2080
movq %rax, %rdi
leaq 0x82e1(%rip), %rsi      # 0xb070
callq 0x21b0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x2dc6
movl $0x8, %edi
callq 0x2090
movq %rax, %rdi
leaq 0x82c0(%rip), %rax      # 0xb073
movq %rax, (%rdi)
movq 0xd203(%rip), %rsi      # 0xffc0
xorl %eax, %eax
movl %eax, %edx
callq 0x2240
leaq -0x28(%rbp), %rdi
callq 0x4620
leaq -0xf40(%rbp), %rdi
callq 0x4640
movl $0x0, -0xf54(%rbp)
cmpl $0xd, -0xf54(%rbp)
jge 0x2e47
leaq -0x28(%rbp), %rdi
callq 0x3cb0
movb %al, -0xf9d(%rbp)
jmp 0x2dff
movb -0xf9d(%rbp), %cl
movslq -0xf54(%rbp), %rax
movb %cl, -0xf4d(%rbp,%rax)
movl -0xf54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf54(%rbp)
jmp 0x2de5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf60(%rbp)
movl %eax, -0xf64(%rbp)
leaq -0xf40(%rbp), %rdi
callq 0x48c0
jmp 0x30e6
leaq -0xf40(%rbp), %rdi
leaq -0xf4d(%rbp), %rsi
callq 0x4690
jmp 0x2e5c
movq $0x0, -0xf70(%rbp)
movb $0x0, -0xf71(%rbp)
movl $0x0, -0xf54(%rbp)
cmpl $0x8, -0xf54(%rbp)
jge 0x2ee2
movl -0xf54(%rbp), %eax
addl $0x5, %eax
cltq
movb -0xf4d(%rbp,%rax), %al
movb %al, -0xf72(%rbp)
movzbl -0xf72(%rbp), %eax
cmpl $0xff, %eax
je 0x2eae
movb $0x1, -0xf71(%rbp)
movzbl -0xf72(%rbp), %eax
movl -0xf54(%rbp), %ecx
shll $0x3, %ecx
movl %ecx, %ecx
shlq %cl, %rax
orq -0xf70(%rbp), %rax
movq %rax, -0xf70(%rbp)
movl -0xf54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf54(%rbp)
jmp 0x2e78
movb -0xf71(%rbp), %al
notb %al
andb $0x1, %al
movb %al, -0xeb8(%rbp)
leaq -0x28(%rbp), %rax
movq %rax, -0xf38(%rbp)
leaq -0xf40(%rbp), %rdi
callq 0x47c0
jmp 0x2f0b
movq -0xf70(%rbp), %rdx
movzbl -0xf71(%rbp), %esi
andl $0x1, %esi
leaq -0xf40(%rbp), %rdi
callq 0x2800
movl %eax, -0xfa4(%rbp)
jmp 0x2f30
movl -0xfa4(%rbp), %eax
movl %eax, -0xf78(%rbp)
cmpl $0x0, -0xf78(%rbp)
jne 0x2f71
movl $0x8, %edi
callq 0x2090
movq %rax, %rdi
leaq 0x8130(%rip), %rax      # 0xb089
movq %rax, (%rdi)
movq 0xd05d(%rip), %rsi      # 0xffc0
xorl %eax, %eax
movl %eax, %edx
callq 0x2240
jmp 0x30f2
testb $0x1, -0xf30(%rbp)
je 0x2fad
movq 0xd06f(%rip), %rdi      # 0xfff0
leaq 0x8115(%rip), %rsi      # 0xb09d
callq 0x2150
movq %rax, -0xfb0(%rbp)
jmp 0x2f96
movq -0xfb0(%rbp), %rdi
movq 0xd014(%rip), %rsi      # 0xffb8
callq 0x2190
jmp 0x2fab
jmp 0x2fad
leaq -0xef8(%rbp), %rdi
movq %rdi, -0xfc0(%rbp)
callq 0x4840
movq -0xfc0(%rbp), %rdi
movq %rax, -0xf90(%rbp)
callq 0x4870
movq %rax, -0xf98(%rbp)
movq -0xf90(%rbp), %rdi
movq -0xf98(%rbp), %rsi
callq 0x4800
movq %rax, -0xfb8(%rbp)
jmp 0x2ff6
movq -0xfb8(%rbp), %rax
movq %rax, -0xf88(%rbp)
leaq -0xf88(%rbp), %rdi
callq 0x48a0
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0xf80(%rbp)
leaq 0xd159(%rip), %rdi      # 0x10180
addq $0x20, %rdi
callq 0x2230
testb $0x1, %al
jne 0x3065
movsd -0xf80(%rbp), %xmm0
leaq -0xf40(%rbp), %rdi
callq 0x33d0
movl %eax, -0xfc4(%rbp)
jmp 0x3050
movl -0xfc4(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0xf9c(%rbp)
jmp 0x30ce
testb $0x1, 0xd154(%rip)      # 0x101c0
je 0x309f
movsd -0xf80(%rbp), %xmm0
leaq -0xf40(%rbp), %rdi
callq 0x3640
movl %eax, -0xfc8(%rbp)
jmp 0x308a
movl -0xfc8(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0xf9c(%rbp)
jmp 0x30ce
movsd -0xf80(%rbp), %xmm0
leaq -0xf40(%rbp), %rdi
callq 0x3ba0
movl %eax, -0xfcc(%rbp)
jmp 0x30bb
movl -0xfcc(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0xf9c(%rbp)
leaq -0xf40(%rbp), %rdi
callq 0x48c0
movl -0x4(%rbp), %eax
addq $0xfd0, %rsp            # imm = 0xFD0
popq %rbp
retq
movq -0xf60(%rbp), %rdi
callq 0x2270
nopw %cs:(%rax,%rax)