#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 */

/* Variables and functions */
double drand48();
double log(double);
double stub1(double);
double stub2(double);
double stub3(double);
double stub4(double);
double slicesample(double init, double (*logpdf)(double), double width0,
                   int burnin) {
  double llb, rrb, z, lx, width;
  int ii;
  for (ii = 0; ii < burnin; ii++) {
    lx = (*logpdf)(init) + log(drand48());
    llb = init - drand48() * width0;
    rrb = init + drand48() * width0;
    width = width0;
    while ((*logpdf)(llb) > lx) {
      llb -= drand48() * width;
      width *= 1.5;
    }
    width = width0;
    while ((*logpdf)(rrb) > lx) {
      rrb += drand48() * width;
      width *= 1.5;
    }
    do {
      z = llb + drand48() * (rrb - llb);
      if ((*logpdf)(z) >= lx) {
        break;
      }
      if (z < init) {
        llb = z;
      } else {
        rrb = z;
      }
    } while (1);
    init = z;
  }
  return init;
}


x86 assembly (clang, -O0):
<slicesample>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1347 <slicesample+0x227>
mov    -0x10(%rbp),%rax
movsd  -0x8(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x68(%rbp)
mov    $0x0,%al
call   1040 <drand48@plt>
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    $0x0,%al
call   1040 <drand48@plt>
movsd  -0x60(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    $0x0,%al
call   1040 <drand48@plt>
movsd  -0x58(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x28(%rbp),%xmm0
call   *%rax
ucomisd -0x40(%rbp),%xmm0
jbe    124c <slicesample+0x12c>
mov    $0x0,%al
call   1040 <drand48@plt>
movsd  -0x48(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xdc3(%rip),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    11ea <slicesample+0xca>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x30(%rbp),%xmm0
call   *%rax
ucomisd -0x40(%rbp),%xmm0
jbe    12a1 <slicesample+0x181>
mov    $0x0,%al
call   1040 <drand48@plt>
movsd  -0x48(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xd6e(%rip),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    1256 <slicesample+0x136>
jmp    12a6 <slicesample+0x186>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    $0x0,%al
call   1040 <drand48@plt>
movsd  -0x70(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
subsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x38(%rbp),%xmm0
call   *%rax
ucomisd -0x40(%rbp),%xmm0
jb     12ee <slicesample+0x1ce>
jmp    132f <slicesample+0x20f>
movsd  -0x38(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1311 <slicesample+0x1f1>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    131b <slicesample+0x1fb>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1320 <slicesample+0x200>
mov    $0x1,%al
test   $0x1,%al
jne    12a6 <slicesample+0x186>
jmp    132f <slicesample+0x20f>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1140 <slicesample+0x20>
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slicesample>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
movsd  %xmm1,0x30(%rsp)
test   %esi,%esi
jle    1348 <slicesample+0x228>
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %ebp,%ebp
jmp    1156 <slicesample+0x36>
add    $0x1,%ebp
movapd 0x20(%rsp),%xmm1
movapd %xmm1,%xmm0
cmp    %r14d,%ebp
je     134c <slicesample+0x22c>
movsd  %xmm0,0x38(%rsp)
call   *%rbx
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1040 <drand48@plt>
call   1030 <log@plt>
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <drand48@plt>
mulsd  0x30(%rsp),%xmm0
movsd  0x38(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1040 <drand48@plt>
movapd %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm0
call   *%rbx
ucomisd 0x8(%rsp),%xmm0
movsd  0x30(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
jbe    11fb <slicesample+0xdb>
xor    %eax,%eax
call   1040 <drand48@plt>
movsd  0x20(%rsp),%xmm2
mulsd  %xmm2,%xmm0
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xe1e(%rip),%xmm2
movsd  %xmm2,0x20(%rsp)
movsd  %xmm1,(%rsp)
movapd %xmm1,%xmm0
call   *%rbx
ucomisd 0x8(%rsp),%xmm0
ja     11c0 <slicesample+0xa0>
movapd 0x10(%rsp),%xmm0
mulsd  0x30(%rsp),%xmm0
addsd  0x38(%rsp),%xmm0
movapd %xmm0,0x10(%rsp)
call   *%rbx
ucomisd 0x8(%rsp),%xmm0
movsd  0x30(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
jbe    126d <slicesample+0x14d>
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <drand48@plt>
movsd  0x20(%rsp),%xmm2
mulsd  %xmm2,%xmm0
movapd 0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
mulsd  0xdad(%rip),%xmm2
movsd  %xmm2,0x20(%rsp)
movapd %xmm1,0x10(%rsp)
movapd %xmm1,%xmm0
call   *%rbx
ucomisd 0x8(%rsp),%xmm0
ja     1230 <slicesample+0x110>
xor    %eax,%eax
call   1040 <drand48@plt>
movapd 0x10(%rsp),%xmm1
movsd  (%rsp),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
movapd %xmm1,0x20(%rsp)
movapd %xmm1,%xmm0
call   *%rbx
movsd  (%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
ucomisd %xmm1,%xmm0
movsd  0x38(%rsp),%xmm4
jb     132b <slicesample+0x20b>
jmp    1140 <slicesample+0x20>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm0,(%rsp)
movapd %xmm3,%xmm0
cmpltsd %xmm1,%xmm0
movapd 0x10(%rsp),%xmm2
andpd  %xmm0,%xmm2
andnpd %xmm3,%xmm0
orpd   %xmm0,%xmm2
movapd %xmm2,0x10(%rsp)
xor    %eax,%eax
call   1040 <drand48@plt>
movapd 0x10(%rsp),%xmm1
movsd  (%rsp),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
movapd %xmm1,0x20(%rsp)
movapd %xmm1,%xmm0
call   *%rbx
movsd  0x38(%rsp),%xmm4
movsd  0x8(%rsp),%xmm1
ucomisd %xmm1,%xmm0
movsd  (%rsp),%xmm2
jae    1140 <slicesample+0x20>
movapd 0x20(%rsp),%xmm3
ucomisd %xmm3,%xmm4
movapd %xmm3,%xmm0
movapd %xmm4,%xmm1
ja     12c0 <slicesample+0x1a0>
movapd %xmm2,%xmm0
jmp    12c0 <slicesample+0x1a0>
movapd %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @slicesample(double %0, double (double)* %1, double %2, i32 %3) {
%5 = alloca double
%6 = alloca double (double)*
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca i32
store double %0, double* %5
store double (double)* %1, double (double)** %6
store double %2, double* %7
store i32 %3, i32* %8
store i32 0, i32* %14
br label %15
15: ; preds = %91, %4
%16 = load i32, i32* %14
%17 = load i32, i32* %8
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %94
19: ; preds = %15
%20 = load double (double)*, double (double)** %6
%21 = load double, double* %5
%22 = call double %20(double %21)
%23 = call double (...) @drand48()
%24 = call double @log(double %23)
%25 = fadd double %22, %24
store double %25, double* %12
%26 = load double, double* %5
%27 = call double (...) @drand48()
%28 = load double, double* %7
%29 = fneg double %27
%30 = call double @llvm.fmuladd.f64(double %29, double %28, double %26)
store double %30, double* %9
%31 = load double, double* %5
%32 = call double (...) @drand48()
%33 = load double, double* %7
%34 = call double @llvm.fmuladd.f64(double %32, double %33, double %31)
store double %34, double* %10
%35 = load double, double* %7
store double %35, double* %13
br label %36
36: ; preds = %42, %19
%37 = load double (double)*, double (double)** %6
%38 = load double, double* %9
%39 = call double %37(double %38)
%40 = load double, double* %12
%41 = fcmp ogt double %39, %40
br i1 %41, label %42, label %50
42: ; preds = %36
%43 = call double (...) @drand48()
%44 = load double, double* %13
%45 = load double, double* %9
%46 = fneg double %43
%47 = call double @llvm.fmuladd.f64(double %46, double %44, double %45)
store double %47, double* %9
%48 = load double, double* %13
%49 = fmul double %48, 1.500000e+00
store double %49, double* %13
br label %36
50: ; preds = %36
%51 = load double, double* %7
store double %51, double* %13
br label %52
52: ; preds = %58, %50
%53 = load double (double)*, double (double)** %6
%54 = load double, double* %10
%55 = call double %53(double %54)
%56 = load double, double* %12
%57 = fcmp ogt double %55, %56
br i1 %57, label %58, label %65
58: ; preds = %52
%59 = call double (...) @drand48()
%60 = load double, double* %13
%61 = load double, double* %10
%62 = call double @llvm.fmuladd.f64(double %59, double %60, double %61)
store double %62, double* %10
%63 = load double, double* %13
%64 = fmul double %63, 1.500000e+00
store double %64, double* %13
br label %52
65: ; preds = %52
br label %66
66: ; preds = %88, %65
%67 = load double, double* %9
%68 = call double (...) @drand48()
%69 = load double, double* %10
%70 = load double, double* %9
%71 = fsub double %69, %70
%72 = call double @llvm.fmuladd.f64(double %68, double %71, double %67)
store double %72, double* %11
%73 = load double (double)*, double (double)** %6
%74 = load double, double* %11
%75 = call double %73(double %74)
%76 = load double, double* %12
%77 = fcmp oge double %75, %76
br i1 %77, label %78, label %79
78: ; preds = %66
br label %89
79: ; preds = %66
%80 = load double, double* %11
%81 = load double, double* %5
%82 = fcmp olt double %80, %81
br i1 %82, label %83, label %85
83: ; preds = %79
%84 = load double, double* %11
store double %84, double* %9
br label %87
85: ; preds = %79
%86 = load double, double* %11
store double %86, double* %10
br label %87
87: ; preds = %85, %83
br label %88
88: ; preds = %87
br i1 true, label %66, label %89
89: ; preds = %88, %78
%90 = load double, double* %11
store double %90, double* %5
br label %91
91: ; preds = %89
%92 = load i32, i32* %14
%93 = add nsw i32 %92, 1
store i32 %93, i32* %14
br label %15
94: ; preds = %15
%95 = load double, double* %5
ret double %95
}

LLVM IR (-O2):
define double @slicesample(double %0, double (double)* nocapture %1, double %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %64
6: ; preds = %4, %60
%7 = phi i32 [ %62, %60 ], [ 0, %4 ]
%8 = phi double [ %61, %60 ], [ %0, %4 ]
%9 = tail call double %1(double %8)
%10 = tail call double (...) @drand48()
%11 = tail call double @log(double %10)
%12 = fadd double %9, %11
%13 = tail call double (...) @drand48()
%14 = fneg double %13
%15 = tail call double @llvm.fmuladd.f64(double %14, double %2, double %8)
%16 = tail call double (...) @drand48()
%17 = tail call double @llvm.fmuladd.f64(double %16, double %2, double %8)
%18 = tail call double %1(double %15)
%19 = fcmp ogt double %18, %12
br i1 %19, label %24, label %20
20: ; preds = %24, %6
%21 = phi double [ %15, %6 ], [ %29, %24 ]
%22 = tail call double %1(double %17)
%23 = fcmp ogt double %22, %12
br i1 %23, label %40, label %33
24: ; preds = %6, %24
%25 = phi double [ %30, %24 ], [ %2, %6 ]
%26 = phi double [ %29, %24 ], [ %15, %6 ]
%27 = tail call double (...) @drand48()
%28 = fneg double %27
%29 = tail call double @llvm.fmuladd.f64(double %28, double %25, double %26)
%30 = fmul double %25, 1.500000e+00
%31 = tail call double %1(double %29)
%32 = fcmp ogt double %31, %12
br i1 %32, label %24, label %20
33: ; preds = %40, %20
%34 = phi double [ %17, %20 ], [ %44, %40 ]
%35 = tail call double (...) @drand48()
%36 = fsub double %34, %21
%37 = tail call double @llvm.fmuladd.f64(double %35, double %36, double %21)
%38 = tail call double %1(double %37)
%39 = fcmp ult double %38, %12
br i1 %39, label %48, label %60
40: ; preds = %20, %40
%41 = phi double [ %45, %40 ], [ %2, %20 ]
%42 = phi double [ %44, %40 ], [ %17, %20 ]
%43 = tail call double (...) @drand48()
%44 = tail call double @llvm.fmuladd.f64(double %43, double %41, double %42)
%45 = fmul double %41, 1.500000e+00
%46 = tail call double %1(double %44)
%47 = fcmp ogt double %46, %12
br i1 %47, label %40, label %33
48: ; preds = %33, %48
%49 = phi double [ %57, %48 ], [ %37, %33 ]
%50 = phi double [ %54, %48 ], [ %21, %33 ]
%51 = phi double [ %53, %48 ], [ %34, %33 ]
%52 = fcmp olt double %49, %8
%53 = select i1 %52, double %51, double %49
%54 = select i1 %52, double %49, double %50
%55 = tail call double (...) @drand48()
%56 = fsub double %53, %54
%57 = tail call double @llvm.fmuladd.f64(double %55, double %56, double %54)
%58 = tail call double %1(double %57)
%59 = fcmp ult double %58, %12
br i1 %59, label %48, label %60
60: ; preds = %48, %33
%61 = phi double [ %37, %33 ], [ %57, %48 ]
%62 = add nuw nsw i32 %7, 1
%63 = icmp eq i32 %62, %3
br i1 %63, label %64, label %6
64: ; preds = %60, %4
%65 = phi double [ %0, %4 ], [ %61, %60 ]
ret double %65
}