#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 drand2();
double ntail(double);
double zprob(double);
double rantruncnorm(double T, int upper) {
  double u;
  if (upper == 0)
    return -rantruncnorm(-T, 1);
  u = (drand2());
  if (u == 0.0)
    u = 0.5;
  u *= ntail(T);
  if (u == 0.0)
    return ((T) < (50.0) ? (50.0) : (T));
  return zprob(u);
}


x86 assembly (clang, -O0):
<rantruncnorm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11a1 <rantruncnorm+0x61>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    $0x1,%edi
call   1050 <rantruncnorm@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    124b <rantruncnorm+0x10b>
mov    $0x0,%al
call   1040 <drand2@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d2 <rantruncnorm+0x92>
jp     11d2 <rantruncnorm+0x92>
movsd  0xe33(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <ntail@plt>
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    123c <rantruncnorm+0xfc>
jp     123c <rantruncnorm+0xfc>
movsd  0xe02(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1223 <rantruncnorm+0xe3>
movsd  0xdef(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    122d <rantruncnorm+0xed>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    124b <rantruncnorm+0x10b>
movsd  -0x20(%rbp),%xmm0
call   1060 <zprob@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rantruncnorm>:
sub    $0x28,%rsp
movapd %xmm0,(%rsp)
test   %edi,%edi
je     1199 <rantruncnorm+0x69>
xor    %eax,%eax
call   1040 <drand2@plt>
xorpd  %xmm1,%xmm1
movapd %xmm0,%xmm2
cmpeqsd %xmm1,%xmm2
movsd  0xea7(%rip),%xmm1
andpd  %xmm2,%xmm1
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
movapd %xmm2,0x10(%rsp)
movapd (%rsp),%xmm0
call   1030 <ntail@plt>
mulsd  0x10(%rsp),%xmm0
ucomisd 0xe8d(%rip),%xmm0
jne    1204 <rantruncnorm+0xd4>
jp     1204 <rantruncnorm+0xd4>
movsd  0xe79(%rip),%xmm0
maxsd  (%rsp),%xmm0
add    $0x28,%rsp
ret
movapd (%rsp),%xmm0
xorpd  0xe7a(%rip),%xmm0
movapd %xmm0,(%rsp)
xor    %eax,%eax
call   1040 <drand2@plt>
xorpd  %xmm1,%xmm1
movapd %xmm0,%xmm2
cmpeqsd %xmm1,%xmm2
movsd  0xe39(%rip),%xmm1
andpd  %xmm2,%xmm1
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
movapd %xmm2,0x10(%rsp)
movapd (%rsp),%xmm0
call   1030 <ntail@plt>
mulsd  0x10(%rsp),%xmm0
ucomisd 0xe1f(%rip),%xmm0
jne    120d <rantruncnorm+0xdd>
jp     120d <rantruncnorm+0xdd>
movsd  0xe0b(%rip),%xmm0
maxsd  (%rsp),%xmm0
jmp    1212 <rantruncnorm+0xe2>
add    $0x28,%rsp
jmp    1050 <zprob@plt>
call   1050 <zprob@plt>
xorpd  0xe06(%rip),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @rantruncnorm(double %0, i32 %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca double
store double %0, double* %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load double, double* %4
%11 = fneg double %10
%12 = call double @rantruncnorm(double %11, i32 1)
%13 = fneg double %12
store double %13, double* %3
br label %37
14: ; preds = %2
%15 = call double (...) @drand2()
store double %15, double* %6
%16 = load double, double* %6
%17 = fcmp oeq double %16, 0.000000e+00
br i1 %17, label %18, label %19
18: ; preds = %14
store double 5.000000e-01, double* %6
br label %19
19: ; preds = %18, %14
%20 = load double, double* %4
%21 = call double @ntail(double %20)
%22 = load double, double* %6
%23 = fmul double %22, %21
store double %23, double* %6
%24 = load double, double* %6
%25 = fcmp oeq double %24, 0.000000e+00
br i1 %25, label %26, label %34
26: ; preds = %19
%27 = load double, double* %4
%28 = fcmp olt double %27, 5.000000e+01
br i1 %28, label %29, label %30
29: ; preds = %26
br label %32
30: ; preds = %26
%31 = load double, double* %4
br label %32
32: ; preds = %30, %29
%33 = phi double [ 5.000000e+01, %29 ], [ %31, %30 ]
store double %33, double* %3
br label %37
34: ; preds = %19
%35 = load double, double* %6
%36 = call double @zprob(double %35)
store double %36, double* %3
br label %37
37: ; preds = %34, %32, %9
%38 = load double, double* %3
ret double %38
}

LLVM IR (-O2):
define double @rantruncnorm(double %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %20
4: ; preds = %2
%5 = fneg double %0
%6 = tail call double (...) @drand2()
%7 = fcmp oeq double %6, 0.000000e+00
%8 = select i1 %7, double 5.000000e-01, double %6
%9 = tail call double @ntail(double %5)
%10 = fmul double %9, %8
%11 = fcmp oeq double %10, 0.000000e+00
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = fcmp olt double %5, 5.000000e+01
%14 = select i1 %13, double 5.000000e+01, double %5
br label %17
15: ; preds = %4
%16 = tail call double @zprob(double %10)
br label %17
17: ; preds = %12, %15
%18 = phi double [ %14, %12 ], [ %16, %15 ]
%19 = fneg double %18
br label %32
20: ; preds = %2
%21 = tail call double (...) @drand2()
%22 = fcmp oeq double %21, 0.000000e+00
%23 = select i1 %22, double 5.000000e-01, double %21
%24 = tail call double @ntail(double %0)
%25 = fmul double %24, %23
%26 = fcmp oeq double %25, 0.000000e+00
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = fcmp olt double %0, 5.000000e+01
%29 = select i1 %28, double 5.000000e+01, double %0
br label %32
30: ; preds = %20
%31 = tail call double @zprob(double %25)
br label %32
32: ; preds = %30, %27, %17
%33 = phi double [ %19, %17 ], [ %29, %27 ], [ %31, %30 ]
ret double %33
}