#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 long uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fread(long *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
long getle32(long *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  uint32_t olen;
  long ilen;
  unsigned long offs;
  FILE *f;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s compressed_file\n", argv[0]);
    return 1;
  }
  f = fopen(argv[1], "r");
  if (!f) {
    perror(argv[1]);
    return 1;
  }
  if (fseek(f, -4L, SEEK_END)) {
    perror(argv[1]);
  }
  fread(&olen, sizeof olen, 1, f);
  ilen = ftell(f);
  olen = getle32(&olen);
  fclose(f);
  offs = (olen > ilen) ? olen - ilen : 0;
  offs += olen >> 12;
  offs += 64 * 1024 + 128;
  offs = (offs + 4095) & ~4095;
  printf(".section \".rodata..compressed\",\"a\",@progbits\n");
  printf(".globl z_input_len\n");
  printf("z_input_len = %lu\n", ilen);
  printf(".globl z_output_len\n");
  printf("z_output_len = %lu\n", (unsigned long)olen);
  printf(".globl z_extract_offset\n");
  printf("z_extract_offset = 0x%lx\n", offs);
  printf(".globl z_extract_offset_negative\n");
  printf("z_extract_offset_negative = -0x%lx\n", offs);
  printf(".globl input_data, input_data_end\n");
  printf("input_data:\n");
  printf(".incbin \"%s\"\n", argv[1]);
  printf("input_data_end:\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d8 <main+0x48>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13b7 <main+0x227>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe34(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1214 <main+0x84>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13b7 <main+0x227>
mov    -0x30(%rbp),%rdi
mov    0x2dc9(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffffffffffc,%rsi
call   1090 <fseek@plt>
cmp    $0x0,%rax
je     1244 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <perror@plt>
mov    -0x30(%rbp),%rcx
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x30(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <getle32@plt>
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jle    129d <main+0x10d>
mov    -0x18(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    12a8 <main+0x118>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
jmp    12a8 <main+0x118>
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
sar    $0xc,%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x10080,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0xfff,%rax
and    $0xfffffffffffff000,%rax
mov    %rax,-0x28(%rbp)
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x1,%edi
jg     11d3 <main+0x33>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe3d(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%r15d
jmp    1325 <main+0x185>
mov    0x8(%r14),%rdi
lea    0xe3d(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1334 <main+0x194>
mov    %rax,%rbx
mov    0x2df2(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xfffffffffffffffc,%rsi
call   10a0 <fseek@plt>
test   %rax,%rax
jne    1345 <main+0x1a5>
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1090 <ftell@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1050 <getle32@plt>
mov    %rax,(%rsp)
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    (%rsp),%rax
xor    %r15d,%r15d
mov    %rax,%rcx
sub    %r12,%rcx
cmovle %r15,%rcx
sar    $0xc,%rax
lea    (%rax,%rcx,1),%rbx
add    $0x1107f,%rbx
and    $0xfffffffffffff000,%rbx
lea    0xe1b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3c(%rip),%rdi
call   1030 <puts@plt>
lea    0xd90(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe32(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%rsi
lea    0xd82(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe28(%rip),%rdi
call   1030 <puts@plt>
lea    0xd7c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe23(%rip),%rdi
call   1030 <puts@plt>
lea    0xd79(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe27(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3d(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%r14),%rsi
lea    0xd70(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe2b(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x8(%r14),%rdi
call   10c0 <perror@plt>
mov    $0x1,%r15d
jmp    1325 <main+0x185>
mov    0x8(%r14),%rdi
call   10c0 <perror@plt>
jmp    1210 <main+0x70>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s compressed_file\0A\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@.str.2 = [46 x i8] c".section \22.rodata..compressed\22,\22a\22,@progbits\0A\00"
@.str.3 = [20 x i8] c".globl z_input_len\0A\00"
@.str.4 = [19 x i8] c"z_input_len = %lu\0A\00"
@.str.5 = [21 x i8] c".globl z_output_len\0A\00"
@.str.6 = [20 x i8] c"z_output_len = %lu\0A\00"
@.str.7 = [25 x i8] c".globl z_extract_offset\0A\00"
@.str.8 = [26 x i8] c"z_extract_offset = 0x%lx\0A\00"
@.str.9 = [34 x i8] c".globl z_extract_offset_negative\0A\00"
@.str.10 = [36 x i8] c"z_extract_offset_negative = -0x%lx\0A\00"
@.str.11 = [35 x i8] c".globl input_data, input_data_end\0A\00"
@.str.12 = [13 x i8] c"input_data:\0A\00"
@.str.13 = [14 x i8] c".incbin \22%s\22\0A\00"
@.str.14 = [17 x i8] c"input_data_end:\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 1, i32* %3
br label %87
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %9
%23 = load i32*, i32** %9
%24 = icmp ne i32* %23, null
br i1 %24, label %30, label %25
25: ; preds = %18
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @perror(i8* %28)
store i32 1, i32* %3
br label %87
30: ; preds = %18
%31 = load i32*, i32** %9
%32 = load i32, i32* @SEEK_END
%33 = call i64 @fseek(i32* %31, i64 -4, i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 @perror(i8* %38)
br label %40
40: ; preds = %35, %30
%41 = load i32*, i32** %9
%42 = call i32 @fread(i64* %6, i32 8, i32 1, i32* %41)
%43 = load i32*, i32** %9
%44 = call i64 @ftell(i32* %43)
store i64 %44, i64* %7
%45 = call i64 @getle32(i64* %6)
store i64 %45, i64* %6
%46 = load i32*, i32** %9
%47 = call i32 @fclose(i32* %46)
%48 = load i64, i64* %6
%49 = load i64, i64* %7
%50 = icmp sgt i64 %48, %49
br i1 %50, label %51, label %55
51: ; preds = %40
%52 = load i64, i64* %6
%53 = load i64, i64* %7
%54 = sub nsw i64 %52, %53
br label %56
55: ; preds = %40
br label %56
56: ; preds = %55, %51
%57 = phi i64 [ %54, %51 ], [ 0, %55 ]
store i64 %57, i64* %8
%58 = load i64, i64* %6
%59 = ashr i64 %58, 12
%60 = load i64, i64* %8
%61 = add i64 %60, %59
store i64 %61, i64* %8
%62 = load i64, i64* %8
%63 = add i64 %62, 65664
store i64 %63, i64* %8
%64 = load i64, i64* %8
%65 = add i64 %64, 4095
%66 = and i64 %65, -4096
store i64 %66, i64* %8
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%69 = load i64, i64* %7
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i64 %69)
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%72 = load i64, i64* %6
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i64 %72)
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
%75 = load i64, i64* %8
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i64 %75)
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0))
%78 = load i64, i64* %8
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i64 %78)
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0))
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0))
%82 = load i8**, i8*** %5
%83 = getelementptr inbounds i8*, i8** %82, i64 1
%84 = load i8*, i8** %83
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0), i8* %84)
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.14, i64 0, i64 0))
store i32 0, i32* %3
br label %87
87: ; preds = %56, %25, %12
%88 = load i32, i32* %3
ret i32 %88
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s compressed_file\0A\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@.str.4 = [19 x i8] c"z_input_len = %lu\0A\00"
@.str.6 = [20 x i8] c"z_output_len = %lu\0A\00"
@.str.8 = [26 x i8] c"z_extract_offset = 0x%lx\0A\00"
@.str.10 = [36 x i8] c"z_extract_offset_negative = -0x%lx\0A\00"
@.str.13 = [14 x i8] c".incbin \22%s\22\0A\00"
@str = [45 x i8] c".section \22.rodata..compressed\22,\22a\22,@progbits\00"
@str.15 = [19 x i8] c".globl z_input_len\00"
@str.16 = [20 x i8] c".globl z_output_len\00"
@str.17 = [24 x i8] c".globl z_extract_offset\00"
@str.18 = [33 x i8] c".globl z_extract_offset_negative\00"
@str.19 = [34 x i8] c".globl input_data, input_data_end\00"
@str.20 = [12 x i8] c"input_data:\00"
@str.21 = [16 x i8] c"input_data_end:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %53
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i8*, i8** %11
%17 = tail call i32 @perror(i8* %16)
br label %53
18: ; preds = %10
%19 = load i32, i32* @SEEK_END
%20 = tail call i64 @fseek(i32* %13, i64 -4, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i8*, i8** %11
%24 = tail call i32 @perror(i8* %23)
br label %25
25: ; preds = %22, %18
%26 = call i32 @fread(i64* %3, i32 8, i32 1, i32* %13)
%27 = tail call i64 @ftell(i32* %13)
%28 = call i64 @getle32(i64* %3)
store i64 %28, i64* %3
%29 = call i32 @fclose(i32* %13)
%30 = load i64, i64* %3
%31 = icmp sgt i64 %30, %27
%32 = sub nsw i64 %30, %27
%33 = select i1 %31, i64 %32, i64 0
%34 = ashr i64 %30, 12
%35 = add nsw i64 %34, 69759
%36 = add i64 %35, %33
%37 = and i64 %36, -4096
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.15, i64 0, i64 0))
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i64 %27)
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.16, i64 0, i64 0))
%42 = load i64, i64* %3
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i64 %42)
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.17, i64 0, i64 0))
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i64 %37)
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.18, i64 0, i64 0))
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i64 %37)
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.19, i64 0, i64 0))
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.20, i64 0, i64 0))
%50 = load i8*, i8** %11
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0), i8* %50)
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.21, i64 0, i64 0))
br label %53
53: ; preds = %25, %15, %6
%54 = phi i32 [ 1, %6 ], [ 0, %25 ], [ 1, %15 ]
ret i32 %54
}