#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*/ crc32;
typedef int /*<<< orphan*/ aFirmware;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
unsigned long CalcCRC32(unsigned char *, unsigned long);
unsigned long PlaceImage(char *, unsigned long, unsigned char *, int);
int Read32(unsigned char *);
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ Write32(unsigned char *, unsigned long);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
unsigned long fread(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
unsigned long fwrite(unsigned char *, int, unsigned long, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strncmp(unsigned char *, char *, int);
int main(int argc, char *argv[]) {
  static unsigned char aFirmware[512 * 1024];
  FILE *pFile;
  unsigned long size;
  unsigned long pos;
  unsigned long crc32;
  int hasBootRom;
  unsigned long template_F8, template_FC;
  int i;
  if (argc <= 4) {
    printf("Usage:\n");
    printf("make_firmware <output> <template.bin> <bootloader.ajz> "
           "<image1.ucl> {image2.ucl}\n");
    printf("<template.bin> is the original firmware from your box\n");
    printf("<bootloader.ajz> is the scrambled bootloader\n");
    printf("<image1.ucl> is the first image, compressed (recommended) or "
           "uncompressed\n");
    printf("<image1.ucl> is the second image, compressed (recommended) or "
           "uncompressed\n");
    printf("More images may follow, but keep the flash size in mind!\n");
    printf("Compression must be UCL, algorithm 2e.\n");
    printf("Generated with: uclpack --best --2e rockbox.bin imageN.ucl\n");
    exit(0);
  }
  memset(aFirmware, 0xFF, sizeof(aFirmware));
  pFile = fopen(argv[2], "rb");
  if (pFile == NULL) {
    printf("Template file %s not found!\n", argv[2]);
    exit(1);
  }
  size = fread(aFirmware, 1, 256, pFile);
  fclose(pFile);
  if (size < 256) {
    printf("Template file %s too small, need at least the header!\n", argv[2]);
    exit(2);
  }
  if (strncmp(aFirmware, "ARCH", 4) == 0) {
    hasBootRom = 1;
    pos = 256;
  } else if (Read32(aFirmware) == 0x0200) {
    hasBootRom = 0;
    pos = 0;
    template_F8 = Read32(aFirmware + 0xF8);
    template_FC = Read32(aFirmware + 0xFC);
  } else {
    printf("Template file %s invalid!\n", argv[2]);
    exit(3);
  }
  pFile = fopen(argv[3], "rb");
  if (pFile == NULL) {
    printf("Bootloader file %s not found!\n", argv[3]);
    exit(4);
  }
  if (hasBootRom && fseek(pFile, 6, SEEK_SET)) {
    printf("Bootloader file %s too short!\n", argv[3]);
    exit(5);
  }
  size = fread(aFirmware + pos, 1, sizeof(aFirmware) - pos, pFile);
  fclose(pFile);
  if (hasBootRom) {
    Write32(aFirmware + 4, 0x0FFFF500);
    for (i = 0x08; i <= 0x28; i += 8) {
      Write32(aFirmware + i, 0x02000100);
      Write32(aFirmware + i + 4, size);
    }
  } else {
    Write32(aFirmware + 0xF8, template_F8);
    Write32(aFirmware + 0xFC, template_FC);
  }
  size = (size + 3) & ~3;
  pos += size;
  for (i = 4; i < argc; i++) {
    pos = PlaceImage(argv[i], pos, aFirmware, sizeof(aFirmware));
    if (i < argc - 1) {
      pos = (pos + 4096 - 1) & ~(4096 - 1);
    }
  }
  crc32 = CalcCRC32(aFirmware, pos);
  Write32(aFirmware + pos, crc32);
  pos += sizeof(crc32);
  pFile = fopen(argv[1], "wb");
  if (pFile == NULL) {
    printf("Output file %s cannot be created!\n", argv[1]);
    exit(9);
  }
  size = fwrite(aFirmware, 1, pos, pFile);
  fclose(pFile);
  if (size != pos) {
    printf("Error writing %d bytes to output file %s!\n", pos, argv[1]);
    exit(10);
  }
  printf("Firmware file generated with %d bytes.\n", pos);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jg     1275 <main+0xa5>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xf0b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xf37(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xf51(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    0x2e24(%rip),%rdi
mov    $0xff,%esi
mov    $0x80000,%edx
call   1090 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xf5a(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12ce <main+0xfe>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xf3a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%rcx
lea    0x2dc7(%rip),%rdi
mov    $0x1,%esi
mov    $0x100,%edx
call   1040 <fread@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x100,-0x20(%rbp)
jae    1323 <main+0x153>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xf02(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
lea    0x2d76(%rip),%rdi
lea    0xf1a(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1359 <main+0x189>
movl   $0x1,-0x34(%rbp)
movq   $0x100,-0x28(%rbp)
jmp    13db <main+0x20b>
lea    0x2d40(%rip),%rdi
call   10b0 <Read32@plt>
cmp    $0x200,%eax
jne    13b6 <main+0x1e6>
movl   $0x0,-0x34(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0x2d1a(%rip),%rdi
add    $0xf8,%rdi
call   10b0 <Read32@plt>
cltq
mov    %rax,-0x40(%rbp)
lea    0x2d01(%rip),%rdi
add    $0xfc,%rdi
call   10b0 <Read32@plt>
cltq
mov    %rax,-0x48(%rbp)
jmp    13d6 <main+0x206>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x3,%edi
call   10e0 <exit@plt>
jmp    13db <main+0x20b>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe0a(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    141e <main+0x24e>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x4,%edi
call   10e0 <exit@plt>
cmpl   $0x0,-0x34(%rbp)
je     1469 <main+0x299>
mov    -0x18(%rbp),%rdi
mov    0x2bad(%rip),%rax
mov    (%rax),%edx
mov    $0x6,%esi
call   10a0 <fseek@plt>
cmp    $0x0,%rax
je     1469 <main+0x299>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x5,%edi
call   10e0 <exit@plt>
lea    0x2c30(%rip),%rdi
add    -0x28(%rbp),%rdi
mov    $0x80000,%eax
sub    -0x28(%rbp),%rax
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x0,-0x34(%rbp)
je     1510 <main+0x340>
lea    0x2bf5(%rip),%rdi
add    $0x4,%rdi
mov    $0xffff500,%esi
call   1080 <Write32@plt>
movl   $0x8,-0x4c(%rbp)
cmpl   $0x28,-0x4c(%rbp)
jg     150b <main+0x33b>
movslq -0x4c(%rbp),%rax
lea    0x2bcb(%rip),%rdi
add    %rax,%rdi
mov    $0x2000100,%esi
call   1080 <Write32@plt>
movslq -0x4c(%rbp),%rax
lea    0x2bb3(%rip),%rdi
add    %rax,%rdi
add    $0x4,%rdi
mov    -0x20(%rbp),%rsi
call   1080 <Write32@plt>
mov    -0x4c(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x4c(%rbp)
jmp    14c0 <main+0x2f0>
jmp    153e <main+0x36e>
mov    -0x40(%rbp),%rsi
lea    0x2b85(%rip),%rdi
add    $0xf8,%rdi
call   1080 <Write32@plt>
mov    -0x48(%rbp),%rsi
lea    0x2b6e(%rip),%rdi
add    $0xfc,%rdi
call   1080 <Write32@plt>
mov    -0x20(%rbp),%rax
add    $0x3,%rax
and    $0xfffffffffffffffc,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x4,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    15ce <main+0x3fe>
mov    -0x10(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rsi
lea    0x2b1c(%rip),%rdx
mov    $0x80000,%ecx
call   10d0 <PlaceImage@plt>
mov    %rax,-0x28(%rbp)
mov    -0x4c(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    15bb <main+0x3eb>
mov    -0x28(%rbp),%rax
add    $0x1000,%rax
sub    $0x1,%rax
and    $0xfffffffffffff000,%rax
mov    %rax,-0x28(%rbp)
jmp    15c0 <main+0x3f0>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1561 <main+0x391>
mov    -0x28(%rbp),%rsi
lea    0x2ac7(%rip),%rdi
call   1060 <CalcCRC32@plt>
mov    %rax,-0x30(%rbp)
lea    0x2ab7(%rip),%rdi
add    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1080 <Write32@plt>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xc98(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1645 <main+0x475>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xc78(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x9,%edi
call   10e0 <exit@plt>
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0x2a4c(%rip),%rdi
mov    $0x1,%esi
call   10f0 <fwrite@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     169d <main+0x4cd>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xc43(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xa,%edi
call   10e0 <exit@plt>
mov    -0x28(%rbp),%rsi
lea    0xc52(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x4,%edi
jle    1508 <main+0x328>
mov    %rsi,%r15
mov    %edi,%r14d
lea    0x2e9c(%rip),%rdi
mov    $0xff,%esi
mov    $0x80000,%edx
call   10a0 <memset@plt>
mov    0x10(%r15),%rdi
lea    0xde2(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     157b <main+0x39b>
mov    %rax,%rbx
lea    0x2e6a(%rip),%rdi
mov    $0x1,%esi
mov    $0x100,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1060 <fclose@plt>
cmp    $0xff,%rbp
jbe    1597 <main+0x3b7>
lea    0x2e39(%rip),%rbx
lea    0xde9(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %rax,%r12
test   %rax,%rax
mov    %r14,0x10(%rsp)
je     12e8 <main+0x108>
lea    0x2e11(%rip),%rdi
call   10c0 <Read32@plt>
cmp    $0x200,%eax
jne    15ee <main+0x40e>
lea    0x2ef2(%rip),%rdi
call   10c0 <Read32@plt>
mov    %eax,%ebp
lea    0x2ee8(%rip),%rdi
call   10c0 <Read32@plt>
mov    %eax,%r14d
mov    0x18(%r15),%rdi
lea    0xd39(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     160a <main+0x42a>
mov    %rax,%r13
movslq %ebp,%rbp
movslq %r14d,%rax
mov    %rax,0x8(%rsp)
xor    %r14d,%r14d
jmp    132d <main+0x14d>
lea    0x18(%r15),%rbp
mov    0x18(%r15),%rdi
lea    0xd09(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1611 <main+0x431>
mov    %rax,%r13
mov    0x2cd1(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
mov    $0x6,%esi
call   10b0 <fseek@plt>
test   %rax,%rax
jne    162d <main+0x44d>
mov    $0x100,%r14d
add    %r14,%rbx
mov    $0x80000,%edx
sub    %r14d,%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r13,%rcx
call   1050 <fread@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1060 <fclose@plt>
test   %r12,%r12
je     1378 <main+0x198>
lea    0x2e39(%rip),%rdi
mov    %rbp,%rsi
call   1090 <Write32@plt>
lea    0x2e2e(%rip),%rdi
mov    0x8(%rsp),%rsi
jmp    1424 <main+0x244>
lea    0x2d25(%rip),%rdi
mov    $0xffff500,%esi
call   1090 <Write32@plt>
lea    0x2d18(%rip),%rdi
mov    $0x2000100,%esi
call   1090 <Write32@plt>
lea    0x2d0b(%rip),%rdi
mov    %rbx,%rsi
call   1090 <Write32@plt>
lea    0x2d00(%rip),%rdi
mov    $0x2000100,%esi
call   1090 <Write32@plt>
lea    0x2cf3(%rip),%rdi
mov    %rbx,%rsi
call   1090 <Write32@plt>
lea    0x2ce8(%rip),%rdi
mov    $0x2000100,%esi
call   1090 <Write32@plt>
lea    0x2cdb(%rip),%rdi
mov    %rbx,%rsi
call   1090 <Write32@plt>
lea    0x2cd0(%rip),%rdi
mov    $0x2000100,%esi
call   1090 <Write32@plt>
lea    0x2cc3(%rip),%rdi
mov    %rbx,%rsi
call   1090 <Write32@plt>
lea    0x2cb8(%rip),%rdi
mov    $0x2000100,%esi
call   1090 <Write32@plt>
lea    0x2cab(%rip),%rdi
mov    %rbx,%rsi
call   1090 <Write32@plt>
add    $0x3,%rbx
and    $0xfffffffffffffffc,%rbx
add    %r14,%rbx
mov    0x10(%rsp),%rax
lea    -0x1(%rax),%r14d
mov    %eax,%r12d
mov    $0x4,%ebp
lea    0x2c54(%rip),%r13
nopl   0x0(%rax)
mov    (%r15,%rbp,8),%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    $0x80000,%ecx
call   10e0 <PlaceImage@plt>
lea    0xfff(%rax),%rbx
and    $0xfffffffffffff000,%rbx
cmp    %r14,%rbp
cmovae %rax,%rbx
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1450 <main+0x270>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1070 <CalcCRC32@plt>
add    %rbx,%r13
mov    %r13,%rdi
mov    %rax,%rsi
call   1090 <Write32@plt>
mov    0x8(%r15),%rdi
lea    0xc0f(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     15b3 <main+0x3d3>
mov    %rax,%rbp
add    $0x8,%rbx
lea    0x2bde(%rip),%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1100 <fwrite@plt>
mov    %rax,%r14
mov    %rbp,%rdi
call   1060 <fclose@plt>
cmp    %rbx,%r14
jne    15cf <main+0x3ef>
lea    0xc19(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc1f(%rip),%rdi
call   1040 <puts@plt>
lea    0xc1a(%rip),%rdi
call   1040 <puts@plt>
lea    0xc5f(%rip),%rdi
call   1040 <puts@plt>
lea    0xc89(%rip),%rdi
call   1040 <puts@plt>
lea    0xcaa(%rip),%rdi
call   1040 <puts@plt>
lea    0xce8(%rip),%rdi
call   1040 <puts@plt>
lea    0xd27(%rip),%rdi
call   1040 <puts@plt>
lea    0xd54(%rip),%rdi
call   1040 <puts@plt>
lea    0xd6f(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    0x10(%r15),%rsi
lea    0xa7d(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    0x10(%r15),%rsi
lea    0xa7e(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x2,%edi
call   10f0 <exit@plt>
mov    0x8(%r15),%rsi
lea    0xafa(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x9,%edi
call   10f0 <exit@plt>
mov    0x8(%r15),%rdx
lea    0xb01(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xa,%edi
call   10f0 <exit@plt>
mov    0x10(%r15),%rsi
lea    0xa63(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x3,%edi
call   10f0 <exit@plt>
add    $0x18,%r15
mov    %r15,%rbp
mov    0x0(%rbp),%rsi
lea    0xa5b(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x4,%edi
call   10f0 <exit@plt>
mov    0x0(%rbp),%rsi
lea    0xa5e(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x5,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@main.aFirmware = internal global [524288 x i8] zeroinitializer
@.str = [8 x i8] c"Usage:\0A\00"
@.str.1 = [82 x i8] c"make_firmware <output> <template.bin> <bootloader.ajz> <image1.ucl> {image2.ucl}\0A\00"
@.str.2 = [55 x i8] c"<template.bin> is the original firmware from your box\0A\00"
@.str.3 = [46 x i8] c"<bootloader.ajz> is the scrambled bootloader\0A\00"
@.str.4 = [75 x i8] c"<image1.ucl> is the first image, compressed (recommended) or uncompressed\0A\00"
@.str.5 = [76 x i8] c"<image1.ucl> is the second image, compressed (recommended) or uncompressed\0A\00"
@.str.6 = [58 x i8] c"More images may follow, but keep the flash size in mind!\0A\00"
@.str.7 = [40 x i8] c"Compression must be UCL, algorithm 2e.\0A\00"
@.str.8 = [60 x i8] c"Generated with: uclpack --best --2e rockbox.bin imageN.ucl\0A\00"
@.str.9 = [3 x i8] c"rb\00"
@.str.10 = [29 x i8] c"Template file %s not found!\0A\00"
@.str.11 = [55 x i8] c"Template file %s too small, need at least the header!\0A\00"
@.str.12 = [5 x i8] c"ARCH\00"
@.str.13 = [27 x i8] c"Template file %s invalid!\0A\00"
@.str.14 = [31 x i8] c"Bootloader file %s not found!\0A\00"
@SEEK_SET = global i32 0
@.str.15 = [31 x i8] c"Bootloader file %s too short!\0A\00"
@.str.16 = [3 x i8] c"wb\00"
@.str.17 = [35 x i8] c"Output file %s cannot be created!\0A\00"
@.str.18 = [43 x i8] c"Error writing %d bytes to output file %s!\0A\00"
@.str.19 = [40 x i8] c"Firmware file generated with %d bytes.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp sle i32 %14, 4
br i1 %15, label %16, label %27
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.5, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.6, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.8, i64 0, i64 0))
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %2
%28 = call i32 @memset(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0), i32 255, i32 524288)
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
store i32* %32, i32** %6
%33 = load i32*, i32** %6
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %41
35: ; preds = %27
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i8* %38)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %27
%42 = load i32*, i32** %6
%43 = call i64 @fread(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0), i32 1, i32 256, i32* %42)
store i64 %43, i64* %7
%44 = load i32*, i32** %6
%45 = call i32 @fclose(i32* %44)
%46 = load i64, i64* %7
%47 = icmp ult i64 %46, 256
br i1 %47, label %48, label %54
48: ; preds = %41
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.11, i64 0, i64 0), i8* %51)
%53 = call i32 @exit(i32 2)
unreachable
54: ; preds = %41
%55 = call i64 @strncmp(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i32 4)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %54
store i32 1, i32* %10
store i64 256, i64* %8
br label %73
58: ; preds = %54
%59 = call i32 @Read32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0))
%60 = icmp eq i32 %59, 512
br i1 %60, label %61, label %66
61: ; preds = %58
store i32 0, i32* %10
store i64 0, i64* %8
%62 = call i32 @Read32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 248))
%63 = sext i32 %62 to i64
store i64 %63, i64* %11
%64 = call i32 @Read32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 252))
%65 = sext i32 %64 to i64
store i64 %65, i64* %12
br label %72
66: ; preds = %58
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 2
%69 = load i8*, i8** %68
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0), i8* %69)
%71 = call i32 @exit(i32 3)
unreachable
72: ; preds = %61
br label %73
73: ; preds = %72, %57
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 3
%76 = load i8*, i8** %75
%77 = call i32* @fopen(i8* %76, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
store i32* %77, i32** %6
%78 = load i32*, i32** %6
%79 = icmp eq i32* %78, null
br i1 %79, label %80, label %86
80: ; preds = %73
%81 = load i8**, i8*** %5
%82 = getelementptr inbounds i8*, i8** %81, i64 3
%83 = load i8*, i8** %82
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0), i8* %83)
%85 = call i32 @exit(i32 4)
unreachable
86: ; preds = %73
%87 = load i32, i32* %10
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %100
89: ; preds = %86
%90 = load i32*, i32** %6
%91 = load i32, i32* @SEEK_SET
%92 = call i64 @fseek(i32* %90, i32 6, i32 %91)
%93 = icmp ne i64 %92, 0
br i1 %93, label %94, label %100
94: ; preds = %89
%95 = load i8**, i8*** %5
%96 = getelementptr inbounds i8*, i8** %95, i64 3
%97 = load i8*, i8** %96
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.15, i64 0, i64 0), i8* %97)
%99 = call i32 @exit(i32 5)
unreachable
100: ; preds = %89, %86
%101 = load i64, i64* %8
%102 = getelementptr inbounds i8, i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0), i64 %101
%103 = load i64, i64* %8
%104 = sub i64 524288, %103
%105 = trunc i64 %104 to i32
%106 = load i32*, i32** %6
%107 = call i64 @fread(i8* %102, i32 1, i32 %105, i32* %106)
store i64 %107, i64* %7
%108 = load i32*, i32** %6
%109 = call i32 @fclose(i32* %108)
%110 = load i32, i32* %10
%111 = icmp ne i32 %110, 0
br i1 %111, label %112, label %132
112: ; preds = %100
%113 = call i32 @Write32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 4), i64 268432640)
store i32 8, i32* %13
br label %114
114: ; preds = %128, %112
%115 = load i32, i32* %13
%116 = icmp sle i32 %115, 40
br i1 %116, label %117, label %131
117: ; preds = %114
%118 = load i32, i32* %13
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds i8, i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0), i64 %119
%121 = call i32 @Write32(i8* %120, i64 33554688)
%122 = load i32, i32* %13
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds i8, i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0), i64 %123
%125 = getelementptr inbounds i8, i8* %124, i64 4
%126 = load i64, i64* %7
%127 = call i32 @Write32(i8* %125, i64 %126)
br label %128
128: ; preds = %117
%129 = load i32, i32* %13
%130 = add nsw i32 %129, 8
store i32 %130, i32* %13
br label %114
131: ; preds = %114
br label %137
132: ; preds = %100
%133 = load i64, i64* %11
%134 = call i32 @Write32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 248), i64 %133)
%135 = load i64, i64* %12
%136 = call i32 @Write32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 252), i64 %135)
br label %137
137: ; preds = %132, %131
%138 = load i64, i64* %7
%139 = add i64 %138, 3
%140 = and i64 %139, -4
store i64 %140, i64* %7
%141 = load i64, i64* %7
%142 = load i64, i64* %8
%143 = add i64 %142, %141
store i64 %143, i64* %8
store i32 4, i32* %13
br label %144
144: ; preds = %166, %137
%145 = load i32, i32* %13
%146 = load i32, i32* %4
%147 = icmp slt i32 %145, %146
br i1 %147, label %148, label %169
148: ; preds = %144
%149 = load i8**, i8*** %5
%150 = load i32, i32* %13
%151 = sext i32 %150 to i64
%152 = getelementptr inbounds i8*, i8** %149, i64 %151
%153 = load i8*, i8** %152
%154 = load i64, i64* %8
%155 = call i64 @PlaceImage(i8* %153, i64 %154, i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0), i32 524288)
store i64 %155, i64* %8
%156 = load i32, i32* %13
%157 = load i32, i32* %4
%158 = sub nsw i32 %157, 1
%159 = icmp slt i32 %156, %158
br i1 %159, label %160, label %165
160: ; preds = %148
%161 = load i64, i64* %8
%162 = add i64 %161, 4096
%163 = sub i64 %162, 1
%164 = and i64 %163, -4096
store i64 %164, i64* %8
br label %165
165: ; preds = %160, %148
br label %166
166: ; preds = %165
%167 = load i32, i32* %13
%168 = add nsw i32 %167, 1
store i32 %168, i32* %13
br label %144
169: ; preds = %144
%170 = load i64, i64* %8
%171 = call i64 @CalcCRC32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0), i64 %170)
store i64 %171, i64* %9
%172 = load i64, i64* %8
%173 = getelementptr inbounds i8, i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0), i64 %172
%174 = load i64, i64* %9
%175 = call i32 @Write32(i8* %173, i64 %174)
%176 = load i64, i64* %8
%177 = add i64 %176, 8
store i64 %177, i64* %8
%178 = load i8**, i8*** %5
%179 = getelementptr inbounds i8*, i8** %178, i64 1
%180 = load i8*, i8** %179
%181 = call i32* @fopen(i8* %180, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0))
store i32* %181, i32** %6
%182 = load i32*, i32** %6
%183 = icmp eq i32* %182, null
br i1 %183, label %184, label %190
184: ; preds = %169
%185 = load i8**, i8*** %5
%186 = getelementptr inbounds i8*, i8** %185, i64 1
%187 = load i8*, i8** %186
%188 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.17, i64 0, i64 0), i8* %187)
%189 = call i32 @exit(i32 9)
unreachable
190: ; preds = %169
%191 = load i64, i64* %8
%192 = load i32*, i32** %6
%193 = call i64 @fwrite(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0), i32 1, i64 %191, i32* %192)
store i64 %193, i64* %7
%194 = load i32*, i32** %6
%195 = call i32 @fclose(i32* %194)
%196 = load i64, i64* %7
%197 = load i64, i64* %8
%198 = icmp ne i64 %196, %197
br i1 %198, label %199, label %206
199: ; preds = %190
%200 = load i64, i64* %8
%201 = load i8**, i8*** %5
%202 = getelementptr inbounds i8*, i8** %201, i64 1
%203 = load i8*, i8** %202
%204 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.18, i64 0, i64 0), i64 %200, i8* %203)
%205 = call i32 @exit(i32 10)
unreachable
206: ; preds = %190
%207 = load i64, i64* %8
%208 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.19, i64 0, i64 0), i64 %207)
ret i32 0
}

