#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ uint8_t;
typedef scalar_t__ uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fread(int /*<<< orphan*/ *, int, scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ ftell(int /*<<< orphan*/ *);
scalar_t__ fwrite(int /*<<< orphan*/ *, scalar_t__, int, int /*<<< orphan*/ *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ printf(char *, char const *, char const *);
int /*<<< orphan*/ unlink(char const *);
scalar_t__ uzlib_compress(int /*<<< orphan*/ **, scalar_t__ *,
                          int /*<<< orphan*/ *, scalar_t__);
int main(int argc, char **argv) {
  const char *in = argv[1], *out = argv[2];
  if (argc != 3)
    return 1;
  printf("Compressing in=%s out=%s\n", in, out);
  FILE *fin, *fout;
  int status = -1;
  uint32_t iLen, oLen;
  uint8_t *iBuf, *oBuf;
  if (!(fin = fopen(in, "rb")) || fseek(fin, 0, SEEK_END) ||
      (iLen = ftell(fin)) <= 0 || fseek(fin, 0, SEEK_SET))
    return 1;
  if ((fout = fopen(out, "wb")) == NULL ||
      (iBuf = (uint8_t *)malloc(iLen)) == NULL ||
      fread(iBuf, 1, iLen, fin) != iLen)
    return 1;
  if (uzlib_compress(&oBuf, &oLen, iBuf, iLen) == 0 &&
      oLen == fwrite(oBuf, oLen, 1, fout))
    status = 0;
  free(iBuf);
  if (oBuf)
    free(oBuf);
  fclose(fin);
  fclose(fout);
  if (status == 0)
    unlink(out);
  return (status == 0) ? 1 : 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11f4 <main+0x44>
movl   $0x1,-0x4(%rbp)
jmp    1396 <main+0x1e6>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xdfd(%rip),%rdi
call   1070 <printf@plt>
movl   $0xffffffff,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1280 <main+0xd0>
mov    -0x28(%rbp),%rdi
mov    0x2db0(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
cmp    $0x0,%rax
jne    1280 <main+0xd0>
mov    -0x28(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jle    1280 <main+0xd0>
mov    -0x28(%rbp),%rdi
mov    0x2d6b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
cmp    $0x0,%rax
je     128c <main+0xdc>
movl   $0x1,-0x4(%rbp)
jmp    1396 <main+0x1e6>
mov    -0x20(%rbp),%rdi
lea    0xd86(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     12e1 <main+0x131>
mov    -0x40(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
je     12e1 <main+0x131>
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
cmp    -0x40(%rbp),%rax
je     12ed <main+0x13d>
movl   $0x1,-0x4(%rbp)
jmp    1396 <main+0x1e6>
mov    -0x50(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    -0x58(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1090 <uzlib_compress@plt>
cmp    $0x0,%rax
jne    1341 <main+0x191>
mov    -0x48(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
call   10d0 <fwrite@plt>
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
cmp    %rcx,%rax
jne    1341 <main+0x191>
movl   $0x0,-0x34(%rbp)
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x58(%rbp)
je     135e <main+0x1ae>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
cmpl   $0x0,-0x34(%rbp)
jne    1383 <main+0x1d3>
mov    -0x20(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x34(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%ebp
cmp    $0x3,%edi
jne    1216 <main+0x66>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%r14
lea    0xe29(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1070 <printf@plt>
lea    0xe31(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1216 <main+0x66>
mov    %rax,%rbx
mov    0x2de3(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
test   %rax,%rax
je     1227 <main+0x77>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1080 <ftell@plt>
test   %rax,%rax
jle    1216 <main+0x66>
mov    %rax,%r12
mov    0x2d9a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
test   %rax,%rax
jne    1216 <main+0x66>
lea    0xdc7(%rip),%rsi
mov    %r14,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1216 <main+0x66>
mov    %rax,%r15
mov    %r12,%rdi
call   10a0 <malloc@plt>
test   %rax,%rax
je     1216 <main+0x66>
mov    %rax,%r13
mov    $0x1,%ebp
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmp    %r12,%rax
jne    1216 <main+0x66>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r13,%rdx
mov    %r12,%rcx
call   1090 <uzlib_compress@plt>
test   %rax,%rax
je     12b1 <main+0x101>
xor    %ebp,%ebp
jmp    12d2 <main+0x122>
mov    0x10(%rsp),%rbp
mov    0x8(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
mov    %r15,%rcx
call   10d0 <fwrite@plt>
cmp    %rax,%rbp
sete   %bpl
mov    %r13,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     12e9 <main+0x139>
call   1030 <free@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
test   %bpl,%bpl
je     1306 <main+0x156>
mov    %r14,%rdi
call   1040 <unlink@plt>
movzbl %bpl,%ebp
jmp    1216 <main+0x66>

LLVM IR (-O0):
@.str = [26 x i8] c"Compressing in=%s out=%s\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32*
%14 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
store i8* %20, i8** %7
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 3
br i1 %22, label %23, label %24
23: ; preds = %2
store i32 1, i32* %3
br label %99
24: ; preds = %2
%25 = load i8*, i8** %6
%26 = load i8*, i8** %7
%27 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %25, i8* %26)
store i32 -1, i32* %10
%28 = load i8*, i8** %6
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %8
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %45
31: ; preds = %24
%32 = load i32*, i32** %8
%33 = load i32, i32* @SEEK_END
%34 = call i64 @fseek(i32* %32, i32 0, i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %45, label %36
36: ; preds = %31
%37 = load i32*, i32** %8
%38 = call i64 @ftell(i32* %37)
store i64 %38, i64* %11
%39 = icmp sle i64 %38, 0
br i1 %39, label %45, label %40
40: ; preds = %36
%41 = load i32*, i32** %8
%42 = load i32, i32* @SEEK_SET
%43 = call i64 @fseek(i32* %41, i32 0, i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %40, %36, %31, %24
store i32 1, i32* %3
br label %99
46: ; preds = %40
%47 = load i8*, i8** %7
%48 = call i32* @fopen(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %48, i32** %9
%49 = icmp eq i32* %48, null
br i1 %49, label %62, label %50
50: ; preds = %46
%51 = load i64, i64* %11
%52 = call i64 @malloc(i64 %51)
%53 = inttoptr i64 %52 to i32*
store i32* %53, i32** %13
%54 = icmp eq i32* %53, null
br i1 %54, label %62, label %55
55: ; preds = %50
%56 = load i32*, i32** %13
%57 = load i64, i64* %11
%58 = load i32*, i32** %8
%59 = call i64 @fread(i32* %56, i32 1, i64 %57, i32* %58)
%60 = load i64, i64* %11
%61 = icmp ne i64 %59, %60
br i1 %61, label %62, label %63
62: ; preds = %55, %50, %46
store i32 1, i32* %3
br label %99
63: ; preds = %55
%64 = load i32*, i32** %13
%65 = load i64, i64* %11
%66 = call i64 @uzlib_compress(i32** %14, i64* %12, i32* %64, i64 %65)
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %76
68: ; preds = %63
%69 = load i64, i64* %12
%70 = load i32*, i32** %14
%71 = load i64, i64* %12
%72 = load i32*, i32** %9
%73 = call i64 @fwrite(i32* %70, i64 %71, i32 1, i32* %72)
%74 = icmp eq i64 %69, %73
br i1 %74, label %75, label %76
75: ; preds = %68
store i32 0, i32* %10
br label %76
76: ; preds = %75, %68, %63
%77 = load i32*, i32** %13
%78 = call i32 @free(i32* %77)
%79 = load i32*, i32** %14
%80 = icmp ne i32* %79, null
br i1 %80, label %81, label %84
81: ; preds = %76
%82 = load i32*, i32** %14
%83 = call i32 @free(i32* %82)
br label %84
84: ; preds = %81, %76
%85 = load i32*, i32** %8
%86 = call i32 @fclose(i32* %85)
%87 = load i32*, i32** %9
%88 = call i32 @fclose(i32* %87)
%89 = load i32, i32* %10
%90 = icmp eq i32 %89, 0
br i1 %90, label %91, label %94
91: ; preds = %84
%92 = load i8*, i8** %7
%93 = call i32 @unlink(i8* %92)
br label %94
94: ; preds = %91, %84
%95 = load i32, i32* %10
%96 = icmp eq i32 %95, 0
%97 = zext i1 %96 to i64
%98 = select i1 %96, i32 1, i32 0
store i32 %98, i32* %3
br label %99
99: ; preds = %94, %62, %45, %23
%100 = load i32, i32* %3
ret i32 %100
}

LLVM IR (-O2):
@.str = [26 x i8] c"Compressing in=%s out=%s\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca i32*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = icmp eq i32 %0, 3
br i1 %9, label %10, label %61
10: ; preds = %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %8)
%12 = bitcast i64* %3 to i8*
%13 = bitcast i32** %4 to i8*
%14 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %59, label %16
16: ; preds = %10
%17 = load i32, i32* @SEEK_END
%18 = tail call i64 @fseek(i32* %14, i32 0, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %59
20: ; preds = %16
%21 = tail call i64 @ftell(i32* %14)
%22 = icmp slt i64 %21, 1
br i1 %22, label %59, label %23
23: ; preds = %20
%24 = load i32, i32* @SEEK_SET
%25 = tail call i64 @fseek(i32* %14, i32 0, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %59
27: ; preds = %23
%28 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i32* %28, null
br i1 %29, label %59, label %30
30: ; preds = %27
%31 = tail call i64 @malloc(i64 %21)
%32 = inttoptr i64 %31 to i32*
%33 = icmp eq i64 %31, 0
br i1 %33, label %59, label %34
34: ; preds = %30
%35 = tail call i64 @fread(i32* %32, i32 1, i64 %21, i32* %14)
%36 = icmp eq i64 %35, %21
br i1 %36, label %37, label %59
37: ; preds = %34
%38 = call i64 @uzlib_compress(i32** %4, i64* %3, i32* %32, i64 %21)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = load i64, i64* %3
%42 = load i32*, i32** %4
%43 = call i64 @fwrite(i32* %42, i64 %41, i32 1, i32* %28)
%44 = icmp eq i64 %41, %43
br label %45
45: ; preds = %40, %37
%46 = phi i1 [ false, %37 ], [ %44, %40 ]
%47 = call i32 @free(i32* %32)
%48 = load i32*, i32** %4
%49 = icmp eq i32* %48, null
br i1 %49, label %52, label %50
50: ; preds = %45
%51 = call i32 @free(i32* %48)
br label %52
52: ; preds = %50, %45
%53 = call i32 @fclose(i32* %14)
%54 = call i32 @fclose(i32* %28)
br i1 %46, label %55, label %57
55: ; preds = %52
%56 = call i32 @unlink(i8* %8)
br label %57
57: ; preds = %55, %52
%58 = zext i1 %46 to i32
br label %59
59: ; preds = %27, %30, %34, %10, %16, %20, %23, %57
%60 = phi i32 [ %58, %57 ], [ 1, %23 ], [ 1, %20 ], [ 1, %16 ], [ 1, %10 ], [ 1, %34 ], [ 1, %30 ], [ 1, %27 ]
br label %61
61: ; preds = %2, %59
%62 = phi i32 [ %60, %59 ], [ 1, %2 ]
ret i32 %62
}