#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 u_int;
typedef char u_char;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ chdir(char *);
char *create_dir(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int fread(void *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ getfile(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read_err();
int /*<<< orphan*/ std_err();
int /*<<< orphan*/ stdout;
void unpack(u_char *input, u_char *outdir, u_char *list) {
  FILE *fd, *fdl;
  u_int i, id, attr, num, name, off, size, curroff, headsize;
  u_char buff[512], *p;
  printf("- open input PAK file:       %s\n", input);
  fd = fopen(input, "rb");
  if (!fd)
    std_err();
  printf("- create output listfile:    %s\n", list);
  fdl = fopen(list, "wb");
  if (!fdl)
    std_err();
  printf("- enter in output directory: %s\n", outdir);
  if (chdir(outdir) < 0)
    std_err();
  if (fread((void *)&id, 4, 1, fd) != 1)
    read_err();
  printf("- ID:                        0x%08x\n", id);
  fprintf(fdl,
          "%08x"
          " // ID\n",
          id);
  if (fread((void *)&num, 4, 1, fd) != 1)
    read_err();
  printf("- Number of files:           0x%08x\n", num);
  fprintf(fdl,
          "%08x"
          " // files\n",
          num);
  for (i = 0; i < num; i++) {
    if (fread((void *)&name, 4, 1, fd) != 1)
      read_err();
    if (fseek(fd, name + 4 + 4, SEEK_CUR) < 0)
      std_err();
  }
  headsize = ftell(fd);
  printf("- Header size:               0x%08x\n", headsize);
  fprintf(fdl,
          "%08x"
          " // header size\n",
          headsize);
  fseek(fd, 8, SEEK_SET);
  fputs("\n"
        "Filesize     Offset   Filename\n"
        "----------------------------------------------------------------------"
        "--------\n",
        stdout);
  for (i = 0; i < num; i++) {
    if (fread((void *)&name, 4, 1, fd) != 1)
      read_err();
    if (fread(buff, name, 1, fd) != 1)
      read_err();
    buff[name] = 0;
    if (fread((void *)&off, 4, 1, fd) != 1)
      read_err();
    if (fread((void *)&size, 4, 1, fd) != 1)
      read_err();
    off += headsize;
    size -= 12;
    printf("%-12u %08x %s\n", size, off, buff);
    curroff = ftell(fd);
    if (fseek(fd, off, SEEK_SET) < 0)
      std_err();
    if (fread((void *)&attr, 4, 1, fd) != 1)
      read_err();
    fprintf(fdl,
            "%08x"
            " %s\n",
            attr, buff);
    p = create_dir(buff);
    getfile(fd, p, size);
    if (fseek(fd, curroff, SEEK_SET) < 0)
      std_err();
  }
  fclose(fd);
  fclose(fdl);
}


x86 assembly (clang, -O0):
<unpack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121f <unpack+0x4f>
mov    $0x0,%al
call   10f0 <std_err@plt>
mov    -0x18(%rbp),%rsi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1257 <unpack+0x87>
mov    $0x0,%al
call   10f0 <std_err@plt>
mov    -0x10(%rbp),%rsi
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <chdir@plt>
cmp    $0x0,%rax
jge    1283 <unpack+0xb3>
mov    $0x0,%al
call   10f0 <std_err@plt>
lea    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     12aa <unpack+0xda>
mov    $0x0,%al
call   1050 <read_err@plt>
mov    -0x30(%rbp),%esi
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%edx
lea    0xdc5(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
lea    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     12f7 <unpack+0x127>
mov    $0x0,%al
call   1050 <read_err@plt>
mov    -0x38(%rbp),%esi
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%edx
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1396 <unpack+0x1c6>
lea    -0x3c(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1357 <unpack+0x187>
mov    $0x0,%al
call   1050 <read_err@plt>
mov    -0x20(%rbp),%rdi
mov    -0x3c(%rbp),%esi
add    $0x4,%esi
add    $0x4,%esi
mov    0x2c7d(%rip),%rax
mov    (%rax),%edx
call   10c0 <fseek@plt>
cmp    $0x0,%rax
jge    1383 <unpack+0x1b3>
mov    $0x0,%al
call   10f0 <std_err@plt>
jmp    1388 <unpack+0x1b8>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1324 <unpack+0x154>
mov    -0x20(%rbp),%rdi
call   10a0 <ftell@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%esi
lea    0xd22(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x4c(%rbp),%edx
lea    0xd32(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2c05(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%esi
call   10c0 <fseek@plt>
mov    0x2bea(%rip),%rax
mov    (%rax),%esi
lea    0xd19(%rip),%rdi
call   1080 <fputs@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    15b1 <unpack+0x3e1>
lea    -0x3c(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     142e <unpack+0x25e>
mov    $0x0,%al
call   1050 <read_err@plt>
lea    -0x250(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1456 <unpack+0x286>
mov    $0x0,%al
call   1050 <read_err@plt>
movslq -0x3c(%rbp),%rax
movb   $0x0,-0x250(%rbp,%rax,1)
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1489 <unpack+0x2b9>
mov    $0x0,%al
call   1050 <read_err@plt>
lea    -0x44(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     14b0 <unpack+0x2e0>
mov    $0x0,%al
call   1050 <read_err@plt>
mov    -0x4c(%rbp),%eax
add    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x44(%rbp),%eax
sub    $0xc,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%esi
mov    -0x40(%rbp),%edx
lea    -0x250(%rbp),%rcx
lea    0xca2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <ftell@plt>
mov    %eax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%esi
mov    0x2ae1(%rip),%rax
mov    (%rax),%edx
call   10c0 <fseek@plt>
cmp    $0x0,%rax
jge    150f <unpack+0x33f>
mov    $0x0,%al
call   10f0 <std_err@plt>
lea    -0x34(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1536 <unpack+0x366>
mov    $0x0,%al
call   1050 <read_err@plt>
mov    -0x28(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    -0x250(%rbp),%rcx
lea    0xc33(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
lea    -0x250(%rbp),%rdi
call   10b0 <create_dir@plt>
mov    %rax,-0x258(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x258(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   10e0 <getfile@plt>
mov    -0x20(%rbp),%rdi
mov    -0x48(%rbp),%esi
mov    0x2a52(%rip),%rax
mov    (%rax),%edx
call   10c0 <fseek@plt>
cmp    $0x0,%rax
jge    159e <unpack+0x3ce>
mov    $0x0,%al
call   10f0 <std_err@plt>
jmp    15a3 <unpack+0x3d3>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    13fb <unpack+0x22b>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpack>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x238,%rsp
mov    %rdx,%rbp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe0f(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe1f(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1219 <unpack+0x49>
xor    %eax,%eax
call   10f0 <std_err@plt>
lea    0xe04(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe14(%rip),%rsi
mov    %rbp,%rdi
call   10d0 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
jne    1248 <unpack+0x78>
xor    %eax,%eax
call   10f0 <std_err@plt>
lea    0xdf9(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1060 <chdir@plt>
test   %rax,%rax
jns    126d <unpack+0x9d>
xor    %eax,%eax
call   10f0 <std_err@plt>
lea    0x24(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1290 <unpack+0xc0>
xor    %eax,%eax
call   1050 <read_err@plt>
mov    0x24(%rsp),%ebp
lea    0xdce(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xde3(%rip),%rsi
mov    %r13,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0x1c(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     12da <unpack+0x10a>
xor    %eax,%eax
call   1050 <read_err@plt>
mov    0x1c(%rsp),%r15d
lea    0xdb4(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdc8(%rip),%rsi
mov    %r13,%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
test   %r15d,%r15d
jle    136c <unpack+0x19c>
lea    0xc(%rsp),%r14
mov    0x2cd3(%rip),%r12
mov    %r15d,%ebp
jmp    133d <unpack+0x16d>
nopw   0x0(%rax,%rax,1)
mov    0xc(%rsp),%esi
add    $0x8,%esi
mov    (%r12),%edx
mov    %rbx,%rdi
call   10c0 <fseek@plt>
test   %rax,%rax
js     1360 <unpack+0x190>
add    $0xffffffff,%ebp
je     136c <unpack+0x19c>
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1320 <unpack+0x150>
xor    %eax,%eax
call   1050 <read_err@plt>
jmp    1320 <unpack+0x150>
xor    %eax,%eax
call   10f0 <std_err@plt>
add    $0xffffffff,%ebp
jne    133d <unpack+0x16d>
mov    %rbx,%rdi
call   10a0 <ftell@plt>
mov    %eax,%ebp
lea    0xd51(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd66(%rip),%rsi
mov    %r13,0x28(%rsp)
mov    %r13,%rdi
mov    %ebp,0x18(%rsp)
mov    %ebp,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2c2f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x8,%esi
call   10c0 <fseek@plt>
mov    0x2c11(%rip),%rax
mov    (%rax),%esi
lea    0xd40(%rip),%rdi
call   1080 <fputs@plt>
test   %r15d,%r15d
jle    1561 <unpack+0x391>
lea    0x30(%rsp),%r13
jmp    1437 <unpack+0x267>
nopl   (%rax)
mov    0x20(%rsp),%edx
mov    0x28(%rsp),%rdi
lea    0xd8e(%rip),%rsi
mov    %r13,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r13,%rdi
call   10b0 <create_dir@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r12d,%edx
call   10e0 <getfile@plt>
mov    0x2bc1(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14d,%esi
call   10c0 <fseek@plt>
test   %rax,%rax
js     1550 <unpack+0x380>
add    $0xffffffff,%r15d
je     1561 <unpack+0x391>
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     145a <unpack+0x28a>
xor    %eax,%eax
call   1050 <read_err@plt>
mov    0xc(%rsp),%ebp
mov    %r13,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     147c <unpack+0x2ac>
xor    %eax,%eax
call   1050 <read_err@plt>
movslq %ebp,%rax
movb   $0x0,0x30(%rsp,%rax,1)
lea    0x14(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     14a7 <unpack+0x2d7>
xor    %eax,%eax
call   1050 <read_err@plt>
lea    0x10(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     14ca <unpack+0x2fa>
xor    %eax,%eax
call   1050 <read_err@plt>
mov    0x14(%rsp),%ebp
add    0x18(%rsp),%ebp
mov    %ebp,0x14(%rsp)
mov    0x10(%rsp),%r12d
add    $0xfffffff4,%r12d
mov    %r12d,0x10(%rsp)
lea    0xc8d(%rip),%rdi
mov    %r12d,%esi
mov    %ebp,%edx
mov    %r13,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   10a0 <ftell@plt>
mov    %eax,%r14d
mov    0x2acc(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   10c0 <fseek@plt>
test   %rax,%rax
jns    1524 <unpack+0x354>
xor    %eax,%eax
call   10f0 <std_err@plt>
lea    0x20(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     13e0 <unpack+0x210>
xor    %eax,%eax
call   1050 <read_err@plt>
jmp    13e0 <unpack+0x210>
xor    %eax,%eax
call   10f0 <std_err@plt>
add    $0xffffffff,%r15d
jne    1437 <unpack+0x267>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x28(%rsp),%rdi
call   1040 <fclose@plt>
add    $0x238,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"- open input PAK file: %s\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [33 x i8] c"- create output listfile: %s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [33 x i8] c"- enter in output directory: %s\0A\00"
@.str.5 = [37 x i8] c"- ID: 0x%08x\0A\00"
@.str.6 = [12 x i8] c"%08x // ID\0A\00"
@.str.7 = [37 x i8] c"- Number of files: 0x%08x\0A\00"
@.str.8 = [15 x i8] c"%08x // files\0A\00"
@SEEK_CUR = global i32 0
@.str.9 = [37 x i8] c"- Header size: 0x%08x\0A\00"
@.str.10 = [21 x i8] c"%08x // header size\0A\00"
@SEEK_SET = global i32 0
@.str.11 = [112 x i8] c"\0AFilesize Offset Filename\0A------------------------------------------------------------------------------\0A\00"
@stdout = global i32 0
@.str.12 = [15 x i8] c"%-12u %08x %s\0A\00"
@.str.13 = [9 x i8] c"%08x %s\0A\00"
define void @unpack(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%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 [512 x i8]
%19 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%20 = load i8*, i8** %4
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %4
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %7
%24 = load i32*, i32** %7
%25 = icmp ne i32* %24, null
br i1 %25, label %28, label %26
26: ; preds = %3
%27 = call i32 (...) @std_err()
br label %28
28: ; preds = %26, %3
%29 = load i8*, i8** %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = load i8*, i8** %6
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %32, i32** %8
%33 = load i32*, i32** %8
%34 = icmp ne i32* %33, null
br i1 %34, label %37, label %35
35: ; preds = %28
%36 = call i32 (...) @std_err()
br label %37
37: ; preds = %35, %28
%38 = load i8*, i8** %5
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %38)
%40 = load i8*, i8** %5
%41 = call i64 @chdir(i8* %40)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 (...) @std_err()
br label %45
45: ; preds = %43, %37
%46 = bitcast i32* %10 to i8*
%47 = load i32*, i32** %7
%48 = call i32 @fread(i8* %46, i32 4, i32 1, i32* %47)
%49 = icmp ne i32 %48, 1
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = call i32 (...) @read_err()
br label %52
52: ; preds = %50, %45
%53 = load i32, i32* %10
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %53)
%55 = load i32*, i32** %8
%56 = load i32, i32* %10
%57 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %55, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %56)
%58 = bitcast i32* %12 to i8*
%59 = load i32*, i32** %7
%60 = call i32 @fread(i8* %58, i32 4, i32 1, i32* %59)
%61 = icmp ne i32 %60, 1
br i1 %61, label %62, label %64
62: ; preds = %52
%63 = call i32 (...) @read_err()
br label %64
64: ; preds = %62, %52
%65 = load i32, i32* %12
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %65)
%67 = load i32*, i32** %8
%68 = load i32, i32* %12
%69 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i32 %68)
store i32 0, i32* %9
br label %70
70: ; preds = %92, %64
%71 = load i32, i32* %9
%72 = load i32, i32* %12
%73 = icmp slt i32 %71, %72
br i1 %73, label %74, label %95
74: ; preds = %70
%75 = bitcast i32* %13 to i8*
%76 = load i32*, i32** %7
%77 = call i32 @fread(i8* %75, i32 4, i32 1, i32* %76)
%78 = icmp ne i32 %77, 1
br i1 %78, label %79, label %81
79: ; preds = %74
%80 = call i32 (...) @read_err()
br label %81
81: ; preds = %79, %74
%82 = load i32*, i32** %7
%83 = load i32, i32* %13
%84 = add nsw i32 %83, 4
%85 = add nsw i32 %84, 4
%86 = load i32, i32* @SEEK_CUR
%87 = call i64 @fseek(i32* %82, i32 %85, i32 %86)
%88 = icmp slt i64 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %81
%90 = call i32 (...) @std_err()
br label %91
91: ; preds = %89, %81
br label %92
92: ; preds = %91
%93 = load i32, i32* %9
%94 = add nsw i32 %93, 1
store i32 %94, i32* %9
br label %70
95: ; preds = %70
%96 = load i32*, i32** %7
%97 = call i32 @ftell(i32* %96)
store i32 %97, i32* %17
%98 = load i32, i32* %17
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), i32 %98)
%100 = load i32*, i32** %8
%101 = load i32, i32* %17
%102 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %100, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i32 %101)
%103 = load i32*, i32** %7
%104 = load i32, i32* @SEEK_SET
%105 = call i64 @fseek(i32* %103, i32 8, i32 %104)
%106 = load i32, i32* @stdout
%107 = call i32 @fputs(i8* getelementptr inbounds ([112 x i8], [112 x i8]* @.str.11, i64 0, i64 0), i32 %106)
store i32 0, i32* %9
br label %108
108: ; preds = %189, %95
%109 = load i32, i32* %9
%110 = load i32, i32* %12
%111 = icmp slt i32 %109, %110
br i1 %111, label %112, label %192
112: ; preds = %108
%113 = bitcast i32* %13 to i8*
%114 = load i32*, i32** %7
%115 = call i32 @fread(i8* %113, i32 4, i32 1, i32* %114)
%116 = icmp ne i32 %115, 1
br i1 %116, label %117, label %119
117: ; preds = %112
%118 = call i32 (...) @read_err()
br label %119
119: ; preds = %117, %112
%120 = getelementptr inbounds [512 x i8], [512 x i8]* %18, i64 0, i64 0
%121 = load i32, i32* %13
%122 = load i32*, i32** %7
%123 = call i32 @fread(i8* %120, i32 %121, i32 1, i32* %122)
%124 = icmp ne i32 %123, 1
br i1 %124, label %125, label %127
125: ; preds = %119
%126 = call i32 (...) @read_err()
br label %127
127: ; preds = %125, %119
%128 = load i32, i32* %13
%129 = sext i32 %128 to i64
%130 = getelementptr inbounds [512 x i8], [512 x i8]* %18, i64 0, i64 %129
store i8 0, i8* %130
%131 = bitcast i32* %14 to i8*
%132 = load i32*, i32** %7
%133 = call i32 @fread(i8* %131, i32 4, i32 1, i32* %132)
%134 = icmp ne i32 %133, 1
br i1 %134, label %135, label %137
135: ; preds = %127
%136 = call i32 (...) @read_err()
br label %137
137: ; preds = %135, %127
%138 = bitcast i32* %15 to i8*
%139 = load i32*, i32** %7
%140 = call i32 @fread(i8* %138, i32 4, i32 1, i32* %139)
%141 = icmp ne i32 %140, 1
br i1 %141, label %142, label %144
142: ; preds = %137
%143 = call i32 (...) @read_err()
br label %144
144: ; preds = %142, %137
%145 = load i32, i32* %17
%146 = load i32, i32* %14
%147 = add nsw i32 %146, %145
store i32 %147, i32* %14
%148 = load i32, i32* %15
%149 = sub nsw i32 %148, 12
store i32 %149, i32* %15
%150 = load i32, i32* %15
%151 = load i32, i32* %14
%152 = getelementptr inbounds [512 x i8], [512 x i8]* %18, i64 0, i64 0
%153 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i32 %150, i32 %151, i8* %152)
%154 = load i32*, i32** %7
%155 = call i32 @ftell(i32* %154)
store i32 %155, i32* %16
%156 = load i32*, i32** %7
%157 = load i32, i32* %14
%158 = load i32, i32* @SEEK_SET
%159 = call i64 @fseek(i32* %156, i32 %157, i32 %158)
%160 = icmp slt i64 %159, 0
br i1 %160, label %161, label %163
161: ; preds = %144
%162 = call i32 (...) @std_err()
br label %163
163: ; preds = %161, %144
%164 = bitcast i32* %11 to i8*
%165 = load i32*, i32** %7
%166 = call i32 @fread(i8* %164, i32 4, i32 1, i32* %165)
%167 = icmp ne i32 %166, 1
br i1 %167, label %168, label %170
168: ; preds = %163
%169 = call i32 (...) @read_err()
br label %170
170: ; preds = %168, %163
%171 = load i32*, i32** %8
%172 = load i32, i32* %11
%173 = getelementptr inbounds [512 x i8], [512 x i8]* %18, i64 0, i64 0
%174 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %171, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.13, i64 0, i64 0), i32 %172, i8* %173)
%175 = getelementptr inbounds [512 x i8], [512 x i8]* %18, i64 0, i64 0
%176 = call i8* @create_dir(i8* %175)
store i8* %176, i8** %19
%177 = load i32*, i32** %7
%178 = load i8*, i8** %19
%179 = load i32, i32* %15
%180 = call i32 @getfile(i32* %177, i8* %178, i32 %179)
%181 = load i32*, i32** %7
%182 = load i32, i32* %16
%183 = load i32, i32* @SEEK_SET
%184 = call i64 @fseek(i32* %181, i32 %182, i32 %183)
%185 = icmp slt i64 %184, 0
br i1 %185, label %186, label %188
186: ; preds = %170
%187 = call i32 (...) @std_err()
br label %188
188: ; preds = %186, %170
br label %189
189: ; preds = %188
%190 = load i32, i32* %9
%191 = add nsw i32 %190, 1
store i32 %191, i32* %9
br label %108
192: ; preds = %108
%193 = load i32*, i32** %7
%194 = call i32 @fclose(i32* %193)
%195 = load i32*, i32** %8
%196 = call i32 @fclose(i32* %195)
ret void
}

LLVM IR (-O2):
@.str = [33 x i8] c"- open input PAK file: %s\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [33 x i8] c"- create output listfile: %s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [33 x i8] c"- enter in output directory: %s\0A\00"
@.str.5 = [37 x i8] c"- ID: 0x%08x\0A\00"
@.str.6 = [12 x i8] c"%08x // ID\0A\00"
@.str.7 = [37 x i8] c"- Number of files: 0x%08x\0A\00"
@.str.8 = [15 x i8] c"%08x // files\0A\00"
@SEEK_CUR = global i32 0
@.str.9 = [37 x i8] c"- Header size: 0x%08x\0A\00"
@.str.10 = [21 x i8] c"%08x // header size\0A\00"
@SEEK_SET = global i32 0
@.str.11 = [112 x i8] c"\0AFilesize Offset Filename\0A------------------------------------------------------------------------------\0A\00"
@stdout = global i32 0
@.str.12 = [15 x i8] c"%-12u %08x %s\0A\00"
@.str.13 = [9 x i8] c"%08x %s\0A\00"
define void @unpack(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [512 x i8]
%11 = bitcast i32* %4 to i8*
%12 = bitcast i32* %5 to i8*
%13 = bitcast i32* %6 to i8*
%14 = bitcast i32* %7 to i8*
%15 = bitcast i32* %8 to i8*
%16 = bitcast i32* %9 to i8*
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0)
%19 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = tail call i32 (...) @std_err()
br label %23
23: ; preds = %21, %3
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%25 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = tail call i32 (...) @std_err()
br label %29
29: ; preds = %27, %23
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%31 = tail call i64 @chdir(i8* %1)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = tail call i32 (...) @std_err()
br label %35
35: ; preds = %33, %29
%36 = call i32 @fread(i8* %11, i32 4, i32 1, i32* %19)
%37 = icmp eq i32 %36, 1
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = tail call i32 (...) @read_err()
br label %40
40: ; preds = %38, %35
%41 = load i32, i32* %4
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %41)
%43 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %41)
%44 = call i32 @fread(i8* %13, i32 4, i32 1, i32* %19)
%45 = icmp eq i32 %44, 1
br i1 %45, label %48, label %46
46: ; preds = %40
%47 = tail call i32 (...) @read_err()
br label %48
48: ; preds = %46, %40
%49 = load i32, i32* %6
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %49)
%51 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i32 %49)
%52 = icmp sgt i32 %49, 0
br i1 %52, label %53, label %70
53: ; preds = %48, %67
%54 = phi i32 [ %68, %67 ], [ 0, %48 ]
%55 = call i32 @fread(i8* %14, i32 4, i32 1, i32* %19)
%56 = icmp eq i32 %55, 1
br i1 %56, label %59, label %57
57: ; preds = %53
%58 = tail call i32 (...) @read_err()
br label %59
59: ; preds = %57, %53
%60 = load i32, i32* %7
%61 = add nsw i32 %60, 8
%62 = load i32, i32* @SEEK_CUR
%63 = tail call i64 @fseek(i32* %19, i32 %61, i32 %62)
%64 = icmp slt i64 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %59
%66 = tail call i32 (...) @std_err()
br label %67
67: ; preds = %59, %65
%68 = add nuw nsw i32 %54, 1
%69 = icmp eq i32 %68, %49
br i1 %69, label %70, label %53
70: ; preds = %67, %48
%71 = tail call i32 @ftell(i32* %19)
%72 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), i32 %71)
%73 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i32 %71)
%74 = load i32, i32* @SEEK_SET
%75 = tail call i64 @fseek(i32* %19, i32 8, i32 %74)
%76 = load i32, i32* @stdout
%77 = tail call i32 @fputs(i8* getelementptr inbounds ([112 x i8], [112 x i8]* @.str.11, i64 0, i64 0), i32 %76)
br i1 %52, label %78, label %132
78: ; preds = %70, %129
%79 = phi i32 [ %130, %129 ], [ 0, %70 ]
%80 = call i32 @fread(i8* %14, i32 4, i32 1, i32* %19)
%81 = icmp eq i32 %80, 1
br i1 %81, label %84, label %82
82: ; preds = %78
%83 = call i32 (...) @read_err()
br label %84
84: ; preds = %82, %78
%85 = load i32, i32* %7
%86 = call i32 @fread(i8* %17, i32 %85, i32 1, i32* %19)
%87 = icmp eq i32 %86, 1
br i1 %87, label %90, label %88
88: ; preds = %84
%89 = call i32 (...) @read_err()
br label %90
90: ; preds = %88, %84
%91 = sext i32 %85 to i64
%92 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 %91
store i8 0, i8* %92
%93 = call i32 @fread(i8* %15, i32 4, i32 1, i32* %19)
%94 = icmp eq i32 %93, 1
br i1 %94, label %97, label %95
95: ; preds = %90
%96 = call i32 (...) @read_err()
br label %97
97: ; preds = %95, %90
%98 = call i32 @fread(i8* %16, i32 4, i32 1, i32* %19)
%99 = icmp eq i32 %98, 1
br i1 %99, label %102, label %100
100: ; preds = %97
%101 = call i32 (...) @read_err()
br label %102
102: ; preds = %100, %97
%103 = load i32, i32* %8
%104 = add nsw i32 %103, %71
store i32 %104, i32* %8
%105 = load i32, i32* %9
%106 = add nsw i32 %105, -12
store i32 %106, i32* %9
%107 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i32 %106, i32 %104, i8* %17)
%108 = call i32 @ftell(i32* %19)
%109 = load i32, i32* @SEEK_SET
%110 = call i64 @fseek(i32* %19, i32 %104, i32 %109)
%111 = icmp slt i64 %110, 0
br i1 %111, label %112, label %114
112: ; preds = %102
%113 = call i32 (...) @std_err()
br label %114
114: ; preds = %112, %102
%115 = call i32 @fread(i8* %12, i32 4, i32 1, i32* %19)
%116 = icmp eq i32 %115, 1
br i1 %116, label %119, label %117
117: ; preds = %114
%118 = call i32 (...) @read_err()
br label %119
119: ; preds = %117, %114
%120 = load i32, i32* %5
%121 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.13, i64 0, i64 0), i32 %120, i8* %17)
%122 = call i8* @create_dir(i8* %17)
%123 = call i32 @getfile(i32* %19, i8* %122, i32 %106)
%124 = load i32, i32* @SEEK_SET
%125 = call i64 @fseek(i32* %19, i32 %108, i32 %124)
%126 = icmp slt i64 %125, 0
br i1 %126, label %127, label %129
127: ; preds = %119
%128 = call i32 (...) @std_err()
br label %129
129: ; preds = %119, %127
%130 = add nuw nsw i32 %79, 1
%131 = icmp eq i32 %130, %49
br i1 %131, label %132, label %78
132: ; preds = %129, %70
%133 = call i32 @fclose(i32* %19)
%134 = call i32 @fclose(i32* %25)
ret void
}