#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;
struct entropy_ctx {
  int dummy;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
double entropy_current(struct entropy_ctx *);
int /*<<< orphan*/ entropy_init(struct entropy_ctx *);
int /*<<< orphan*/ entropy_sizeof();
int /*<<< orphan*/ entropy_update(struct entropy_ctx *, int /*<<< orphan*/ *,
                                  size_t);
size_t fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(struct entropy_ctx *);
struct entropy_ctx *malloc(int /*<<< orphan*/);
int entropy(FILE *fp, double *out_e) {
  struct entropy_ctx *ctx;
  ctx = malloc(entropy_sizeof());
  entropy_init(ctx);
  uint8_t buf[1024];
  size_t len;
  do {
    len = fread(buf, sizeof(buf[0]), 1024, fp);
    entropy_update(ctx, buf, len);
  } while (len == 1024);
  *out_e = entropy_current(ctx);
  free(ctx);
  return 0;
}


x86 assembly (clang, -O0):
<entropy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <entropy_sizeof@plt>
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <entropy_init@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x4,%esi
mov    $0x400,%edx
call   1050 <fread@plt>
mov    %rax,-0x1028(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    -0x1028(%rbp),%rdx
call   1080 <entropy_update@plt>
cmpq   $0x400,-0x1028(%rbp)
je     119e <entropy+0x2e>
mov    -0x18(%rbp),%rdi
call   1060 <entropy_current@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<entropy>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1030 <entropy_sizeof@plt>
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1070 <entropy_init@plt>
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    $0x4,%esi
mov    $0x400,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rax,%rdx
call   1080 <entropy_update@plt>
cmp    $0x400,%rbx
je     11b0 <entropy+0x40>
mov    %r12,%rdi
call   1060 <entropy_current@plt>
movsd  %xmm0,(%r14)
mov    %r12,%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.entropy_ctx = type { i32 }
define i32 @entropy(i32* %0, double* %1) {
%3 = alloca i32*
%4 = alloca double*
%5 = alloca %struct.entropy_ctx*
%6 = alloca [1024 x i32]
%7 = alloca i64
store i32* %0, i32** %3
store double* %1, double** %4
%8 = call i32 (...) @entropy_sizeof()
%9 = call %struct.entropy_ctx* @malloc(i32 %8)
store %struct.entropy_ctx* %9, %struct.entropy_ctx** %5
%10 = load %struct.entropy_ctx*, %struct.entropy_ctx** %5
%11 = call i32 @entropy_init(%struct.entropy_ctx* %10)
br label %12
12: ; preds = %20, %2
%13 = getelementptr inbounds [1024 x i32], [1024 x i32]* %6, i64 0, i64 0
%14 = load i32*, i32** %3
%15 = call i64 @fread(i32* %13, i32 4, i32 1024, i32* %14)
store i64 %15, i64* %7
%16 = load %struct.entropy_ctx*, %struct.entropy_ctx** %5
%17 = getelementptr inbounds [1024 x i32], [1024 x i32]* %6, i64 0, i64 0
%18 = load i64, i64* %7
%19 = call i32 @entropy_update(%struct.entropy_ctx* %16, i32* %17, i64 %18)
br label %20
20: ; preds = %12
%21 = load i64, i64* %7
%22 = icmp eq i64 %21, 1024
br i1 %22, label %12, label %23
23: ; preds = %20
%24 = load %struct.entropy_ctx*, %struct.entropy_ctx** %5
%25 = call double @entropy_current(%struct.entropy_ctx* %24)
%26 = load double*, double** %4
store double %25, double* %26
%27 = load %struct.entropy_ctx*, %struct.entropy_ctx** %5
%28 = call i32 @free(%struct.entropy_ctx* %27)
ret i32 0
}

LLVM IR (-O2):
%struct.entropy_ctx = type { i32 }
define i32 @entropy(i32* nocapture %0, double* nocapture writeonly %1) {
%3 = alloca [1024 x i32]
%4 = tail call i32 (...) @entropy_sizeof()
%5 = tail call %struct.entropy_ctx* @malloc(i32 %4)
%6 = tail call i32 @entropy_init(%struct.entropy_ctx* %5)
%7 = bitcast [1024 x i32]* %3 to i8*
%8 = getelementptr inbounds [1024 x i32], [1024 x i32]* %3, i64 0, i64 0
br label %9
9: ; preds = %9, %2
%10 = call i64 @fread(i32* %8, i32 4, i32 1024, i32* %0)
%11 = call i32 @entropy_update(%struct.entropy_ctx* %5, i32* %8, i64 %10)
%12 = icmp eq i64 %10, 1024
br i1 %12, label %9, label %13
13: ; preds = %9
%14 = call double @entropy_current(%struct.entropy_ctx* %5)
store double %14, double* %1
%15 = call i32 @free(%struct.entropy_ctx* %5)
ret i32 0
}