#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*/ off_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
int gunzip_size(char *path) {
  int fd;
  unsigned char buf[8];
  fd = open(path, O_RDONLY);
  lseek(fd, (off_t)(-8), SEEK_END);
  read(fd, (char *)buf, sizeof(buf));
  return (
      ((unsigned long)(((unsigned short)(unsigned char)((buf + 4)[0]) |
                        ((unsigned short)(unsigned char)((buf + 4)[1]) << 8))) |
       ((unsigned long)((
            (unsigned short)(unsigned char)(((buf + 4) + 2)[0]) |
            ((unsigned short)(unsigned char)(((buf + 4) + 2)[1]) << 8)))
        << 16)));
}


x86 assembly (clang, -O0):
<gunzip_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffff8,%esi
call   1030 <lseek@plt>
mov    -0xc(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read@plt>
movzbl -0x10(%rbp),%eax
movzwl %ax,%eax
movzbl -0xf(%rbp),%ecx
movzwl %cx,%ecx
shl    $0x8,%ecx
or     %ecx,%eax
cltq
movzbl -0xe(%rbp),%ecx
movzwl %cx,%ecx
movzbl -0xd(%rbp),%edx
movzwl %dx,%edx
shl    $0x8,%edx
or     %edx,%ecx
movslq %ecx,%rcx
shl    $0x10,%rcx
or     %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gunzip_size>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,%ebx
mov    0x2e9c(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0xfffffff8,%esi
call   1030 <lseek@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1040 <read@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
define i32 @gunzip_size(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [8 x i8]
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* %5, i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = load i32, i32* @SEEK_END
%10 = call i32 @lseek(i32 %8, i32 -8, i32 %9)
%11 = load i32, i32* %3
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 8)
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%15 = getelementptr inbounds i8, i8* %14, i64 4
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = zext i8 %17 to i16
%19 = zext i16 %18 to i32
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%21 = getelementptr inbounds i8, i8* %20, i64 4
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8, i8* %22
%24 = zext i8 %23 to i16
%25 = zext i16 %24 to i32
%26 = shl i32 %25, 8
%27 = or i32 %19, %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%30 = getelementptr inbounds i8, i8* %29, i64 4
%31 = getelementptr inbounds i8, i8* %30, i64 2
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = zext i8 %33 to i16
%35 = zext i16 %34 to i32
%36 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%37 = getelementptr inbounds i8, i8* %36, i64 4
%38 = getelementptr inbounds i8, i8* %37, i64 2
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8, i8* %39
%41 = zext i8 %40 to i16
%42 = zext i16 %41 to i32
%43 = shl i32 %42, 8
%44 = or i32 %35, %43
%45 = sext i32 %44 to i64
%46 = shl i64 %45, 16
%47 = or i64 %28, %46
%48 = trunc i64 %47 to i32
ret i32 %48
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
define i32 @gunzip_size(i8* nocapture %0) {
%2 = alloca [8 x i8]
%3 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @lseek(i32 %5, i32 -8, i32 %6)
%8 = call i32 @read(i32 %5, i8* %3, i32 8)
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 4
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 5
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = shl nuw nsw i32 %14, 8
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 6
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 7
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = shl nuw i32 %21, 24
%23 = shl nuw nsw i32 %18, 16
%24 = or i32 %15, %11
%25 = or i32 %24, %23
%26 = or i32 %25, %22
ret i32 %26
}