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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int read32bit(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char buf[16], *entry = NULL;
  FILE *infile = NULL, *outfile = NULL;
  int unk1;
  int datastart;
  int filecount;
  int datastart2;
  int entrylen;
  int i;
  printf("fridge 0.0\n\n");
  if (argc != 2) {
    fprintf(stderr, "usage: %s BLAH.DPK\n\n", argv[0]);
    return 1;
  }
  if (!(infile = fopen(argv[1], "rb"))) {
    fprintf(stderr, "error opening %s for input", argv[1]);
    return 1;
  }
  fread(buf, 1, 16, infile);
  unk1 = read32bit(buf + 4);
  if (memcmp(buf, "FRID", 4)) {
    fprintf(stderr, "%s is not a FRID DPK file\n", argv[1]);
    return 1;
  }
  if (unk1 != 0xe0000000)
    fprintf(stderr,
            "expected 0xe0000000 at 0x04, got %#010x, moving on anyway...\n",
            unk1);
  datastart = read32bit(buf + 8);
  printf("data starts at: %#010x\n", datastart);
  filecount = read32bit(buf + 0xc);
  printf("%d files\n", filecount);
  fread(buf, 1, 16, infile);
  datastart2 = read32bit(buf);
  if (datastart2 != datastart)
    fprintf(stderr,
            "expected %#010x at 0x10, got %#010x, moving on anyway...\n",
            datastart2);
  entrylen = read32bit(buf + 4);
  printf("file entry length: %#x\n", entrylen);
  if (entrylen != 0x18) {
    fprintf(stderr, "I don't know how to deal with an entry length != 0x18\n");
    return 1;
  }
  if (read32bit(buf + 8) || read32bit(buf + 0xc))
    fprintf(
        stderr,
        "expected 0 from 0x14-0x1f, got %#010x,%#010x, moving on anyway...\n",
        read32bit(buf + 8), read32bit(buf + 0xc));
  entry = (char *)malloc(entrylen);
  if (!entry) {
    fprintf(stderr, "error allocating memory for entry buffer, %#x bytes\n",
            entrylen);
    return 1;
  }
  for (i = 0; i < filecount; i++) {
    int offset, size, unk2, memloc;
    fread(entry, 1, entrylen, infile);
    offset = read32bit(entry + 0xc);
    size = read32bit(entry + 0x10);
    unk2 = read32bit(entry + 0x14);
    printf("file %d\n\t%s\n\toffset: %#010x\tsize: %#010x\tunk2: %#010x\n", i,
           entry, offset, size, unk2);
    outfile = fopen(entry, "wb");
    if (!outfile) {
      fprintf(stderr, "error opening %s for output\n", entry);
      return 1;
    }
    memloc = ftell(infile);
    fseek(infile, offset, SEEK_SET);
    while (size >= 16) {
      fread(buf, 1, 16, infile);
      fwrite(buf, 1, 16, outfile);
      size -= 16;
    }
    if (size) {
      fread(buf, 1, size, infile);
      fwrite(buf, 1, size, outfile);
    }
    fclose(outfile);
    outfile = NULL;
    fseek(infile, memloc, SEEK_SET);
  }
  free(entry);
  entry = NULL;
  fclose(infile);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
je     1230 <main+0x70>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    163d <main+0x47d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde3(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    127d <main+0xbd>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    163d <main+0x47d>
lea    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10,%edx
call   1040 <fread@plt>
lea    -0x20(%rbp),%rdi
add    $0x4,%rdi
call   10c0 <read32bit@plt>
mov    %eax,-0x3c(%rbp)
lea    -0x20(%rbp),%rdi
lea    0xd91(%rip),%rsi
mov    $0x4,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
je     12ee <main+0x12e>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd6a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    163d <main+0x47d>
cmpl   $0xe0000000,-0x3c(%rbp)
je     1315 <main+0x155>
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
mov    -0x3c(%rbp),%edx
lea    0xd52(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    -0x20(%rbp),%rdi
add    $0x8,%rdi
call   10c0 <read32bit@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%esi
lea    0xd6f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x20(%rbp),%rdi
add    $0xc,%rdi
call   10c0 <read32bit@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%esi
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10,%edx
call   1040 <fread@plt>
lea    -0x20(%rbp),%rdi
call   10c0 <read32bit@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x40(%rbp),%eax
je     13a0 <main+0x1e0>
mov    0x2c53(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%edx
lea    0xd27(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    -0x20(%rbp),%rdi
add    $0x4,%rdi
call   10c0 <read32bit@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%esi
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x18,-0x4c(%rbp)
je     13ee <main+0x22e>
mov    0x2c0e(%rip),%rax
mov    (%rax),%edi
lea    0xd37(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    163d <main+0x47d>
lea    -0x20(%rbp),%rdi
add    $0x8,%rdi
call   10c0 <read32bit@plt>
cmp    $0x0,%eax
jne    141a <main+0x25a>
lea    -0x20(%rbp),%rdi
add    $0xc,%rdi
call   10c0 <read32bit@plt>
cmp    $0x0,%eax
je     1459 <main+0x299>
mov    0x2bbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
lea    -0x20(%rbp),%rdi
add    $0x8,%rdi
call   10c0 <read32bit@plt>
mov    %eax,-0x64(%rbp)
lea    -0x20(%rbp),%rdi
add    $0xc,%rdi
call   10c0 <read32bit@plt>
mov    -0x68(%rbp),%edi
mov    -0x64(%rbp),%edx
mov    %eax,%ecx
lea    0xcf7(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x4c(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1496 <main+0x2d6>
mov    0x2b69(%rip),%rax
mov    (%rax),%edi
mov    -0x4c(%rbp),%edx
lea    0xd09(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    163d <main+0x47d>
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1623 <main+0x463>
mov    -0x28(%rbp),%rdi
mov    -0x4c(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x28(%rbp),%rdi
add    $0xc,%rdi
call   10c0 <read32bit@plt>
mov    %eax,-0x54(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x10,%rdi
call   10c0 <read32bit@plt>
mov    %eax,-0x58(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x14,%rdi
call   10c0 <read32bit@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x50(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x54(%rbp),%ecx
mov    -0x58(%rbp),%r8d
mov    -0x5c(%rbp),%r9d
lea    0xcba(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
lea    0xcdf(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1554 <main+0x394>
mov    0x2aac(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xcba(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    163d <main+0x47d>
mov    -0x30(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,-0x60(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    0x2a6a(%rip),%rax
mov    (%rax),%edx
call   10b0 <fseek@plt>
cmpl   $0x10,-0x58(%rbp)
jl     15bb <main+0x3fb>
lea    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10,%edx
call   1040 <fread@plt>
lea    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10,%edx
call   10e0 <fwrite@plt>
mov    -0x58(%rbp),%eax
sub    $0x10,%eax
mov    %eax,-0x58(%rbp)
jmp    1575 <main+0x3b5>
cmpl   $0x0,-0x58(%rbp)
je     15ef <main+0x42f>
lea    -0x20(%rbp),%rdi
mov    -0x58(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
lea    -0x20(%rbp),%rdi
mov    -0x58(%rbp),%edx
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x60(%rbp),%esi
mov    0x29ca(%rip),%rax
mov    (%rax),%edx
call   10b0 <fseek@plt>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    149d <main+0x2dd>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0x1021(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x2,%ebx
jne    1271 <main+0xa1>
mov    0x8(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1287 <main+0xb7>
mov    %rax,%r15
lea    0x20(%rsp),%r13
mov    $0x1,%ebx
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x10,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
lea    0x24(%rsp),%r12
mov    %r12,%rdi
call   10d0 <read32bit@plt>
mov    %eax,%r14d
lea    0xdf1(%rip),%rsi
mov    %r13,%rdi
mov    $0x4,%edx
call   1080 <memcmp@plt>
test   %rax,%rax
je     12b8 <main+0xe8>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xdd0(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    12a7 <main+0xd7>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xd7b(%rip),%rsi
jmp    129b <main+0xcb>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xd7d(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0xe0000000,%r14d
je     12db <main+0x10b>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
lea    0xd82(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0x28(%rsp),%r14
mov    %r14,%rdi
call   10d0 <read32bit@plt>
mov    %eax,%ebp
lea    0xda0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x2c(%rsp),%r13
mov    %r13,%rdi
call   10d0 <read32bit@plt>
lea    0xd9b(%rip),%rdi
mov    %eax,0xc(%rsp)
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x10,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
mov    %rbx,%rdi
call   10d0 <read32bit@plt>
cmp    %ebp,%eax
je     135a <main+0x18a>
mov    0x2c98(%rip),%rcx
mov    (%rcx),%edi
lea    0xd62(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r12,%rdi
call   10d0 <read32bit@plt>
mov    %eax,%ebx
lea    0xd82(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    $0x18,%ebx
jne    1554 <main+0x384>
mov    %r14,%rdi
call   10d0 <read32bit@plt>
test   %eax,%eax
jne    1395 <main+0x1c5>
mov    %r13,%rdi
call   10d0 <read32bit@plt>
test   %eax,%eax
je     13c4 <main+0x1f4>
mov    0x2c44(%rip),%rax
mov    (%rax),%ebx
mov    %r14,%rdi
call   10d0 <read32bit@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   10d0 <read32bit@plt>
lea    0xd85(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x18,%edi
call   10b0 <malloc@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     1589 <main+0x3b9>
cmpl   $0x0,0xc(%rsp)
jle    1570 <main+0x3a0>
mov    0x10(%rsp),%rax
lea    0xc(%rax),%rcx
mov    %rcx,0x40(%rsp)
lea    0x10(%rax),%rcx
mov    %rcx,0x38(%rsp)
add    $0x14,%rax
mov    %rax,0x30(%rsp)
lea    0x20(%rsp),%r14
xor    %ebx,%ebx
jmp    1437 <main+0x267>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    (%rbx),%edx
mov    %r15,%rdi
mov    0x18(%rsp),%esi
call   10c0 <fseek@plt>
mov    0x1c(%rsp),%ebx
add    $0x1,%ebx
cmp    0xc(%rsp),%ebx
je     1570 <main+0x3a0>
mov    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x18,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
mov    0x40(%rsp),%rdi
call   10d0 <read32bit@plt>
mov    %eax,%ebp
mov    0x38(%rsp),%rdi
call   10d0 <read32bit@plt>
mov    %eax,%r13d
mov    0x30(%rsp),%rdi
call   10d0 <read32bit@plt>
lea    0xd39(%rip),%rdi
mov    %ebx,0x1c(%rsp)
mov    %ebx,%esi
mov    %r12,%rdx
mov    %ebp,%ecx
mov    %r13d,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
lea    0xd4e(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     15aa <main+0x3da>
mov    %rax,%r12
mov    %r15,%rdi
call   10a0 <ftell@plt>
mov    %eax,0x18(%rsp)
mov    0x2b17(%rip),%rbx
mov    (%rbx),%edx
mov    %r15,%rdi
mov    %ebp,%esi
call   10c0 <fseek@plt>
cmp    $0x10,%r13d
jl     1520 <main+0x350>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x10,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x10,%edx
mov    %r12,%rcx
call   10f0 <fwrite@plt>
lea    -0x10(%r13),%ebp
cmp    $0x1f,%r13d
mov    %ebp,%r13d
ja     14e0 <main+0x310>
test   %ebp,%ebp
jne    152b <main+0x35b>
jmp    1410 <main+0x240>
mov    %r13d,%ebp
test   %ebp,%ebp
je     1410 <main+0x240>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r12,%rcx
call   10f0 <fwrite@plt>
jmp    1410 <main+0x240>
mov    0x2a85(%rip),%rax
mov    (%rax),%edi
lea    0xba1(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    12a2 <main+0xd2>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
xor    %ebx,%ebx
jmp    12a7 <main+0xd7>
mov    0x2a50(%rip),%rax
mov    (%rax),%edi
lea    0xbe6(%rip),%rsi
mov    $0x18,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    12a2 <main+0xd2>
mov    0x2a2f(%rip),%rax
mov    (%rax),%edi
lea    0xc34(%rip),%rsi
mov    0x10(%rsp),%rdx
jmp    129b <main+0xcb>

LLVM IR (-O0):
@.str = [13 x i8] c"fridge 0.0\0A\0A\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"usage: %s BLAH.DPK\0A\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [27 x i8] c"error opening %s for input\00"
@.str.4 = [5 x i8] c"FRID\00"
@.str.5 = [27 x i8] c"%s is not a FRID DPK file\0A\00"
@.str.6 = [62 x i8] c"expected 0xe0000000 at 0x04, got %x, moving on anyway...\0A\00"
@.str.7 = [24 x i8] c"data starts at: %x\0A\00"
@.str.8 = [10 x i8] c"%d files\0A\00"
@.str.9 = [58 x i8] c"expected %x at 0x10, got %x, moving on anyway...\0A\00"
@.str.10 = [24 x i8] c"file entry length: %#x\0A\00"
@.str.11 = [55 x i8] c"I don't know how to deal with an entry length != 0x18\0A\00"
@.str.12 = [67 x i8] c"expected 0 from 0x14-0x1f, got %x,%x, moving on anyway...\0A\00"
@.str.13 = [53 x i8] c"error allocating memory for entry buffer, %#x bytes\0A\00"
@.str.14 = [55 x i8] c"file %d\0A\09%s\0A\09offset: %x\09size: %x\09unk2: %x\0A\00"
@.str.15 = [3 x i8] c"wb\00"
@.str.16 = [29 x i8] c"error opening %s for output\0A\00"
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [16 x i8]
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
store i32* null, i32** %8
store i32* null, i32** %9
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 2
br i1 %22, label %23, label %29
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %27)
store i32 1, i32* %3
br label %206
29: ; preds = %2
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %33, i32** %8
%34 = icmp ne i32* %33, null
br i1 %34, label %41, label %35
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %39)
store i32 1, i32* %3
br label %206
41: ; preds = %29
%42 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%43 = load i32*, i32** %8
%44 = call i32 @fread(i8* %42, i32 1, i32 16, i32* %43)
%45 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%46 = getelementptr inbounds i8, i8* %45, i64 4
%47 = call i32 @read32bit(i8* %46)
store i32 %47, i32* %10
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%49 = call i64 @memcmp(i8* %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %57
51: ; preds = %41
%52 = load i32, i32* @stderr
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 1
%55 = load i8*, i8** %54
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %55)
store i32 1, i32* %3
br label %206
57: ; preds = %41
%58 = load i32, i32* %10
%59 = icmp ne i32 %58, -536870912
br i1 %59, label %60, label %64
60: ; preds = %57
%61 = load i32, i32* @stderr
%62 = load i32, i32* %10
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.6, i64 0, i64 0), i32 %62)
br label %64
64: ; preds = %60, %57
%65 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%66 = getelementptr inbounds i8, i8* %65, i64 8
%67 = call i32 @read32bit(i8* %66)
store i32 %67, i32* %11
%68 = load i32, i32* %11
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %68)
%70 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%71 = getelementptr inbounds i8, i8* %70, i64 12
%72 = call i32 @read32bit(i8* %71)
store i32 %72, i32* %12
%73 = load i32, i32* %12
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %73)
%75 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%76 = load i32*, i32** %8
%77 = call i32 @fread(i8* %75, i32 1, i32 16, i32* %76)
%78 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%79 = call i32 @read32bit(i8* %78)
store i32 %79, i32* %13
%80 = load i32, i32* %13
%81 = load i32, i32* %11
%82 = icmp ne i32 %80, %81
br i1 %82, label %83, label %87
83: ; preds = %64
%84 = load i32, i32* @stderr
%85 = load i32, i32* %13
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.9, i64 0, i64 0), i32 %85)
br label %87
87: ; preds = %83, %64
%88 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%89 = getelementptr inbounds i8, i8* %88, i64 4
%90 = call i32 @read32bit(i8* %89)
store i32 %90, i32* %14
%91 = load i32, i32* %14
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i32 %91)
%93 = load i32, i32* %14
%94 = icmp ne i32 %93, 24
br i1 %94, label %95, label %98
95: ; preds = %87
%96 = load i32, i32* @stderr
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %3
br label %206
98: ; preds = %87
%99 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%100 = getelementptr inbounds i8, i8* %99, i64 8
%101 = call i32 @read32bit(i8* %100)
%102 = icmp ne i32 %101, 0
br i1 %102, label %108, label %103
103: ; preds = %98
%104 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%105 = getelementptr inbounds i8, i8* %104, i64 12
%106 = call i32 @read32bit(i8* %105)
%107 = icmp ne i32 %106, 0
br i1 %107, label %108, label %117
108: ; preds = %103, %98
%109 = load i32, i32* @stderr
%110 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%111 = getelementptr inbounds i8, i8* %110, i64 8
%112 = call i32 @read32bit(i8* %111)
%113 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%114 = getelementptr inbounds i8, i8* %113, i64 12
%115 = call i32 @read32bit(i8* %114)
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.12, i64 0, i64 0), i32 %112, i32 %115)
br label %117
117: ; preds = %108, %103
%118 = load i32, i32* %14
%119 = call i64 @malloc(i32 %118)
%120 = inttoptr i64 %119 to i8*
store i8* %120, i8** %7
%121 = load i8*, i8** %7
%122 = icmp ne i8* %121, null
br i1 %122, label %127, label %123
123: ; preds = %117
%124 = load i32, i32* @stderr
%125 = load i32, i32* %14
%126 = call i32 (i32, i8*, ...) @fprintf(i32 %124, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.13, i64 0, i64 0), i32 %125)
store i32 1, i32* %3
br label %206
127: ; preds = %117
store i32 0, i32* %15
br label %128
128: ; preds = %198, %127
%129 = load i32, i32* %15
%130 = load i32, i32* %12
%131 = icmp slt i32 %129, %130
br i1 %131, label %132, label %201
132: ; preds = %128
%133 = load i8*, i8** %7
%134 = load i32, i32* %14
%135 = load i32*, i32** %8
%136 = call i32 @fread(i8* %133, i32 1, i32 %134, i32* %135)
%137 = load i8*, i8** %7
%138 = getelementptr inbounds i8, i8* %137, i64 12
%139 = call i32 @read32bit(i8* %138)
store i32 %139, i32* %16
%140 = load i8*, i8** %7
%141 = getelementptr inbounds i8, i8* %140, i64 16
%142 = call i32 @read32bit(i8* %141)
store i32 %142, i32* %17
%143 = load i8*, i8** %7
%144 = getelementptr inbounds i8, i8* %143, i64 20
%145 = call i32 @read32bit(i8* %144)
store i32 %145, i32* %18
%146 = load i32, i32* %15
%147 = load i8*, i8** %7
%148 = load i32, i32* %16
%149 = load i32, i32* %17
%150 = load i32, i32* %18
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.14, i64 0, i64 0), i32 %146, i8* %147, i32 %148, i32 %149, i32 %150)
%152 = load i8*, i8** %7
%153 = call i32* @fopen(i8* %152, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0))
store i32* %153, i32** %9
%154 = load i32*, i32** %9
%155 = icmp ne i32* %154, null
br i1 %155, label %160, label %156
156: ; preds = %132
%157 = load i32, i32* @stderr
%158 = load i8*, i8** %7
%159 = call i32 (i32, i8*, ...) @fprintf(i32 %157, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.16, i64 0, i64 0), i8* %158)
store i32 1, i32* %3
br label %206
160: ; preds = %132
%161 = load i32*, i32** %8
%162 = call i32 @ftell(i32* %161)
store i32 %162, i32* %19
%163 = load i32*, i32** %8
%164 = load i32, i32* %16
%165 = load i32, i32* @SEEK_SET
%166 = call i32 @fseek(i32* %163, i32 %164, i32 %165)
br label %167
167: ; preds = %170, %160
%168 = load i32, i32* %17
%169 = icmp sge i32 %168, 16
br i1 %169, label %170, label %179
170: ; preds = %167
%171 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%172 = load i32*, i32** %8
%173 = call i32 @fread(i8* %171, i32 1, i32 16, i32* %172)
%174 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%175 = load i32*, i32** %9
%176 = call i32 @fwrite(i8* %174, i32 1, i32 16, i32* %175)
%177 = load i32, i32* %17
%178 = sub nsw i32 %177, 16
store i32 %178, i32* %17
br label %167
179: ; preds = %167
%180 = load i32, i32* %17
%181 = icmp ne i32 %180, 0
br i1 %181, label %182, label %191
182: ; preds = %179
%183 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%184 = load i32, i32* %17
%185 = load i32*, i32** %8
%186 = call i32 @fread(i8* %183, i32 1, i32 %184, i32* %185)
%187 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%188 = load i32, i32* %17
%189 = load i32*, i32** %9
%190 = call i32 @fwrite(i8* %187, i32 1, i32 %188, i32* %189)
br label %191
191: ; preds = %182, %179
%192 = load i32*, i32** %9
%193 = call i32 @fclose(i32* %192)
store i32* null, i32** %9
%194 = load i32*, i32** %8
%195 = load i32, i32* %19
%196 = load i32, i32* @SEEK_SET
%197 = call i32 @fseek(i32* %194, i32 %195, i32 %196)
br label %198
198: ; preds = %191
%199 = load i32, i32* %15
%200 = add nsw i32 %199, 1
store i32 %200, i32* %15
br label %128
201: ; preds = %128
%202 = load i8*, i8** %7
%203 = call i32 @free(i8* %202)
store i8* null, i8** %7
%204 = load i32*, i32** %8
%205 = call i32 @fclose(i32* %204)
br label %206
206: ; preds = %201, %156, %123, %95, %51, %35, %23
%207 = load i32, i32* %3
ret i32 %207
}

LLVM IR (-O2):
@stderr = global i32 0
@.str.1 = [21 x i8] c"usage: %s BLAH.DPK\0A\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [27 x i8] c"error opening %s for input\00"
@.str.4 = [5 x i8] c"FRID\00"
@.str.5 = [27 x i8] c"%s is not a FRID DPK file\0A\00"
@.str.6 = [62 x i8] c"expected 0xe0000000 at 0x04, got %x, moving on anyway...\0A\00"
@.str.7 = [24 x i8] c"data starts at: %x\0A\00"
@.str.8 = [10 x i8] c"%d files\0A\00"
@.str.9 = [58 x i8] c"expected %x at 0x10, got %x, moving on anyway...\0A\00"
@.str.10 = [24 x i8] c"file entry length: %#x\0A\00"
@.str.11 = [55 x i8] c"I don't know how to deal with an entry length != 0x18\0A\00"
@.str.12 = [67 x i8] c"expected 0 from 0x14-0x1f, got %x,%x, moving on anyway...\0A\00"
@.str.13 = [53 x i8] c"error allocating memory for entry buffer, %#x bytes\0A\00"
@.str.14 = [55 x i8] c"file %d\0A\09%s\0A\09offset: %x\09size: %x\09unk2: %x\0A\00"
@.str.15 = [3 x i8] c"wb\00"
@.str.16 = [29 x i8] c"error opening %s for output\0A\00"
@SEEK_SET = global i32 0
@str = [12 x i8] c"fridge 0.0\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%6 = icmp eq i32 %0, 2
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %117
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %12
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %18)
br label %117
20: ; preds = %11
%21 = call i32 @fread(i8* %4, i32 1, i32 16, i32* %14)
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 4
%23 = call i32 @read32bit(i8* %22)
%24 = call i64 @memcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%25 = icmp eq i64 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %12
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %28)
br label %117
30: ; preds = %20
%31 = icmp eq i32 %23, -536870912
br i1 %31, label %35, label %32
32: ; preds = %30
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.6, i64 0, i64 0), i32 %23)
br label %35
35: ; preds = %32, %30
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 8
%37 = call i32 @read32bit(i8* %36)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 12
%40 = call i32 @read32bit(i8* %39)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %40)
%42 = call i32 @fread(i8* %4, i32 1, i32 16, i32* %14)
%43 = call i32 @read32bit(i8* %4)
%44 = icmp eq i32 %43, %37
br i1 %44, label %48, label %45
45: ; preds = %35
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.9, i64 0, i64 0), i32 %43)
br label %48
48: ; preds = %45, %35
%49 = call i32 @read32bit(i8* %22)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i32 %49)
%51 = icmp eq i32 %49, 24
br i1 %51, label %55, label %52
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.11, i64 0, i64 0))
br label %117
55: ; preds = %48
%56 = call i32 @read32bit(i8* %36)
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = call i32 @read32bit(i8* %39)
%60 = icmp eq i32 %59, 0
br i1 %60, label %66, label %61
61: ; preds = %58, %55
%62 = load i32, i32* @stderr
%63 = call i32 @read32bit(i8* %36)
%64 = call i32 @read32bit(i8* %39)
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.12, i64 0, i64 0), i32 %63, i32 %64)
br label %66
66: ; preds = %61, %58
%67 = call i64 @malloc(i32 24)
%68 = inttoptr i64 %67 to i8*
%69 = icmp eq i64 %67, 0
br i1 %69, label %76, label %70
70: ; preds = %66
%71 = icmp sgt i32 %40, 0
br i1 %71, label %72, label %114
72: ; preds = %70
%73 = getelementptr inbounds i8, i8* %68, i64 12
%74 = getelementptr inbounds i8, i8* %68, i64 16
%75 = getelementptr inbounds i8, i8* %68, i64 20
br label %85
76: ; preds = %66
%77 = load i32, i32* @stderr
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.13, i64 0, i64 0), i32 24)
br label %117
79: ; preds = %111, %108
%80 = call i32 @fclose(i32* %92)
%81 = load i32, i32* @SEEK_SET
%82 = call i32 @fseek(i32* %14, i32 %98, i32 %81)
%83 = add nuw nsw i32 %86, 1
%84 = icmp eq i32 %83, %40
br i1 %84, label %114, label %85
85: ; preds = %72, %79
%86 = phi i32 [ 0, %72 ], [ %83, %79 ]
%87 = call i32 @fread(i8* %68, i32 1, i32 24, i32* %14)
%88 = call i32 @read32bit(i8* %73)
%89 = call i32 @read32bit(i8* %74)
%90 = call i32 @read32bit(i8* %75)
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.14, i64 0, i64 0), i32 %86, i8* %68, i32 %88, i32 %89, i32 %90)
%92 = call i32* @fopen(i8* %68, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0))
%93 = icmp eq i32* %92, null
br i1 %93, label %94, label %97
94: ; preds = %85
%95 = load i32, i32* @stderr
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.16, i64 0, i64 0), i8* %68)
br label %117
97: ; preds = %85
%98 = call i32 @ftell(i32* %14)
%99 = load i32, i32* @SEEK_SET
%100 = call i32 @fseek(i32* %14, i32 %88, i32 %99)
%101 = icmp sgt i32 %89, 15
br i1 %101, label %102, label %108
102: ; preds = %97, %102
%103 = phi i32 [ %106, %102 ], [ %89, %97 ]
%104 = call i32 @fread(i8* %4, i32 1, i32 16, i32* %14)
%105 = call i32 @fwrite(i8* %4, i32 1, i32 16, i32* %92)
%106 = add nsw i32 %103, -16
%107 = icmp ugt i32 %103, 31
br i1 %107, label %102, label %108
108: ; preds = %102, %97
%109 = phi i32 [ %89, %97 ], [ %106, %102 ]
%110 = icmp eq i32 %109, 0
br i1 %110, label %79, label %111
111: ; preds = %108
%112 = call i32 @fread(i8* %4, i32 1, i32 %109, i32* %14)
%113 = call i32 @fwrite(i8* %4, i32 1, i32 %109, i32* %92)
br label %79
114: ; preds = %79, %70
%115 = call i32 @free(i8* %68)
%116 = call i32 @fclose(i32* %14)
br label %117
117: ; preds = %94, %114, %76, %52, %26, %16, %7
%118 = phi i32 [ 1, %7 ], [ 1, %26 ], [ 1, %52 ], [ 0, %114 ], [ 1, %76 ], [ 1, %16 ], [ 1, %94 ]
ret i32 %118
}