LLVM IR (-O2):
@main.aFirmware = internal global [524288 x i8] zeroinitializer
@.str.9 = [3 x i8] c"rb\00"
@.str.10 = [29 x i8] c"Template file %s not found!\0A\00"
@.str.11 = [55 x i8] c"Template file %s too small, need at least the header!\0A\00"
@.str.12 = [5 x i8] c"ARCH\00"
@.str.13 = [27 x i8] c"Template file %s invalid!\0A\00"
@.str.14 = [31 x i8] c"Bootloader file %s not found!\0A\00"
@SEEK_SET = global i32 0
@.str.15 = [31 x i8] c"Bootloader file %s too short!\0A\00"
@.str.16 = [3 x i8] c"wb\00"
@.str.17 = [35 x i8] c"Output file %s cannot be created!\0A\00"
@.str.18 = [43 x i8] c"Error writing %d bytes to output file %s!\0A\00"
@.str.19 = [40 x i8] c"Firmware file generated with %d bytes.\0A\00"
@str = [7 x i8] c"Usage:\00"
@str.20 = [81 x i8] c"make_firmware <output> <template.bin> <bootloader.ajz> <image1.ucl> {image2.ucl}\00"
@str.21 = [54 x i8] c"<template.bin> is the original firmware from your box\00"
@str.22 = [45 x i8] c"<bootloader.ajz> is the scrambled bootloader\00"
@str.23 = [74 x i8] c"<image1.ucl> is the first image, compressed (recommended) or uncompressed\00"
@str.24 = [75 x i8] c"<image1.ucl> is the second image, compressed (recommended) or uncompressed\00"
@str.25 = [57 x i8] c"More images may follow, but keep the flash size in mind!\00"
@str.26 = [39 x i8] c"Compression must be UCL, algorithm 2e.\00"
@str.27 = [59 x i8] c"Generated with: uclpack --best --2e rockbox.bin imageN.ucl\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 5
br i1 %3, label %4, label %15
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.20, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.21, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.22, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str.23, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @str.24, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.25, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.26, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.27, i64 0, i64 0))
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %2
%16 = tail call i32 @memset(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0), i32 255, i32 524288)
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = load i8*, i8** %17
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i8* %22)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %15
%26 = tail call i64 @fread(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0), i32 1, i32 256, i32* %19)
%27 = tail call i32 @fclose(i32* %19)
%28 = icmp ult i64 %26, 256
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i8*, i8** %17
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.11, i64 0, i64 0), i8* %30)
%32 = tail call i32 @exit(i32 2)
unreachable
33: ; preds = %25
%34 = tail call i64 @strncmp(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i32 4)
%35 = icmp eq i64 %34, 0
br i1 %35, label %43, label %36
36: ; preds = %33
%37 = tail call i32 @Read32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0))
%38 = icmp eq i32 %37, 512
br i1 %38, label %48, label %39
39: ; preds = %36
%40 = load i8*, i8** %17
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0), i8* %40)
%42 = tail call i32 @exit(i32 3)
unreachable
43: ; preds = %33
%44 = getelementptr inbounds i8*, i8** %1, i64 3
%45 = load i8*, i8** %44
%46 = tail call i32* @fopen(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%47 = icmp eq i32* %46, null
br i1 %47, label %57, label %62
48: ; preds = %36
%49 = tail call i32 @Read32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 248))
%50 = sext i32 %49 to i64
%51 = tail call i32 @Read32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 252))
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %1, i64 3
%54 = load i8*, i8** %53
%55 = tail call i32* @fopen(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%56 = icmp eq i32* %55, null
br i1 %56, label %57, label %70
57: ; preds = %48, %43
%58 = phi i8** [ %53, %48 ], [ %44, %43 ]
%59 = load i8*, i8** %58
%60 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0), i8* %59)
%61 = tail call i32 @exit(i32 4)
unreachable
62: ; preds = %43
%63 = load i32, i32* @SEEK_SET
%64 = tail call i64 @fseek(i32* %46, i32 6, i32 %63)
%65 = icmp eq i64 %64, 0
br i1 %65, label %70, label %66
66: ; preds = %62
%67 = load i8*, i8** %44
%68 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.15, i64 0, i64 0), i8* %67)
%69 = tail call i32 @exit(i32 5)
unreachable
70: ; preds = %48, %62
%71 = phi i64 [ 256, %62 ], [ 0, %48 ]
%72 = phi i64 [ undef, %62 ], [ %50, %48 ]
%73 = phi i64 [ undef, %62 ], [ %52, %48 ]
%74 = phi i32* [ %46, %62 ], [ %55, %48 ]
%75 = getelementptr inbounds [524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 %71
%76 = trunc i64 %71 to i32
%77 = sub nuw nsw i32 524288, %76
%78 = tail call i64 @fread(i8* %75, i32 1, i32 %77, i32* %74)
%79 = tail call i32 @fclose(i32* %74)
br i1 %35, label %80, label %92
80: ; preds = %70
%81 = tail call i32 @Write32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 4), i64 268432640)
%82 = tail call i32 @Write32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 8), i64 33554688)
%83 = tail call i32 @Write32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 12), i64 %78)
%84 = tail call i32 @Write32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 16), i64 33554688)
%85 = tail call i32 @Write32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 20), i64 %78)
%86 = tail call i32 @Write32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 24), i64 33554688)
%87 = tail call i32 @Write32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 28), i64 %78)
%88 = tail call i32 @Write32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 32), i64 33554688)
%89 = tail call i32 @Write32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 36), i64 %78)
%90 = tail call i32 @Write32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 40), i64 33554688)
%91 = tail call i32 @Write32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 44), i64 %78)
br label %95
92: ; preds = %70
%93 = tail call i32 @Write32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 248), i64 %72)
%94 = tail call i32 @Write32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 252), i64 %73)
br label %95
95: ; preds = %92, %80
%96 = add i64 %78, 3
%97 = and i64 %96, -4
%98 = add i64 %97, %71
%99 = add nsw i32 %0, -1
%100 = zext i32 %99 to i64
%101 = zext i32 %0 to i64
br label %102
102: ; preds = %95, %102
%103 = phi i64 [ 4, %95 ], [ %112, %102 ]
%104 = phi i64 [ %98, %95 ], [ %111, %102 ]
%105 = getelementptr inbounds i8*, i8** %1, i64 %103
%106 = load i8*, i8** %105
%107 = tail call i64 @PlaceImage(i8* %106, i64 %104, i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0), i32 524288)
%108 = icmp ult i64 %103, %100
%109 = add i64 %107, 4095
%110 = and i64 %109, -4096
%111 = select i1 %108, i64 %110, i64 %107
%112 = add nuw nsw i64 %103, 1
%113 = icmp eq i64 %112, %101
br i1 %113, label %114, label %102
114: ; preds = %102
%115 = tail call i64 @CalcCRC32(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0), i64 %111)
%116 = getelementptr inbounds [524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 %111
%117 = tail call i32 @Write32(i8* %116, i64 %115)
%118 = add i64 %111, 8
%119 = getelementptr inbounds i8*, i8** %1, i64 1
%120 = load i8*, i8** %119
%121 = tail call i32* @fopen(i8* %120, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0))
%122 = icmp eq i32* %121, null
br i1 %122, label %123, label %127
123: ; preds = %114
%124 = load i8*, i8** %119
%125 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.17, i64 0, i64 0), i8* %124)
%126 = tail call i32 @exit(i32 9)
unreachable
127: ; preds = %114
%128 = tail call i64 @fwrite(i8* getelementptr inbounds ([524288 x i8], [524288 x i8]* @main.aFirmware, i64 0, i64 0), i32 1, i64 %118, i32* %121)
%129 = tail call i32 @fclose(i32* %121)
%130 = icmp eq i64 %128, %118
br i1 %130, label %135, label %131
131: ; preds = %127
%132 = load i8*, i8** %119
%133 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.18, i64 0, i64 0), i64 %118, i8* %132)
%134 = tail call i32 @exit(i32 10)
unreachable
135: ; preds = %127
%136 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.19, i64 0, i64 0), i64 %118)
ret i32 0
}