#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(struct reservoir *r, const void *it, double w,
                      struct drand48_data *randbuffer) {
  double u = generate_random_uniform(randbuffer);
  double v = -log(u) / w;
  store_item(r, it, w, u, v);
}


x86 assembly (clang, -O0):
<add_to_reservoir>:
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  -0x28(%rbp),%xmm0
call   1050 <log@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -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>:
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>
movsd  %xmm0,0x8(%rsp)
call   1050 <log@plt>
movapd %xmm0,%xmm2
xorpd  0xe9e(%rip),%xmm2
movsd  0x10(%rsp),%xmm0
divsd  %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(%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 = call double @log(double %13)
%15 = fneg double %14
%16 = load double, double* %7
%17 = fdiv double %15, %16
store double %17, double* %10
%18 = load %struct.reservoir*, %struct.reservoir** %5
%19 = load i8*, i8** %6
%20 = load double, double* %7
%21 = load double, double* %9
%22 = load double, double* %10
%23 = call i32 @store_item(%struct.reservoir* %18, i8* %19, double %20, double %21, double %22)
ret void
}

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