// File: /workspace/github_c_makefile_star2_O0/pali[P]bmfdec/./bmfdec.c
// Function: main
int main(int argc, char *argv[]) {
  FILE *fin;
  FILE *fout;
  uint32_t *pin;
  char *pout;
  long sin;
  size_t lin;
  uint32_t lout;
  int ret;
  if ((argc != 1 && argc != 2 && argc != 3) || (argc >= 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0))) {
    fprintf(stderr, "Usage: %s [input_file [output_file]]\n", argv[0]);
    return 1;
  }
  if (argc >= 2) {
    fin = fopen(argv[1], "rb");
    if (!fin) {
      fprintf(stderr, "Cannot open input file %s: %s\n", argv[1], strerror(errno));
      return 1;
    }
  } else {
    fin = stdin;
  }
  if (fseek(fin, 0, SEEK_END) == 0) {
    sin = ftell(fin);
    if (sin < 0) {
      fprintf(stderr, "Cannot determinate size of input file %s: %s\n", argc >= 2 ? argv[1] : "(stdin)", strerror(errno));
      if (argc >= 2)
        fclose(fin);
      return 1;
    }
    ++sin;
    rewind(fin);
    if (sin > 0x800000) {
      fprintf(stderr, "Size of input file %s too large\n", argc >= 2 ? argv[1] : "(stdin)");
      if (argc >= 2)
        fclose(fin);
      return 1;
    }
  } else {
    sin = 0x800000;
  }
  pin = malloc(sin);
  if (!pin) {
    fprintf(stderr, "Cannot allocate memory for input file %s\n", argc >= 2 ? argv[1] : "(stdin)");
    if (argc >= 2)
      fclose(fin);
    return 1;
  }
  lin = fread(pin, 1, sin, fin);
  if (ferror(fin)) {
    fprintf(stderr, "Failed to read data from input file %s\n", argc >= 2 ? argv[1] : "(stdin)");
    free(pin);
    if (argc >= 2)
      fclose(fin);
    return 1;
  } else if (!feof(fin)) {
    fprintf(stderr, "Data too large in input file %s\n", argc >= 2 ? argv[1] : "(stdin)");
    free(pin);
    if (argc >= 2)
      fclose(fin);
    return 1;
  }
  if (argc >= 2)
    fclose(fin);
  if (lin <= 16 || pin[0] != 0x424D4F46 || pin[1] != 0x00000001 || pin[2] != (uint32_t)lin-16) {
    fprintf(stderr, "Invalid input\n");
    free(pin);
    return 1;
  }
  lout = pin[3];
  if (lout > 0x2000000) {
    fprintf(stderr, "Invalid input\n");
    free(pin);
    return 1;
  }
  pout = malloc(lout);
  if (!pout) {
    fprintf(stderr, "Cannot allocate memory for decompression\n");
    free(pin);
    return 1;
  }
  if (ds_dec((char *)pin+16, lin-16, pout, lout, 0) != (int)lout) {
    fprintf(stderr, "Decompress failed\n");
    free(pin);
    free(pout);
    return 1;
  }
  free(pin);
  if (argc >= 3) {
    fout = fopen(argv[2], "wb");
    if (!fout) {
      fprintf(stderr, "Cannot open output file %s: %s\n", argv[2], strerror(errno));
      free(pout);
      return 1;
    }
  } else {
    fout = stdout;
  }
  ret = process_data(pout, lout, fout);
  free(pout);
  if (argc >= 3)
    fclose(fout);
  return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x1, -0x8(%rbp)
