#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 drand48_data {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ drand48_r(struct drand48_data *, double *);
double log(int);
scalar_t__ signbit(double);
double laplace(double lambda, struct drand48_data *buffer) {
  double rnd;
  drand48_r(buffer, &rnd);
  rnd = 0.5 - rnd;
  if (signbit(rnd))
    return lambda * log(1 + 2 * rnd);
  return -lambda * log(1 - 2 * rnd);
}


x86 assembly (clang, -O0):
<laplace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <drand48_r@plt>
movsd  0xeaa(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <signbit@plt>
cmp    $0x0,%rax
je     11b2 <laplace+0x82>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe79(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1202 <laplace+0xd2>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm1
addsd  %xmm1,%xmm1
movsd  0xe24(%rip),%xmm0
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<laplace>:
sub    $0x28,%rsp
movaps %xmm0,0x10(%rsp)
lea    0x8(%rsp),%rsi
call   1050 <drand48_r@plt>
movsd  0xeb5(%rip),%xmm0
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <signbit@plt>
test   %rax,%rax
je     1175 <laplace+0x45>
movsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm0
addsd  0xe95(%rip),%xmm0
jmp    119c <laplace+0x6c>
movaps 0x10(%rsp),%xmm0
xorps  0xe8f(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm1
addsd  %xmm1,%xmm1
movsd  0xe70(%rip),%xmm0
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <log@plt>
mulsd  0x10(%rsp),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.drand48_data = type { i32 }
define double @laplace(double %0, %struct.drand48_data* %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca %struct.drand48_data*
%6 = alloca double
store double %0, double* %4
store %struct.drand48_data* %1, %struct.drand48_data** %5
%7 = load %struct.drand48_data*, %struct.drand48_data** %5
%8 = call i32 @drand48_r(%struct.drand48_data* %7, double* %6)
%9 = load double, double* %6
%10 = fsub double 5.000000e-01, %9
store double %10, double* %6
%11 = load double, double* %6
%12 = call i64 @signbit(double %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load double, double* %4
%16 = load double, double* %6
%17 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %16, double 1.000000e+00)
%18 = fptosi double %17 to i32
%19 = call double @log(i32 %18)
%20 = fmul double %15, %19
store double %20, double* %3
br label %29
21: ; preds = %2
%22 = load double, double* %4
%23 = fneg double %22
%24 = load double, double* %6
%25 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %24, double 1.000000e+00)
%26 = fptosi double %25 to i32
%27 = call double @log(i32 %26)
%28 = fmul double %23, %27
store double %28, double* %3
br label %29
29: ; preds = %21, %14
%30 = load double, double* %3
ret double %30
}

LLVM IR (-O2):
%struct.drand48_data = type { i32 }
define double @laplace(double %0, %struct.drand48_data* %1) {
%3 = alloca double
%4 = bitcast double* %3 to i8*
%5 = call i32 @drand48_r(%struct.drand48_data* %1, double* %3)
%6 = load double, double* %3
%7 = fsub double 5.000000e-01, %6
store double %7, double* %3
%8 = call i64 @signbit(double %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load double, double* %3
%12 = call double @llvm.fmuladd.f64(double %11, double 2.000000e+00, double 1.000000e+00)
br label %17
13: ; preds = %2
%14 = fneg double %0
%15 = load double, double* %3
%16 = call double @llvm.fmuladd.f64(double %15, double -2.000000e+00, double 1.000000e+00)
br label %17
17: ; preds = %13, %10
%18 = phi double [ %16, %13 ], [ %12, %10 ]
%19 = phi double [ %14, %13 ], [ %0, %10 ]
%20 = fptosi double %18 to i32
%21 = call double @log(i32 %20)
%22 = fmul double %21, %19
ret double %22
}