#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 */
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  int total_out;
  char *next_in;
  int avail_in;
  char *next_out;
  int avail_out;
  int /*<<< orphan*/ *opaque;
  int /*<<< orphan*/ *zfree;
  int /*<<< orphan*/ *zalloc;
};
typedef TYPE_1__ z_stream;
struct stat {
  int st_size;
};

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
int Z_BUF_ERROR;
int Z_OK;
int Z_STREAM_END;
int /*<<< orphan*/ Z_SYNC_FLUSH;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fstat(int, struct stat *);
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ inflateEnd(TYPE_1__ *);
int /*<<< orphan*/ inflateInit(TYPE_1__ *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char **, int);
int write(int, char **, int);
int main(int argc, char *argv[]) {
  int fd_in, fd_out, comp_len, uncomp_len, i, last_out;
  char buf_in[1024], buf_out[65536];
  z_stream zstream;
  struct stat statbuf;
  if (argc < 3) {
    printf("Usage: %s <infile.swf> <outfile.swf>\n", argv[0]);
    return 1;
  }
  fd_in = open(argv[1], O_RDONLY);
  if (fd_in < 0) {
    perror("Error opening input file");
    return 1;
  }
  fd_out = open(argv[2], O_WRONLY | O_CREAT, 00644);
  if (fd_out < 0) {
    perror("Error opening output file");
    close(fd_in);
    return 1;
  }
  if (read(fd_in, &buf_in, 8) != 8) {
    printf("Header error\n");
    close(fd_in);
    close(fd_out);
    return 1;
  }
  if (buf_in[0] != 'C' || buf_in[1] != 'W' || buf_in[2] != 'S') {
    printf("Not a compressed flash file\n");
    return 1;
  }
  fstat(fd_in, &statbuf);
  comp_len = statbuf.st_size;
  uncomp_len =
      buf_in[4] | (buf_in[5] << 8) | (buf_in[6] << 16) | (buf_in[7] << 24);
  printf("Compressed size: %d Uncompressed size: %d\n", comp_len - 4,
         uncomp_len - 4);
  buf_in[0] = 'F';
  if (write(fd_out, &buf_in, 8) < 8) {
    perror("Error writing output file");
    return 1;
  }
  zstream.zalloc = NULL;
  zstream.zfree = NULL;
  zstream.opaque = NULL;
  inflateInit(&zstream);
  for (i = 0; i < comp_len - 8;) {
    int ret, len = read(fd_in, &buf_in, 1024);
    ;
    last_out = zstream.total_out;
    zstream.next_in = &buf_in[0];
    zstream.avail_in = len;
    zstream.next_out = &buf_out[0];
    zstream.avail_out = 65536;
    ret = inflate(&zstream, Z_SYNC_FLUSH);
    if (ret != Z_STREAM_END && ret != Z_OK) {
      printf("Error while decompressing: %d\n", ret);
      inflateEnd(&zstream);
      return 1;
    }

    ;
    if (write(fd_out, &buf_out, zstream.total_out - last_out) <
        zstream.total_out - last_out) {
      perror("Error writing output file");
      return 1;
    }
    i += len;
    if (ret == Z_STREAM_END || ret == Z_BUF_ERROR)
      break;
  }
  if (zstream.total_out != uncomp_len - 8) {
    printf("Size mismatch (%lu != %d), updating header...\n", zstream.total_out,
           uncomp_len - 8);
    buf_in[0] = (zstream.total_out + 8) & 0xff;
    buf_in[1] = ((zstream.total_out + 8) >> 8) & 0xff;
    buf_in[2] = ((zstream.total_out + 8) >> 16) & 0xff;
    buf_in[3] = ((zstream.total_out + 8) >> 24) & 0xff;
    lseek(fd_out, 4, SEEK_SET);
    if (write(fd_out, &buf_in, 4) < 4) {
      perror("Error writing output file");
      return 1;
    }
  }
  inflateEnd(&zstream);
  close(fd_in);
  close(fd_out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10480,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11f4 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1637 <main+0x487>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1231 <main+0x81>
lea    0xe06(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1637 <main+0x487>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d60(%rip),%rax
mov    (%rax),%esi
mov    0x2daf(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1284 <main+0xd4>
lea    0xdd4(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1637 <main+0x487>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x8,%edx
call   1080 <read@plt>
cmp    $0x8,%eax
je     12cb <main+0x11b>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1637 <main+0x487>
movsbl -0x430(%rbp),%eax
cmp    $0x43,%eax
jne    12fb <main+0x14b>
movsbl -0x42f(%rbp),%eax
cmp    $0x57,%eax
jne    12fb <main+0x14b>
movsbl -0x42e(%rbp),%eax
cmp    $0x53,%eax
je     1315 <main+0x165>
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1637 <main+0x487>
mov    -0x14(%rbp),%edi
lea    -0x10478(%rbp),%rsi
call   10d0 <fstat@plt>
mov    -0x10478(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x42c(%rbp),%eax
movsbl -0x42b(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movsbl -0x42a(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
movsbl -0x429(%rbp),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%esi
sub    $0x4,%esi
mov    -0x20(%rbp),%edx
sub    $0x4,%edx
lea    0xd16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movb   $0x46,-0x430(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x8,%edx
call   1040 <write@plt>
cmp    $0x8,%eax
jge    13b1 <main+0x201>
lea    0xd0f(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1637 <main+0x487>
movq   $0x0,-0x10438(%rbp)
movq   $0x0,-0x10440(%rbp)
movq   $0x0,-0x10448(%rbp)
lea    -0x10470(%rbp),%rdi
call   1090 <inflateInit@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x8,%ecx
cmp    %ecx,%eax
jge    153d <main+0x38d>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,-0x10480(%rbp)
mov    -0x10470(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x10468(%rbp)
mov    -0x10480(%rbp),%eax
mov    %eax,-0x10460(%rbp)
lea    -0x10430(%rbp),%rax
mov    %rax,-0x10458(%rbp)
movl   $0x10000,-0x10450(%rbp)
mov    0x2b76(%rip),%rax
mov    (%rax),%esi
lea    -0x10470(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x1047c(%rbp)
mov    -0x1047c(%rbp),%eax
mov    0x2b5d(%rip),%rcx
cmp    (%rcx),%eax
je     14bc <main+0x30c>
mov    -0x1047c(%rbp),%eax
mov    0x2b60(%rip),%rcx
cmp    (%rcx),%eax
je     14bc <main+0x30c>
mov    -0x1047c(%rbp),%esi
lea    0xc2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x10470(%rbp),%rdi
call   10a0 <inflateEnd@plt>
movl   $0x1,-0x4(%rbp)
jmp    1637 <main+0x487>
mov    -0x18(%rbp),%edi
lea    -0x10430(%rbp),%rsi
mov    -0x10470(%rbp),%edx
sub    -0x28(%rbp),%edx
call   1040 <write@plt>
mov    -0x10470(%rbp),%ecx
sub    -0x28(%rbp),%ecx
cmp    %ecx,%eax
jge    14fd <main+0x34d>
lea    0xbc3(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1637 <main+0x487>
mov    -0x10480(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1047c(%rbp),%eax
mov    0x2aba(%rip),%rcx
cmp    (%rcx),%eax
je     1533 <main+0x383>
mov    -0x1047c(%rbp),%eax
mov    0x2a95(%rip),%rcx
cmp    (%rcx),%eax
jne    1538 <main+0x388>
jmp    153d <main+0x38d>
jmp    13e5 <main+0x235>
mov    -0x10470(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x8,%ecx
cmp    %ecx,%eax
je     1614 <main+0x464>
mov    -0x10470(%rbp),%esi
mov    -0x20(%rbp),%edx
sub    $0x8,%edx
lea    0xb84(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10470(%rbp),%eax
add    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x430(%rbp)
mov    -0x10470(%rbp),%eax
add    $0x8,%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x42f(%rbp)
mov    -0x10470(%rbp),%eax
add    $0x8,%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,-0x42e(%rbp)
mov    -0x10470(%rbp),%eax
add    $0x8,%eax
sar    $0x18,%eax
and    $0xff,%eax
mov    %al,-0x42d(%rbp)
mov    -0x18(%rbp),%edi
mov    0x29e2(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1060 <lseek@plt>
mov    -0x18(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
cmp    $0x4,%eax
jge    160f <main+0x45f>
lea    0xab1(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1637 <main+0x487>
jmp    1614 <main+0x464>
lea    -0x10470(%rbp),%rdi
call   10a0 <inflateEnd@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10480,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10468,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     11ef <main+0x2f>
mov    (%rbx),%rsi
lea    0xe1d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    14e2 <main+0x322>
mov    0x8(%rbx),%rdi
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10c0 <open@plt>
test   %eax,%eax
js     142e <main+0x26e>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
mov    0x2d88(%rip),%rax
mov    0x2dd9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1a4,%edx
xor    %eax,%eax
call   10c0 <open@plt>
mov    %eax,0x4(%rsp)
test   %eax,%eax
js     143a <main+0x27a>
lea    0x60(%rsp),%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1090 <read@plt>
cmp    $0x8,%eax
jne    13d6 <main+0x216>
cmpb   $0x43,0x60(%rsp)
jne    13f7 <main+0x237>
cmpb   $0x57,0x61(%rsp)
jne    13f7 <main+0x237>
cmpb   $0x53,0x62(%rsp)
jne    13f7 <main+0x237>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
call   10e0 <fstat@plt>
mov    0x8(%rsp),%ebx
movsbl 0x64(%rsp),%eax
movsbl 0x65(%rsp),%ecx
shl    $0x8,%ecx
or     %eax,%ecx
movsbl 0x66(%rsp),%eax
shl    $0x10,%eax
movzbl 0x67(%rsp),%r14d
shl    $0x18,%r14d
or     %eax,%r14d
or     %ecx,%r14d
lea    -0x4(%rbx),%esi
lea    -0x4(%r14),%edx
lea    0xd9e(%rip),%rdi
xor    %r13d,%r13d
xor    %eax,%eax
call   1060 <printf@plt>
movb   $0x46,0x60(%rsp)
lea    0x60(%rsp),%rsi
mov    0x4(%rsp),%edi
mov    $0x8,%edx
call   1050 <write@plt>
cmp    $0x7,%eax
jle    14d6 <main+0x316>
mov    %r14,0x10(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x48(%rsp)
movq   $0x0,0x58(%rsp)
lea    0x20(%rsp),%rdi
call   10a0 <inflateInit@plt>
add    $0xfffffff8,%ebx
mov    %rbx,0x18(%rsp)
xchg   %ax,%ax
cmp    %ebx,%r13d
jge    1408 <main+0x248>
mov    %ebp,%r15d
mov    %ebp,%edi
lea    0x60(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x400,%edx
call   1090 <read@plt>
mov    %eax,%r12d
mov    0x20(%rsp),%ebp
mov    %rbx,0x28(%rsp)
mov    %eax,0x30(%rsp)
lea    0x460(%rsp),%rbx
mov    %rbx,0x38(%rsp)
movl   $0x10000,0x40(%rsp)
mov    0x2c6c(%rip),%rax
mov    (%rax),%esi
lea    0x20(%rsp),%rdi
call   1030 <inflate@plt>
mov    %eax,%r14d
mov    0x2c5e(%rip),%rax
cmp    (%rax),%r14d
je     1387 <main+0x1c7>
mov    0x2c6a(%rip),%rax
cmp    (%rax),%r14d
jne    140e <main+0x24e>
mov    0x20(%rsp),%edx
sub    %ebp,%edx
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
call   1050 <write@plt>
mov    0x20(%rsp),%esi
mov    %esi,%ecx
sub    %ebp,%ecx
cmp    %ecx,%eax
jl     14d6 <main+0x316>
mov    0x2c20(%rip),%rax
cmp    (%rax),%r14d
je     144a <main+0x28a>
add    %r12d,%r13d
mov    0x2bfd(%rip),%rax
cmp    (%rax),%r14d
mov    %r15d,%ebp
mov    0x18(%rsp),%rbx
jne    1310 <main+0x150>
jmp    144d <main+0x28d>
lea    0xd2b(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    0x4(%rsp),%edi
call   1080 <close@plt>
jmp    14e2 <main+0x322>
lea    0xcee(%rip),%rdi
call   1040 <puts@plt>
jmp    14e2 <main+0x322>
mov    0x20(%rsp),%esi
jmp    144d <main+0x28d>
lea    0xc89(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x20(%rsp),%rdi
call   10b0 <inflateEnd@plt>
jmp    14e2 <main+0x322>
lea    0xbf1(%rip),%rdi
jmp    14dd <main+0x31d>
lea    0xbfe(%rip),%rdi
call   10d0 <perror@plt>
mov    %ebp,%edi
jmp    13ed <main+0x22d>
mov    %r15d,%ebp
mov    0x10(%rsp),%rdx
add    $0xfffffff8,%edx
cmp    %edx,%esi
je     14b8 <main+0x2f8>
lea    0xc5d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x20(%rsp),%eax
lea    0x8(%rax),%ecx
mov    %cl,0x60(%rsp)
add    $0x8,%eax
mov    %ah,0x61(%rsp)
mov    %eax,%ecx
shr    $0x10,%ecx
mov    %cl,0x62(%rsp)
shr    $0x18,%eax
mov    %al,0x63(%rsp)
mov    0x2b20(%rip),%rax
mov    (%rax),%edx
mov    0x4(%rsp),%ebx
mov    %ebx,%edi
mov    $0x4,%esi
call   1070 <lseek@plt>
lea    0x60(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <write@plt>
cmp    $0x3,%eax
jle    14d6 <main+0x316>
lea    0x20(%rsp),%rdi
call   10b0 <inflateEnd@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    0x4(%rsp),%edi
call   1080 <close@plt>
xor    %eax,%eax
jmp    14e7 <main+0x327>
lea    0xba7(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%eax
add    $0x10468,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, i8*, i32, i8*, i32, i32*, i32*, i32* }
%struct.stat = type { i32 }
@.str = [38 x i8] c"Usage: %s <infile.swf> <outfile.swf>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [25 x i8] c"Error opening input file\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.2 = [26 x i8] c"Error opening output file\00"
@.str.3 = [14 x i8] c"Header error\0A\00"
@.str.4 = [29 x i8] c"Not a compressed flash file\0A\00"
@.str.5 = [43 x i8] c"Compressed size: %d Uncompressed size: %d\0A\00"
@.str.6 = [26 x i8] c"Error writing output file\00"
@Z_SYNC_FLUSH = global i32 0
@Z_STREAM_END = global i32 0
@Z_OK = global i32 0
@.str.7 = [31 x i8] c"Error while decompressing: %d\0A\00"
@Z_BUF_ERROR = global i32 0
@.str.8 = [47 x i8] c"Size mismatch (%lu != %d), updating header...\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 i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [1024 x i8]
%13 = alloca [65536 x i8]
%14 = alloca %struct.TYPE_5__
%15 = alloca %struct.stat
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 3
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %23)
store i32 1, i32* %3
br label %231
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = load i32, i32* @O_RDONLY
%30 = call i32 (i8*, i32, ...) @open(i8* %28, i32 %29)
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %25
%34 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %231
35: ; preds = %25
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = load i32, i32* @O_WRONLY
%40 = load i32, i32* @O_CREAT
%41 = or i32 %39, %40
%42 = call i32 (i8*, i32, ...) @open(i8* %38, i32 %41, i32 420)
store i32 %42, i32* %7
%43 = load i32, i32* %7
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %35
%46 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%47 = load i32, i32* %6
%48 = call i32 @close(i32 %47)
store i32 1, i32* %3
br label %231
49: ; preds = %35
%50 = load i32, i32* %6
%51 = bitcast [1024 x i8]* %12 to i8**
%52 = call i32 @read(i32 %50, i8** %51, i32 8)
%53 = icmp ne i32 %52, 8
br i1 %53, label %54, label %60
54: ; preds = %49
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%56 = load i32, i32* %6
%57 = call i32 @close(i32 %56)
%58 = load i32, i32* %7
%59 = call i32 @close(i32 %58)
store i32 1, i32* %3
br label %231
60: ; preds = %49
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp ne i32 %63, 67
br i1 %64, label %75, label %65
65: ; preds = %60
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 1
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp ne i32 %68, 87
br i1 %69, label %75, label %70
70: ; preds = %65
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 2
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = icmp ne i32 %73, 83
br i1 %74, label %75, label %77
75: ; preds = %70, %65, %60
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %231
77: ; preds = %70
%78 = load i32, i32* %6
%79 = call i32 @fstat(i32 %78, %struct.stat* %15)
%80 = getelementptr inbounds %struct.stat, %struct.stat* %15, i32 0, i32 0
%81 = load i32, i32* %80
store i32 %81, i32* %8
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 4
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 5
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
%88 = shl i32 %87, 8
%89 = or i32 %84, %88
%90 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 6
%91 = load i8, i8* %90
%92 = sext i8 %91 to i32
%93 = shl i32 %92, 16
%94 = or i32 %89, %93
%95 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 7
%96 = load i8, i8* %95
%97 = sext i8 %96 to i32
%98 = shl i32 %97, 24
%99 = or i32 %94, %98
store i32 %99, i32* %9
%100 = load i32, i32* %8
%101 = sub nsw i32 %100, 4
%102 = load i32, i32* %9
%103 = sub nsw i32 %102, 4
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %101, i32 %103)
%105 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
store i8 70, i8* %105
%106 = load i32, i32* %7
%107 = bitcast [1024 x i8]* %12 to i8**
%108 = call i32 @write(i32 %106, i8** %107, i32 8)
%109 = icmp slt i32 %108, 8
br i1 %109, label %110, label %112
110: ; preds = %77
%111 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %231
112: ; preds = %77
%113 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 7
store i32* null, i32** %113
%114 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 6
store i32* null, i32** %114
%115 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 5
store i32* null, i32** %115
%116 = call i32 @inflateInit(%struct.TYPE_5__* %14)
store i32 0, i32* %10
br label %117
117: ; preds = %175, %112
%118 = load i32, i32* %10
%119 = load i32, i32* %8
%120 = sub nsw i32 %119, 8
%121 = icmp slt i32 %118, %120
br i1 %121, label %122, label %176
122: ; preds = %117
%123 = load i32, i32* %6
%124 = bitcast [1024 x i8]* %12 to i8**
%125 = call i32 @read(i32 %123, i8** %124, i32 1024)
store i32 %125, i32* %17
%126 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 0
%127 = load i32, i32* %126
store i32 %127, i32* %11
%128 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%129 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 1
store i8* %128, i8** %129
%130 = load i32, i32* %17
%131 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 2
store i32 %130, i32* %131
%132 = getelementptr inbounds [65536 x i8], [65536 x i8]* %13, i64 0, i64 0
%133 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 3
store i8* %132, i8** %133
%134 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 4
store i32 65536, i32* %134
%135 = load i32, i32* @Z_SYNC_FLUSH
%136 = call i32 @inflate(%struct.TYPE_5__* %14, i32 %135)
store i32 %136, i32* %16
%137 = load i32, i32* %16
%138 = load i32, i32* @Z_STREAM_END
%139 = icmp ne i32 %137, %138
br i1 %139, label %140, label %148
140: ; preds = %122
%141 = load i32, i32* %16
%142 = load i32, i32* @Z_OK
%143 = icmp ne i32 %141, %142
br i1 %143, label %144, label %148
144: ; preds = %140
%145 = load i32, i32* %16
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %145)
%147 = call i32 @inflateEnd(%struct.TYPE_5__* %14)
store i32 1, i32* %3
br label %231
148: ; preds = %140, %122
%149 = load i32, i32* %7
%150 = bitcast [65536 x i8]* %13 to i8**
%151 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 0
%152 = load i32, i32* %151
%153 = load i32, i32* %11
%154 = sub nsw i32 %152, %153
%155 = call i32 @write(i32 %149, i8** %150, i32 %154)
%156 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 0
%157 = load i32, i32* %156
%158 = load i32, i32* %11
%159 = sub nsw i32 %157, %158
%160 = icmp slt i32 %155, %159
br i1 %160, label %161, label %163
161: ; preds = %148
%162 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %231
163: ; preds = %148
%164 = load i32, i32* %17
%165 = load i32, i32* %10
%166 = add nsw i32 %165, %164
store i32 %166, i32* %10
%167 = load i32, i32* %16
%168 = load i32, i32* @Z_STREAM_END
%169 = icmp eq i32 %167, %168
br i1 %169, label %174, label %170
170: ; preds = %163
%171 = load i32, i32* %16
%172 = load i32, i32* @Z_BUF_ERROR
%173 = icmp eq i32 %171, %172
br i1 %173, label %174, label %175
174: ; preds = %170, %163
br label %176
175: ; preds = %170
br label %117
176: ; preds = %174, %117
%177 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 0
%178 = load i32, i32* %177
%179 = load i32, i32* %9
%180 = sub nsw i32 %179, 8
%181 = icmp ne i32 %178, %180
br i1 %181, label %182, label %225
182: ; preds = %176
%183 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 0
%184 = load i32, i32* %183
%185 = load i32, i32* %9
%186 = sub nsw i32 %185, 8
%187 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.8, i64 0, i64 0), i32 %184, i32 %186)
%188 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 0
%189 = load i32, i32* %188
%190 = add nsw i32 %189, 8
%191 = and i32 %190, 255
%192 = trunc i32 %191 to i8
%193 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
store i8 %192, i8* %193
%194 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 0
%195 = load i32, i32* %194
%196 = add nsw i32 %195, 8
%197 = ashr i32 %196, 8
%198 = and i32 %197, 255
%199 = trunc i32 %198 to i8
%200 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 1
store i8 %199, i8* %200
%201 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 0
%202 = load i32, i32* %201
%203 = add nsw i32 %202, 8
%204 = ashr i32 %203, 16
%205 = and i32 %204, 255
%206 = trunc i32 %205 to i8
%207 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 2
store i8 %206, i8* %207
%208 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 0
%209 = load i32, i32* %208
%210 = add nsw i32 %209, 8
%211 = ashr i32 %210, 24
%212 = and i32 %211, 255
%213 = trunc i32 %212 to i8
%214 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 3
store i8 %213, i8* %214
%215 = load i32, i32* %7
%216 = load i32, i32* @SEEK_SET
%217 = call i32 @lseek(i32 %215, i32 4, i32 %216)
%218 = load i32, i32* %7
%219 = bitcast [1024 x i8]* %12 to i8**
%220 = call i32 @write(i32 %218, i8** %219, i32 4)
%221 = icmp slt i32 %220, 4
br i1 %221, label %222, label %224
222: ; preds = %182
%223 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %231
224: ; preds = %182
br label %225
225: ; preds = %224, %176
%226 = call i32 @inflateEnd(%struct.TYPE_5__* %14)
%227 = load i32, i32* %6
%228 = call i32 @close(i32 %227)
%229 = load i32, i32* %7
%230 = call i32 @close(i32 %229)
store i32 0, i32* %3
br label %231
231: ; preds = %225, %222, %161, %144, %110, %75, %54, %45, %33, %20
%232 = load i32, i32* %3
ret i32 %232
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, i8*, i32, i8*, i32, i32*, i32*, i32* }
%struct.stat = type { i32 }
@.str = [38 x i8] c"Usage: %s <infile.swf> <outfile.swf>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [25 x i8] c"Error opening input file\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.2 = [26 x i8] c"Error opening output file\00"
@.str.5 = [43 x i8] c"Compressed size: %d Uncompressed size: %d\0A\00"
@.str.6 = [26 x i8] c"Error writing output file\00"
@Z_SYNC_FLUSH = global i32 0
@Z_STREAM_END = global i32 0
@Z_OK = global i32 0
@.str.7 = [31 x i8] c"Error while decompressing: %d\0A\00"
@Z_BUF_ERROR = global i32 0
@.str.8 = [47 x i8] c"Size mismatch (%lu != %d), updating header...\0A\00"
@SEEK_SET = global i32 0
@str = [28 x i8] c"Not a compressed flash file\00"
@str.9 = [13 x i8] c"Header error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [65536 x i8]
%5 = alloca %struct.TYPE_5__
%6 = alloca %struct.stat
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.TYPE_5__* %5 to i8*
%10 = bitcast %struct.stat* %6 to i8*
%11 = icmp slt i32 %0, 3
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %156
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDONLY
%19 = tail call i32 (i8*, i32, ...) @open(i8* %17, i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %156
23: ; preds = %15
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = load i32, i32* @O_WRONLY
%27 = load i32, i32* @O_CREAT
%28 = or i32 %27, %26
%29 = tail call i32 (i8*, i32, ...) @open(i8* %25, i32 %28, i32 420)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %23
%32 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%33 = tail call i32 @close(i32 %19)
br label %156
34: ; preds = %23
%35 = bitcast [1024 x i8]* %3 to i8**
%36 = call i32 @read(i32 %19, i8** %35, i32 8)
%37 = icmp eq i32 %36, 8
br i1 %37, label %42, label %38
38: ; preds = %34
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.9, i64 0, i64 0))
%40 = tail call i32 @close(i32 %19)
%41 = tail call i32 @close(i32 %29)
br label %156
42: ; preds = %34
%43 = load i8, i8* %7
%44 = icmp ne i8 %43, 67
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1
%46 = load i8, i8* %45
%47 = icmp ne i8 %46, 87
%48 = select i1 %44, i1 true, i1 %47
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 2
%50 = load i8, i8* %49
%51 = icmp ne i8 %50, 83
%52 = select i1 %48, i1 true, i1 %51
br i1 %52, label %53, label %55
53: ; preds = %42
%54 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %156
55: ; preds = %42
%56 = call i32 @fstat(i32 %19, %struct.stat* %6)
%57 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
%58 = load i32, i32* %57
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 4
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 5
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = shl nsw i32 %64, 8
%66 = or i32 %65, %61
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 6
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = shl nsw i32 %69, 16
%71 = or i32 %66, %70
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 7
%73 = load i8, i8* %72
%74 = zext i8 %73 to i32
%75 = shl nuw i32 %74, 24
%76 = or i32 %71, %75
%77 = add nsw i32 %58, -4
%78 = add nsw i32 %76, -4
%79 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %77, i32 %78)
store i8 70, i8* %7
%80 = call i32 @write(i32 %29, i8** %35, i32 8)
%81 = icmp slt i32 %80, 8
br i1 %81, label %82, label %84
82: ; preds = %55
%83 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %156
84: ; preds = %55
%85 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 5
%86 = bitcast i32** %85 to i8*
%87 = call i32 @inflateInit(%struct.TYPE_5__* %5)
%88 = add nsw i32 %58, -8
%89 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 0
%90 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 1
%91 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 2
%92 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 3
%93 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 4
%94 = bitcast [65536 x i8]* %4 to i8**
br label %95
95: ; preds = %122, %84
%96 = phi i32 [ 0, %84 ], [ %123, %122 ]
%97 = icmp slt i32 %96, %88
br i1 %97, label %100, label %98
98: ; preds = %95
%99 = load i32, i32* %89
br label %129
100: ; preds = %95
%101 = call i32 @read(i32 %19, i8** %35, i32 1024)
%102 = load i32, i32* %89
store i8* %7, i8** %90
store i32 %101, i32* %91
store i8* %8, i8** %92
store i32 65536, i32* %93
%103 = load i32, i32* @Z_SYNC_FLUSH
%104 = call i32 @inflate(%struct.TYPE_5__* %5, i32 %103)
%105 = load i32, i32* @Z_STREAM_END
%106 = icmp eq i32 %104, %105
%107 = load i32, i32* @Z_OK
%108 = icmp eq i32 %104, %107
%109 = select i1 %106, i1 true, i1 %108
br i1 %109, label %113, label %110
110: ; preds = %100
%111 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %104)
%112 = call i32 @inflateEnd(%struct.TYPE_5__* %5)
br label %156
113: ; preds = %100
%114 = load i32, i32* %89
%115 = sub nsw i32 %114, %102
%116 = call i32 @write(i32 %29, i8** %94, i32 %115)
%117 = load i32, i32* %89
%118 = sub nsw i32 %117, %102
%119 = icmp slt i32 %116, %118
br i1 %119, label %120, label %122
120: ; preds = %113
%121 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %156
122: ; preds = %113
%123 = add nsw i32 %101, %96
%124 = load i32, i32* @Z_STREAM_END
%125 = icmp eq i32 %104, %124
%126 = load i32, i32* @Z_BUF_ERROR
%127 = icmp eq i32 %104, %126
%128 = select i1 %125, i1 true, i1 %127
br i1 %128, label %129, label %95
129: ; preds = %122, %98
%130 = phi i32 [ %99, %98 ], [ %117, %122 ]
%131 = add nsw i32 %76, -8
%132 = icmp eq i32 %130, %131
br i1 %132, label %152, label %133
133: ; preds = %129
%134 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.8, i64 0, i64 0), i32 %130, i32 %131)
%135 = load i32, i32* %89
%136 = trunc i32 %135 to i8
%137 = add i8 %136, 8
store i8 %137, i8* %7
%138 = add nsw i32 %135, 8
%139 = lshr i32 %138, 8
%140 = trunc i32 %139 to i8
store i8 %140, i8* %45
%141 = lshr i32 %138, 16
%142 = trunc i32 %141 to i8
store i8 %142, i8* %49
%143 = lshr i32 %138, 24
%144 = trunc i32 %143 to i8
%145 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 3
store i8 %144, i8* %145
%146 = load i32, i32* @SEEK_SET
%147 = call i32 @lseek(i32 %29, i32 4, i32 %146)
%148 = call i32 @write(i32 %29, i8** %35, i32 4)
%149 = icmp slt i32 %148, 4
br i1 %149, label %150, label %152
150: ; preds = %133
%151 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %156
152: ; preds = %133, %129
%153 = call i32 @inflateEnd(%struct.TYPE_5__* %5)
%154 = call i32 @close(i32 %19)
%155 = call i32 @close(i32 %29)
br label %156
156: ; preds = %120, %110, %152, %150, %82, %53, %38, %31, %21, %12
%157 = phi i32 [ 1, %12 ], [ 1, %21 ], [ 1, %31 ], [ 1, %38 ], [ 1, %53 ], [ 1, %82 ], [ 1, %150 ], [ 0, %152 ], [ 1, %110 ], [ 1, %120 ]
ret i32 %157
}