je 0x17eb
cmpl $0x2, -0x8(%rbp)
je 0x17eb
cmpl $0x3, -0x8(%rbp)
jne 0x1823
cmpl $0x2, -0x8(%rbp)
jl 0x184e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6af0(%rip), %rsi      # 0x82f0
callq 0x10f0
cmpl $0x0, %eax
je 0x1823
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6ada(%rip), %rsi      # 0x82f3
callq 0x10f0
cmpl $0x0, %eax
jne 0x184e
movq 0x97ce(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x6abf(%rip), %rsi      # 0x82fa
movb $0x0, %al
callq 0x1100
movl $0x1, -0x4(%rbp)
jmp 0x1dbd
cmpl $0x2, -0x8(%rbp)
jl 0x18c0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6abd(%rip), %rsi      # 0x8320
callq 0x1170
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x18be
movq 0x977e(%rip), %rax      # 0xaff8
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
callq 0x1050
movl (%rax), %edi
callq 0x11a0
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rdx
movq %rax, %rcx
leaq 0x6a78(%rip), %rsi      # 0x8323
movb $0x0, %al
callq 0x1100
movl $0x1, -0x4(%rbp)
jmp 0x1dbd
jmp 0x18ce
movq 0x9711(%rip), %rax      # 0xafd8
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x1150
cmpl $0x0, %eax
jne 0x19f5
movq -0x18(%rbp), %rdi
callq 0x1110
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jge 0x1974
movq 0x96f4(%rip), %rax      # 0xaff8
movq (%rax), %rax
movq %rax, -0x60(%rbp)
cmpl $0x2, -0x8(%rbp)
jl 0x191f
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
jmp 0x192c
leaq 0x6a4a(%rip), %rax      # 0x8370
movq %rax, -0x68(%rbp)
jmp 0x192c
movq -0x68(%rbp), %rax
movq %rax, -0x70(%rbp)
callq 0x1050
movl (%rax), %edi
callq 0x11a0
movq -0x60(%rbp), %rdi
movq -0x70(%rbp), %rdx
movq %rax, %rcx
leaq 0x69f0(%rip), %rsi      # 0x8342
movb $0x0, %al
callq 0x1100
cmpl $0x2, -0x8(%rbp)
jl 0x1968
movq -0x18(%rbp), %rdi
callq 0x1090
movl $0x1, -0x4(%rbp)
jmp 0x1dbd
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
callq 0x10b0
cmpq $0x800000, -0x38(%rbp)  # imm = 0x800000
jle 0x19f3
movq 0x965e(%rip), %rax      # 0xaff8
movq (%rax), %rax
movq %rax, -0x78(%rbp)
cmpl $0x2, -0x8(%rbp)
jl 0x19b5
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x80(%rbp)
jmp 0x19c2
leaq 0x69b4(%rip), %rax      # 0x8370
movq %rax, -0x80(%rbp)
jmp 0x19c2
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %rdx
leaq 0x69a7(%rip), %rsi      # 0x8378
movb $0x0, %al
callq 0x1100
cmpl $0x2, -0x8(%rbp)
jl 0x19e7
movq -0x18(%rbp), %rdi
callq 0x1090
movl $0x1, -0x4(%rbp)
jmp 0x1dbd
jmp 0x19fd
movq $0x800000, -0x38(%rbp)  # imm = 0x800000
movq -0x38(%rbp), %rdi
callq 0x1140
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x1a80
movq 0x95e0(%rip), %rax      # 0xaff8
movq (%rax), %rax
movq %rax, -0x88(%rbp)
cmpl $0x2, -0x8(%rbp)
jl 0x1a39
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x90(%rbp)
jmp 0x1a49
leaq 0x6930(%rip), %rax      # 0x8370
movq %rax, -0x90(%rbp)
jmp 0x1a49
movq -0x88(%rbp), %rdi
movq -0x90(%rbp), %rdx
leaq 0x693b(%rip), %rsi      # 0x8399
movb $0x0, %al
callq 0x1100
cmpl $0x2, -0x8(%rbp)
jl 0x1a74
movq -0x18(%rbp), %rdi
callq 0x1090
movl $0x1, -0x4(%rbp)
jmp 0x1dbd
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl $0x1, %esi
callq 0x1080
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1070
cmpl $0x0, %eax
je 0x1b20
movq 0x9549(%rip), %rax      # 0xaff8
movq (%rax), %rax
movq %rax, -0x98(%rbp)
cmpl $0x2, -0x8(%rbp)
jl 0x1ad0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xa0(%rbp)
jmp 0x1ae0
leaq 0x6899(%rip), %rax      # 0x8370
movq %rax, -0xa0(%rbp)
jmp 0x1ae0
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %rdx
leaq 0x68ce(%rip), %rsi      # 0x83c3
movb $0x0, %al
callq 0x1100
movq -0x28(%rbp), %rdi
callq 0x1030
cmpl $0x2, -0x8(%rbp)
jl 0x1b14
movq -0x18(%rbp), %rdi
callq 0x1090
movl $0x1, -0x4(%rbp)
jmp 0x1dbd
movq -0x18(%rbp), %rdi
callq 0x1120
cmpl $0x0, %eax
jne 0x1ba6
movq 0x94c3(%rip), %rax      # 0xaff8
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
cmpl $0x2, -0x8(%rbp)
jl 0x1b56
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xb0(%rbp)
jmp 0x1b66
leaq 0x6813(%rip), %rax      # 0x8370
movq %rax, -0xb0(%rbp)
jmp 0x1b66
movq -0xa8(%rbp), %rdi
movq -0xb0(%rbp), %rdx
leaq 0x6870(%rip), %rsi      # 0x83eb
movb $0x0, %al
callq 0x1100
movq -0x28(%rbp), %rdi
callq 0x1030
cmpl $0x2, -0x8(%rbp)
jl 0x1b9a
movq -0x18(%rbp), %rdi
callq 0x1090
movl $0x1, -0x4(%rbp)
jmp 0x1dbd
jmp 0x1ba8
cmpl $0x2, -0x8(%rbp)
jl 0x1bb7
movq -0x18(%rbp), %rdi
callq 0x1090
cmpq $0x10, -0x40(%rbp)
jbe 0x1be6
movq -0x28(%rbp), %rax
cmpl $0x424d4f46, (%rax)     # imm = 0x424D4F46
jne 0x1be6
movq -0x28(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jne 0x1be6
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x40(%rbp), %rcx
subl $0x10, %ecx
cmpl %ecx, %eax
je 0x1c13
movq 0x940b(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x6815(%rip), %rsi      # 0x840c
movb $0x0, %al
callq 0x1100
movq -0x28(%rbp), %rdi
callq 0x1030
movl $0x1, -0x4(%rbp)
jmp 0x1dbd
movq -0x28(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x44(%rbp)
cmpl $0x2000000, -0x44(%rbp) # imm = 0x2000000
jbe 0x1c53
movq 0x93cb(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x67d5(%rip), %rsi      # 0x840c
movb $0x0, %al
callq 0x1100
movq -0x28(%rbp), %rdi
callq 0x1030
movl $0x1, -0x4(%rbp)
jmp 0x1dbd
movl -0x44(%rbp), %eax
movl %eax, %edi
callq 0x1140
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x1c95
movq 0x9389(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x67a2(%rip), %rsi      # 0x841b
movb $0x0, %al
callq 0x1100
movq -0x28(%rbp), %rdi
callq 0x1030
movl $0x1, -0x4(%rbp)
jmp 0x1dbd
movq -0x28(%rbp), %rdi
addq $0x10, %rdi
movq -0x40(%rbp), %rax
subq $0x10, %rax
movl %eax, %esi
movq -0x30(%rbp), %rdx
movl -0x44(%rbp), %ecx
xorl %r8d, %r8d
callq 0x12b0
cmpl -0x44(%rbp), %eax
je 0x1cf1
movq 0x9336(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x6779(%rip), %rsi      # 0x8445
movb $0x0, %al
callq 0x1100
movq -0x28(%rbp), %rdi
callq 0x1030
movq -0x30(%rbp), %rdi
callq 0x1030
movl $0x1, -0x4(%rbp)
jmp 0x1dbd
movq -0x28(%rbp), %rdi
callq 0x1030
cmpl $0x3, -0x8(%rbp)
jl 0x1d7e
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x6749(%rip), %rsi      # 0x8458
callq 0x1170
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x1d7c
movq 0x92d2(%rip), %rax      # 0xaff8
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xb8(%rbp)
callq 0x1050
movl (%rax), %edi
callq 0x11a0
movq -0xc0(%rbp), %rdi
movq -0xb8(%rbp), %rdx
movq %rax, %rcx
leaq 0x66f8(%rip), %rsi      # 0x845b
movb $0x0, %al
callq 0x1100
movq -0x30(%rbp), %rdi
callq 0x1030
movl $0x1, -0x4(%rbp)
jmp 0x1dbd
jmp 0x1d8c
movq 0x924b(%rip), %rax      # 0xafd0
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %esi
movq -0x20(%rbp), %rdx
callq 0x1dd0
movl %eax, -0x48(%rbp)
movq -0x30(%rbp), %rdi
callq 0x1030
cmpl $0x3, -0x8(%rbp)
jl 0x1db7
movq -0x20(%rbp), %rdi
callq 0x1090
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)