#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 */
struct reservoir {
  int dummy;
};
struct drand48_data {
  int dummy;
};

/* Variables and functions */
double generate_random_uniform(struct drand48_data *);
double log(double);
int /*<<< orphan*/ store_item(struct reservoir *, void const *, double, double,
                              double);
void add_to_reservoir_log(struct reservoir *r, const void *it, double logw,
                          struct drand48_data *randbuffer) {
  double u = generate_random_uniform(randbuffer);
  double v = log(log(1 / u)) - logw;
  store_item(r, it, logw, u, v);
}


x86 assembly (clang, -O0):
<add_to_reservoir_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <generate_random_uniform@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  0xea1(%rip),%xmm0
divsd  -0x28(%rbp),%xmm0
call   1050 <log@plt>
call   1050 <log@plt>
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movsd  -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
call   1040 <store_item@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_to_reservoir_log>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movsd  %xmm0,0x10(%rsp)
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdx,%rdi
call   1030 <generate_random_uniform@plt>
movapd %xmm0,%xmm1
movsd  %xmm0,0x8(%rsp)
movsd  0xea3(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1050 <log@plt>
call   1050 <log@plt>
movapd %xmm0,%xmm2
movsd  0x10(%rsp),%xmm0
subsd  %xmm0,%xmm2
mov    %rbx,%rdi
mov    %r14,%rsi
movsd  0x8(%rsp),%xmm1
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1040 <store_item@plt>

LLVM IR (-O0):
%struct.reservoir = type { i32 }
%struct.drand48_data = type { i32 }
define void @add_to_reservoir_log(%struct.reservoir* %0, i8* %1, double %2, %struct.drand48_data* %3) {
%5 = alloca %struct.reservoir*
%6 = alloca i8*
%7 = alloca double
%8 = alloca %struct.drand48_data*
%9 = alloca double
%10 = alloca double
store %struct.reservoir* %0, %struct.reservoir** %5
store i8* %1, i8** %6
store double %2, double* %7
store %struct.drand48_data* %3, %struct.drand48_data** %8
%11 = load %struct.drand48_data*, %struct.drand48_data** %8
%12 = call double @generate_random_uniform(%struct.drand48_data* %11)
store double %12, double* %9
%13 = load double, double* %9
%14 = fdiv double 1.000000e+00, %13
%15 = call double @log(double %14)
%16 = call double @log(double %15)
%17 = load double, double* %7
%18 = fsub double %16, %17
store double %18, double* %10
%19 = load %struct.reservoir*, %struct.reservoir** %5
%20 = load i8*, i8** %6
%21 = load double, double* %7
%22 = load double, double* %9
%23 = load double, double* %10
%24 = call i32 @store_item(%struct.reservoir* %19, i8* %20, double %21, double %22, double %23)
ret void
}

LLVM IR (-O2):
%struct.reservoir = type { i32 }
%struct.drand48_data = type { i32 }
define void @add_to_reservoir_log(%struct.reservoir* %0, i8* %1, double %2, %struct.drand48_data* %3) {
%5 = tail call double @generate_random_uniform(%struct.drand48_data* %3)
%6 = fdiv double 1.000000e+00, %5
%7 = tail call double @log(double %6)
%8 = tail call double @log(double %7)
%9 = fsub double %8, %2
%10 = tail call i32 @store_item(%struct.reservoir* %0, i8* %1, double %2, double %5, double %9)
ret void
}