#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*/ total_in;
  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*/ exit(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 /*<<< orphan*/ write(int, char **, int);
main(int argc, char *argv[]) {
  int fd_in, fd_out, comp_len, uncomp_len, tag, i, last_out;
  char buf_in[1024], buf_out[1024];
  z_stream zstream;
  struct stat statbuf;
  if (argc < 3) {
    printf("Usage: %s <infile.swf> <outfile.swf>\n", argv[0]);
    exit(1);
  }
  fd_in = open(argv[1], O_RDONLY);
  if (fd_in < 0) {
    perror("Error while opening: ");
    exit(1);
  }
  fd_out = open(argv[2], O_WRONLY | O_CREAT, 00644);
  if (fd_out < 0) {
    perror("Error while opening: ");
    close(fd_in);
    exit(1);
  }
  if (read(fd_in, &buf_in, 8) != 8) {
    printf("Header error\n");
    close(fd_in);
    close(fd_out);
    exit(1);
  }
  if (buf_in[0] != 'C' || buf_in[1] != 'W' || buf_in[2] != 'S') {
    printf("Not a compressed flash file\n");
    exit(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';
  write(fd_out, &buf_in, 8);
  zstream.zalloc = NULL;
  zstream.zfree = NULL;
  zstream.opaque = NULL;
  inflateInit(&zstream);
  for (i = 0; i < comp_len - 4;) {
    int ret, len = read(fd_in, &buf_in, 1024);
    ("read %d bytes\n", len);
    last_out = zstream.total_out;
    zstream.next_in = &buf_in[0];
    zstream.avail_in = len;
    zstream.next_out = &buf_out[0];
    zstream.avail_out = 1024;
    ret = inflate(&zstream, Z_SYNC_FLUSH);
    if (ret == Z_STREAM_END || ret == Z_BUF_ERROR)
      break;
    if (ret != Z_OK) {
      printf("Error while decompressing: %d\n", ret);
      inflateEnd(&zstream);
      exit(1);
    }
    ("a_in: %d t_in: %d a_out: %d t_out: %d -- %d out\n", zstream.avail_in,
     zstream.total_in, zstream.avail_out, zstream.total_out,
     zstream.total_out - last_out);
    write(fd_out, &buf_out, zstream.total_out - last_out);
    i += len;
  }
  if (zstream.total_out != uncomp_len - 8) {
    printf("Size mismatch (%d != %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);
    write(fd_out, &buf_in, 4);
  }
  inflateEnd(&zstream);
  close(fd_in);
  close(fd_out);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x880,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1202 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    123d <main+0x7d>
lea    0xdf8(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d54(%rip),%rax
mov    (%rax),%esi
mov    0x2da3(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    128e <main+0xce>
lea    0xdaf(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x8,%edx
call   1080 <read@plt>
cmp    $0x8,%eax
je     12d3 <main+0x113>
lea    0xd8a(%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>
mov    $0x1,%edi
call   10d0 <exit@plt>
movsbl -0x430(%rbp),%eax
cmp    $0x43,%eax
jne    1303 <main+0x143>
movsbl -0x42f(%rbp),%eax
cmp    $0x57,%eax
jne    1303 <main+0x143>
movsbl -0x42e(%rbp),%eax
cmp    $0x53,%eax
je     131b <main+0x15b>
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x878(%rbp),%rsi
call   10e0 <fstat@plt>
mov    -0x878(%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    0xcf3(%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>
movq   $0x0,-0x838(%rbp)
movq   $0x0,-0x840(%rbp)
movq   $0x0,-0x848(%rbp)
lea    -0x870(%rbp),%rdi
call   1090 <inflateInit@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x4,%ecx
cmp    %ecx,%eax
jge    14e2 <main+0x322>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,-0x880(%rbp)
mov    -0x870(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x868(%rbp)
mov    -0x880(%rbp),%eax
mov    %eax,-0x860(%rbp)
lea    -0x830(%rbp),%rax
mov    %rax,-0x858(%rbp)
movl   $0x400,-0x850(%rbp)
mov    0x2b91(%rip),%rax
mov    (%rax),%esi
lea    -0x870(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x87c(%rbp)
mov    -0x87c(%rbp),%eax
mov    0x2b78(%rip),%rcx
cmp    (%rcx),%eax
je     1475 <main+0x2b5>
mov    -0x87c(%rbp),%eax
mov    0x2b53(%rip),%rcx
cmp    (%rcx),%eax
jne    147a <main+0x2ba>
jmp    14e2 <main+0x322>
mov    -0x87c(%rbp),%eax
mov    0x2b61(%rip),%rcx
cmp    (%rcx),%eax
je     14b9 <main+0x2f9>
mov    -0x87c(%rbp),%esi
lea    0xc05(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x870(%rbp),%rdi
call   10a0 <inflateEnd@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x830(%rbp),%rsi
mov    -0x870(%rbp),%edx
sub    -0x2c(%rbp),%edx
call   1040 <write@plt>
mov    -0x880(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    13ca <main+0x20a>
mov    -0x870(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x8,%ecx
cmp    %ecx,%eax
je     1593 <main+0x3d3>
mov    -0x870(%rbp),%esi
mov    -0x20(%rbp),%edx
sub    $0x8,%edx
lea    0xbe8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x870(%rbp),%eax
add    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x430(%rbp)
mov    -0x870(%rbp),%eax
add    $0x8,%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x42f(%rbp)
mov    -0x870(%rbp),%eax
add    $0x8,%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,-0x42e(%rbp)
mov    -0x870(%rbp),%eax
add    $0x8,%eax
sar    $0x18,%eax
and    $0xff,%eax
mov    %al,-0x42d(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2a3d(%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>
lea    -0x870(%rbp),%rdi
call   10a0 <inflateEnd@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x880,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x868,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jle    1464 <main+0x294>
mov    0x8(%rbx),%rdi
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10c0 <open@plt>
mov    %eax,0x8(%rsp)
test   %eax,%eax
js     147f <main+0x2af>
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,0xc(%rsp)
test   %eax,%eax
js     1495 <main+0x2c5>
lea    0x60(%rsp),%rsi
mov    0x8(%rsp),%edi
mov    $0x8,%edx
call   1090 <read@plt>
cmp    $0x8,%eax
jne    14a7 <main+0x2d7>
cmpb   $0x43,0x60(%rsp)
jne    14cf <main+0x2ff>
cmpb   $0x57,0x61(%rsp)
jne    14cf <main+0x2ff>
cmpb   $0x53,0x62(%rsp)
jne    14cf <main+0x2ff>
lea    0x10(%rsp),%rsi
mov    0x8(%rsp),%edi
call   10f0 <fstat@plt>
mov    0x10(%rsp),%ebp
movsbl 0x64(%rsp),%eax
movsbl 0x65(%rsp),%ecx
shl    $0x8,%ecx
or     %eax,%ecx
movsbl 0x66(%rsp),%eax
shl    $0x10,%eax
movzbl 0x67(%rsp),%edx
shl    $0x18,%edx
or     %eax,%edx
or     %ecx,%edx
lea    -0x4(%rbp),%r13d
mov    %rdx,0x18(%rsp)
add    $0xfffffffc,%edx
lea    0xd7c(%rip),%rdi
xor    %r14d,%r14d
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
movb   $0x46,0x60(%rsp)
lea    0x60(%rsp),%rbx
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1050 <write@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0x48(%rsp)
movq   $0x0,0x58(%rsp)
lea    0x20(%rsp),%rdi
call   10a0 <inflateInit@plt>
cmp    $0x5,%ebp
jl     13a6 <main+0x1d6>
lea    0x460(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1090 <read@plt>
mov    %eax,%r15d
mov    0x20(%rsp),%r12d
mov    %rbx,0x28(%rsp)
mov    %eax,0x30(%rsp)
mov    %rbp,0x38(%rsp)
movl   $0x400,0x40(%rsp)
mov    0x2c72(%rip),%rax
mov    (%rax),%esi
lea    0x20(%rsp),%rdi
call   1030 <inflate@plt>
mov    0x2c67(%rip),%rcx
cmp    (%rcx),%eax
je     13a6 <main+0x1d6>
mov    0x2c4c(%rip),%rcx
cmp    (%rcx),%eax
je     13a6 <main+0x1d6>
mov    0x2c69(%rip),%rcx
cmp    (%rcx),%eax
jne    1440 <main+0x270>
mov    0x20(%rsp),%edx
sub    %r12d,%edx
mov    0xc(%rsp),%edi
mov    %rbp,%rsi
call   1050 <write@plt>
add    %r15d,%r14d
cmp    %r13d,%r14d
jl     1320 <main+0x150>
mov    0x20(%rsp),%esi
mov    0x18(%rsp),%rdx
add    $0xfffffff8,%edx
cmp    %edx,%esi
je     1410 <main+0x240>
lea    0xcc9(%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    0x2bc3(%rip),%rax
mov    (%rax),%edx
mov    0xc(%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>
lea    0x20(%rsp),%rdi
call   10b0 <inflateEnd@plt>
mov    0x8(%rsp),%edi
call   1080 <close@plt>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x868,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc20(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x20(%rsp),%rdi
call   10b0 <inflateEnd@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    (%rbx),%rsi
lea    0xb92(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xba0(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xb8a(%rip),%rdi
call   10d0 <perror@plt>
mov    0x8(%rsp),%edi
jmp    14c0 <main+0x2f0>
lea    0xc22(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%edi
call   1080 <close@plt>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xbde(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

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

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