#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*/ olen;
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 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]);
  }
  if (fread(&olen, sizeof(olen), 1, f) != 1) {
    perror(argv[1]);
    return 1;
  }
  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    13d9 <main+0x249>
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    13d9 <main+0x249>
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>
cmp    $0x1,%eax
je     127d <main+0xed>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d9 <main+0x249>
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    12bf <main+0x12f>
mov    -0x18(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    12ca <main+0x13a>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
jmp    12ca <main+0x13a>
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    0xd12(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd39(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xd3c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd42(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xd49(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd87(%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    1331 <main+0x191>
mov    0x8(%r14),%rdi
lea    0xe3d(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1340 <main+0x1a0>
mov    %rax,%rbx
mov    0x2df2(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xfffffffffffffffc,%rsi
call   10a0 <fseek@plt>
test   %rax,%rax
jne    1351 <main+0x1b1>
mov    %rsp,%rdi
mov    $0x1,%r15d
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    135f <main+0x1bf>
mov    %rbx,%rdi
call   1090 <ftell@plt>
mov    %rax,%r12
mov    %rsp,%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    0xe0f(%rip),%rdi
call   1030 <puts@plt>
lea    0xe30(%rip),%rdi
call   1030 <puts@plt>
lea    0xd84(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe26(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%rsi
lea    0xd76(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe1c(%rip),%rdi
call   1030 <puts@plt>
lea    0xd70(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe17(%rip),%rdi
call   1030 <puts@plt>
lea    0xd6d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe1b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%r14),%rsi
lea    0xd64(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe1f(%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    1331 <main+0x191>
mov    0x8(%r14),%rdi
call   10c0 <perror@plt>
jmp    1210 <main+0x70>
mov    0x8(%r14),%rdi
call   10c0 <perror@plt>
jmp    1331 <main+0x191>

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 %94
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 %94
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 = icmp ne i32 %42, 1
br i1 %43, label %44, label %49
44: ; preds = %40
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32 @perror(i8* %47)
store i32 1, i32* %3
br label %94
49: ; preds = %40
%50 = load i32*, i32** %9
%51 = call i64 @ftell(i32* %50)
store i64 %51, i64* %7
%52 = call i64 @getle32(i64* %6)
store i64 %52, i64* %6
%53 = load i32*, i32** %9
%54 = call i32 @fclose(i32* %53)
%55 = load i64, i64* %6
%56 = load i64, i64* %7
%57 = icmp sgt i64 %55, %56
br i1 %57, label %58, label %62
58: ; preds = %49
%59 = load i64, i64* %6
%60 = load i64, i64* %7
%61 = sub nsw i64 %59, %60
br label %63
62: ; preds = %49
br label %63
63: ; preds = %62, %58
%64 = phi i64 [ %61, %58 ], [ 0, %62 ]
store i64 %64, i64* %8
%65 = load i64, i64* %6
%66 = ashr i64 %65, 12
%67 = load i64, i64* %8
%68 = add i64 %67, %66
store i64 %68, i64* %8
%69 = load i64, i64* %8
%70 = add i64 %69, 65664
store i64 %70, i64* %8
%71 = load i64, i64* %8
%72 = add i64 %71, 4095
%73 = and i64 %72, -4096
store i64 %73, i64* %8
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%76 = load i64, i64* %7
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i64 %76)
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%79 = load i64, i64* %6
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i64 %79)
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
%82 = load i64, i64* %8
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i64 %82)
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0))
%85 = load i64, i64* %8
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i64 %85)
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0))
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0))
%89 = load i8**, i8*** %5
%90 = getelementptr inbounds i8*, i8** %89, i64 1
%91 = load i8*, i8** %90
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0), i8* %91)
%93 = 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 %94
94: ; preds = %63, %44, %25, %12
%95 = load i32, i32* %3
ret i32 %95
}

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 %58
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 %58
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 = icmp eq i32 %26, 1
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = load i8*, i8** %11
%30 = tail call i32 @perror(i8* %29)
br label %58
31: ; preds = %25
%32 = tail call i64 @ftell(i32* %13)
%33 = call i64 @getle32(i64* %3)
store i64 %33, i64* %3
%34 = call i32 @fclose(i32* %13)
%35 = load i64, i64* %3
%36 = icmp sgt i64 %35, %32
%37 = sub nsw i64 %35, %32
%38 = select i1 %36, i64 %37, i64 0
%39 = ashr i64 %35, 12
%40 = add nsw i64 %39, 69759
%41 = add i64 %40, %38
%42 = and i64 %41, -4096
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.15, i64 0, i64 0))
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i64 %32)
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.16, i64 0, i64 0))
%47 = load i64, i64* %3
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i64 %47)
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.17, i64 0, i64 0))
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i64 %42)
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.18, i64 0, i64 0))
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i64 %42)
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.19, i64 0, i64 0))
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.20, i64 0, i64 0))
%55 = load i8*, i8** %11
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0), i8* %55)
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.21, i64 0, i64 0))
br label %58
58: ; preds = %31, %28, %15, %6
%59 = phi i32 [ 1, %6 ], [ 1, %28 ], [ 0, %31 ], [ 1, %15 ]
ret i32 %59
}