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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ *Z_NULL;
unsigned long adler32(unsigned long, int /*<<< orphan*/ *, long);
int /*<<< orphan*/ fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(long);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
unsigned long fadler32(FILE *file) {
  fseek(file, 0, SEEK_END);
  long fileSize = ftell(file);
  rewind(file);
  char *buffer = (char *)malloc(fileSize);
  fread(buffer, 1, fileSize, file);
  unsigned long adler = adler32(0L, Z_NULL, 0);
  adler = adler32(adler, (Bytef *)buffer, fileSize);
  free(buffer);
  return adler;
}


x86 assembly (clang, -O0):
<fadler32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x10(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rdi
call   1070 <adler32@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1070 <adler32@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fadler32>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <rewind@plt>
mov    %r14,%rdi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%rsi
xor    %edi,%edi
xor    %edx,%edx
call   1070 <adler32@plt>
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1070 <adler32@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@Z_NULL = global i32* null
define i64 @fadler32(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
store i32* %0, i32** %2
%6 = load i32*, i32** %2
%7 = load i32, i32* @SEEK_END
%8 = call i32 @fseek(i32* %6, i32 0, i32 %7)
%9 = load i32*, i32** %2
%10 = call i64 @ftell(i32* %9)
store i64 %10, i64* %3
%11 = load i32*, i32** %2
%12 = call i32 @rewind(i32* %11)
%13 = load i64, i64* %3
%14 = call i64 @malloc(i64 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = load i64, i64* %3
%18 = load i32*, i32** %2
%19 = call i32 @fread(i8* %16, i32 1, i64 %17, i32* %18)
%20 = load i32*, i32** @Z_NULL
%21 = call i64 @adler32(i64 0, i32* %20, i64 0)
store i64 %21, i64* %5
%22 = load i64, i64* %5
%23 = load i8*, i8** %4
%24 = bitcast i8* %23 to i32*
%25 = load i64, i64* %3
%26 = call i64 @adler32(i64 %22, i32* %24, i64 %25)
store i64 %26, i64* %5
%27 = load i8*, i8** %4
%28 = call i32 @free(i8* %27)
%29 = load i64, i64* %5
ret i64 %29
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@Z_NULL = global i32* null
define i64 @fadler32(i32* nocapture %0) {
%2 = load i32, i32* @SEEK_END
%3 = tail call i32 @fseek(i32* %0, i32 0, i32 %2)
%4 = tail call i64 @ftell(i32* %0)
%5 = tail call i32 @rewind(i32* %0)
%6 = tail call i64 @malloc(i64 %4)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @fread(i8* %7, i32 1, i64 %4, i32* %0)
%9 = load i32*, i32** @Z_NULL
%10 = tail call i64 @adler32(i64 0, i32* %9, i64 0)
%11 = inttoptr i64 %6 to i32*
%12 = tail call i64 @adler32(i64 %10, i32* %11, i64 %4)
%13 = tail call i32 @free(i8* %7)
ret i64 %12
}