#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 */
int RAND_MAX;
int log(double);
int rand();
int LogL16fromY(double Y, int em) {
  if (Y >= 1.8371976e19)
    return (0x7fff);
  if (Y <= -1.8371976e19)
    return (0xffff);
  if (Y > 5.4136769e-20)
    return (
        (em) == 0
            ? (int)(256. * (((1. / 0.69314718055994530942) * log(Y)) + 64.))
            : (int)((256. * (((1. / 0.69314718055994530942) * log(Y)) + 64.)) +
                    rand() * (1. / RAND_MAX) - .5));
  if (Y < -5.4136769e-20)
    return (
        ~0x7fff |
        ((em) == 0
             ? (int)(256. * (((1. / 0.69314718055994530942) * log(-Y)) + 64.))
             : (int)((256. *
                      (((1. / 0.69314718055994530942) * log(-Y)) + 64.)) +
                     rand() * (1. / RAND_MAX) - .5)));
  return (0);
}


x86 assembly (clang, -O0):
<LogL16fromY>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xec3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1153 <LogL16fromY+0x33>
movl   $0x7fff,-0x4(%rbp)
jmp    136e <LogL16fromY+0x24e>
movsd  0xead(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1172 <LogL16fromY+0x52>
movl   $0xffff,-0x4(%rbp)
jmp    136e <LogL16fromY+0x24e>
movsd  -0x10(%rbp),%xmm0
movsd  0xe91(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1255 <LogL16fromY+0x135>
cmpl   $0x0,-0x14(%rbp)
jne    11d1 <LogL16fromY+0xb1>
movsd  -0x10(%rbp),%xmm0
call   1030 <log@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe8f(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xe8b(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe67(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
jmp    124a <LogL16fromY+0x12a>
movsd  -0x10(%rbp),%xmm0
call   1030 <log@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe51(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe4d(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
movsd  -0x20(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
mov    0x2dd5(%rip),%rax
cvtsi2sdl (%rax),%xmm3
movsd  0xe11(%rip),%xmm2
divsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
movsd  0xdf9(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xde1(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    136e <LogL16fromY+0x24e>
movsd  0xdbb(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1367 <LogL16fromY+0x247>
cmpl   $0x0,-0x14(%rbp)
jne    12c7 <LogL16fromY+0x1a7>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <log@plt>
cvtsi2sd %eax,%xmm1
movsd  0xd99(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xd95(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xd71(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
jmp    1357 <LogL16fromY+0x237>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <log@plt>
cvtsi2sd %eax,%xmm0
movsd  0xd44(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd40(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
movsd  -0x30(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
mov    0x2cc8(%rip),%rax
cvtsi2sdl (%rax),%xmm3
movsd  0xd04(%rip),%xmm2
divsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
movsd  0xcec(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xcd4(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
or     $0xffff8000,%eax
mov    %eax,-0x4(%rbp)
jmp    136e <LogL16fromY+0x24e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LogL16fromY>:
push   %rbx
sub    $0x10,%rsp
mov    $0x7fff,%eax
ucomisd 0xece(%rip),%xmm0
jae    127d <LogL16fromY+0x15d>
mov    $0xffff,%eax
movsd  0xec3(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    127d <LogL16fromY+0x15d>
mov    %edi,%ebx
ucomisd 0xeb7(%rip),%xmm0
jbe    11d4 <LogL16fromY+0xb4>
call   1030 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xeb1(%rip),%xmm0
addsd  0xeb1(%rip),%xmm0
test   %ebx,%ebx
je     125e <LogL16fromY+0x13e>
xor    %eax,%eax
movsd  %xmm0,0x8(%rsp)
call   1040 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    0x2e4e(%rip),%rax
xorps  %xmm1,%xmm1
cvtsi2sdl (%rax),%xmm1
movsd  0xe87(%rip),%xmm2
divsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm2
movsd  0x8(%rsp),%xmm0
mulsd  0xe79(%rip),%xmm0
addsd  %xmm2,%xmm0
addsd  0xe75(%rip),%xmm0
cvttsd2si %xmm0,%eax
jmp    127d <LogL16fromY+0x15d>
xor    %eax,%eax
movsd  0xe3a(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    127d <LogL16fromY+0x15d>
xorpd  0xe60(%rip),%xmm0
call   1030 <log@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  0xe1c(%rip),%xmm1
addsd  0xe1c(%rip),%xmm1
test   %ebx,%ebx
je     126c <LogL16fromY+0x14c>
xor    %eax,%eax
movsd  %xmm1,0x8(%rsp)
call   1040 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    0x2dbd(%rip),%rax
xorps  %xmm1,%xmm1
cvtsi2sdl (%rax),%xmm1
movsd  0xdf6(%rip),%xmm2
divsd  %xmm1,%xmm2
movsd  0x8(%rsp),%xmm1
mulsd  0xdec(%rip),%xmm1
mulsd  %xmm0,%xmm2
addsd  %xmm2,%xmm1
addsd  0xde4(%rip),%xmm1
jmp    1274 <LogL16fromY+0x154>
mulsd  0xdd2(%rip),%xmm0
cvttsd2si %xmm0,%eax
jmp    127d <LogL16fromY+0x15d>
mulsd  0xdc4(%rip),%xmm1
cvttsd2si %xmm1,%eax
or     $0xffff8000,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@RAND_MAX = global i32 0
define i32 @LogL16fromY(double %0, i32 %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca i32
store double %0, double* %4
store i32 %1, i32* %5
%6 = load double, double* %4
%7 = fcmp oge double %6, 0x43EFDECBDAA8C010
br i1 %7, label %8, label %9
8: ; preds = %2
store i32 32767, i32* %3
br label %75
9: ; preds = %2
%10 = load double, double* %4
%11 = fcmp ole double %10, 0xC3EFDECBDAA8C010
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 65535, i32* %3
br label %75
13: ; preds = %9
%14 = load double, double* %4
%15 = fcmp ogt double %14, 0x3BEFF4EACF8A88B5
br i1 %15, label %16, label %42
16: ; preds = %13
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load double, double* %4
%21 = call i32 @log(double %20)
%22 = sitofp i32 %21 to double
%23 = call double @llvm.fmuladd.f64(double 0x3FF71547652B82FE, double %22, double 6.400000e+01)
%24 = fmul double 2.560000e+02, %23
%25 = fptosi double %24 to i32
br label %40
26: ; preds = %16
%27 = load double, double* %4
%28 = call i32 @log(double %27)
%29 = sitofp i32 %28 to double
%30 = call double @llvm.fmuladd.f64(double 0x3FF71547652B82FE, double %29, double 6.400000e+01)
%31 = call i32 (...) @rand()
%32 = sitofp i32 %31 to double
%33 = load i32, i32* @RAND_MAX
%34 = sitofp i32 %33 to double
%35 = fdiv double 1.000000e+00, %34
%36 = fmul double %32, %35
%37 = call double @llvm.fmuladd.f64(double 2.560000e+02, double %30, double %36)
%38 = fsub double %37, 5.000000e-01
%39 = fptosi double %38 to i32
br label %40
40: ; preds = %26, %19
%41 = phi i32 [ %25, %19 ], [ %39, %26 ]
store i32 %41, i32* %3
br label %75
42: ; preds = %13
%43 = load double, double* %4
%44 = fcmp olt double %43, 0xBBEFF4EACF8A88B5
br i1 %44, label %45, label %74
45: ; preds = %42
%46 = load i32, i32* %5
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %56
48: ; preds = %45
%49 = load double, double* %4
%50 = fneg double %49
%51 = call i32 @log(double %50)
%52 = sitofp i32 %51 to double
%53 = call double @llvm.fmuladd.f64(double 0x3FF71547652B82FE, double %52, double 6.400000e+01)
%54 = fmul double 2.560000e+02, %53
%55 = fptosi double %54 to i32
br label %71
56: ; preds = %45
%57 = load double, double* %4
%58 = fneg double %57
%59 = call i32 @log(double %58)
%60 = sitofp i32 %59 to double
%61 = call double @llvm.fmuladd.f64(double 0x3FF71547652B82FE, double %60, double 6.400000e+01)
%62 = call i32 (...) @rand()
%63 = sitofp i32 %62 to double
%64 = load i32, i32* @RAND_MAX
%65 = sitofp i32 %64 to double
%66 = fdiv double 1.000000e+00, %65
%67 = fmul double %63, %66
%68 = call double @llvm.fmuladd.f64(double 2.560000e+02, double %61, double %67)
%69 = fsub double %68, 5.000000e-01
%70 = fptosi double %69 to i32
br label %71
71: ; preds = %56, %48
%72 = phi i32 [ %55, %48 ], [ %70, %56 ]
%73 = or i32 -32768, %72
store i32 %73, i32* %3
br label %75
74: ; preds = %42
store i32 0, i32* %3
br label %75
75: ; preds = %74, %71, %40, %12, %8
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@RAND_MAX = global i32 0
define i32 @LogL16fromY(double %0, i32 %1) {
%3 = fcmp ult double %0, 0x43EFDECBDAA8C010
br i1 %3, label %4, label %50
4: ; preds = %2
%5 = fcmp ugt double %0, 0xC3EFDECBDAA8C010
br i1 %5, label %6, label %50
6: ; preds = %4
%7 = fcmp ogt double %0, 0x3BEFF4EACF8A88B5
br i1 %7, label %8, label %27
8: ; preds = %6
%9 = icmp eq i32 %1, 0
%10 = tail call i32 @log(double %0)
%11 = sitofp i32 %10 to double
%12 = tail call double @llvm.fmuladd.f64(double %11, double 0x3FF71547652B82FE, double 6.400000e+01)
br i1 %9, label %13, label %15
13: ; preds = %8
%14 = fmul double %12, 2.560000e+02
br label %24
15: ; preds = %8
%16 = tail call i32 (...) @rand()
%17 = sitofp i32 %16 to double
%18 = load i32, i32* @RAND_MAX
%19 = sitofp i32 %18 to double
%20 = fdiv double 1.000000e+00, %19
%21 = fmul double %20, %17
%22 = tail call double @llvm.fmuladd.f64(double %12, double 2.560000e+02, double %21)
%23 = fadd double %22, -5.000000e-01
br label %24
24: ; preds = %15, %13
%25 = phi double [ %14, %13 ], [ %23, %15 ]
%26 = fptosi double %25 to i32
br label %50
27: ; preds = %6
%28 = fcmp olt double %0, 0xBBEFF4EACF8A88B5
br i1 %28, label %29, label %50
29: ; preds = %27
%30 = icmp eq i32 %1, 0
%31 = fneg double %0
%32 = tail call i32 @log(double %31)
%33 = sitofp i32 %32 to double
%34 = tail call double @llvm.fmuladd.f64(double %33, double 0x3FF71547652B82FE, double 6.400000e+01)
br i1 %30, label %35, label %37
35: ; preds = %29
%36 = fmul double %34, 2.560000e+02
br label %46
37: ; preds = %29
%38 = tail call i32 (...) @rand()
%39 = sitofp i32 %38 to double
%40 = load i32, i32* @RAND_MAX
%41 = sitofp i32 %40 to double
%42 = fdiv double 1.000000e+00, %41
%43 = fmul double %42, %39
%44 = tail call double @llvm.fmuladd.f64(double %34, double 2.560000e+02, double %43)
%45 = fadd double %44, -5.000000e-01
br label %46
46: ; preds = %37, %35
%47 = phi double [ %36, %35 ], [ %45, %37 ]
%48 = fptosi double %47 to i32
%49 = or i32 %48, -32768
br label %50
50: ; preds = %27, %4, %2, %46, %24
%51 = phi i32 [ %26, %24 ], [ %49, %46 ], [ 32767, %2 ], [ 65535, %4 ], [ 0, %27 ]
ret i32 %51
}