; LLVM IR from tsotchke/quantum_geometric_tensor :: src/quantum_geometric/core (quantum_rng)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.qrng_ctx = type { i64, i64, i64, i64, i64, [16 x double], i64, [16 x double], [16 x i64], [16 x i64], [16 x i64], %struct.timeval, i32, %union.anon, i64 }
%struct.timeval = type { i64, i64 }
%union.anon = type { [128 x i64] }

; Function Attrs: nounwind uwtable
declare hidden i64 @get_runtime_entropy(ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local double @qrng_get_entropy_estimate(ptr noundef %0) #0 {
  %2 = alloca double, align 8
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %9, label %8

8:                                                ; preds = %1
  store double 0.000000e+00, ptr %2, align 8
  br label %47

9:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store double 0.000000e+00, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %10

10:                                               ; preds = %26, %9
  %11 = load i32, ptr %5, align 4, !tbaa !11
  %12 = icmp slt i32 %11, 16
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %29

14:                                               ; preds = %10
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.qrng_ctx, ptr %15, i32 0, i32 5
  %17 = load i32, ptr %5, align 4, !tbaa !11
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [16 x double], ptr %16, i64 0, i64 %18
  %20 = load double, ptr %19, align 8, !tbaa !9
  %21 = fadd double %20, 1.000000e-10
  %22 = call double @log2(double noundef %21) #3
  %23 = fneg double %22
  %24 = load double, ptr %4, align 8, !tbaa !9
  %25 = fadd double %24, %23
  store double %25, ptr %4, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %14
  %27 = load i32, ptr %5, align 4, !tbaa !11
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %5, align 4, !tbaa !11
  br label %10, !llvm.loop !13

29:                                               ; preds = %13
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = call i64 @get_runtime_entropy(ptr noundef %30)
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.qrng_ctx, ptr %32, i32 0, i32 2
  store i64 %31, ptr %33, align 8, !tbaa !15
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.qrng_ctx, ptr %34, i32 0, i32 2
  %36 = load i64, ptr %35, align 8, !tbaa !15
  %37 = and i64 %36, 255
  %38 = uitofp i64 %37 to double
  %39 = fdiv double %38, 2.560000e+02
  %40 = fadd double %39, 1.000000e-10
  %41 = call double @log2(double noundef %40) #3
  %42 = fneg double %41
  %43 = load double, ptr %4, align 8, !tbaa !9
  %44 = fadd double %43, %42
  store double %44, ptr %4, align 8, !tbaa !9
  %45 = load double, ptr %4, align 8, !tbaa !9
  %46 = fdiv double %45, 1.700000e+01
  store double %46, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %47

47:                                               ; preds = %29, %8
  %48 = load double, ptr %2, align 8
  ret double %48
}

; Function Attrs: nounwind
declare double @log2(double noundef) #2

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !17, i64 16}
!16 = !{!"", !17, i64 0, !17, i64 8, !17, i64 16, !17, i64 24, !17, i64 32, !7, i64 40, !17, i64 168, !7, i64 176, !7, i64 304, !7, i64 432, !7, i64 560, !18, i64 688, !12, i64 704, !7, i64 712, !17, i64 1736}
!17 = !{!"long", !7, i64 0}
!18 = !{!"timeval", !17, i64 0, !17, i64 8}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind uwtable
declare hidden i64 @get_runtime_entropy(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local double @qrng_get_entropy_estimate(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %91, label %.preheader

.preheader:                                       ; preds = %1
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = load double, ptr %2, align 8, !tbaa !5
  %4 = fadd double %3, 1.000000e-10
  %5 = tail call double @log2(double noundef %4) #2
  %6 = fsub double 0.000000e+00, %5
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = fadd double %8, 1.000000e-10
  %10 = tail call double @log2(double noundef %9) #2
  %11 = fsub double %6, %10
  %12 = getelementptr inbounds i8, ptr %0, i64 56
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = fadd double %13, 1.000000e-10
  %15 = tail call double @log2(double noundef %14) #2
  %16 = fsub double %11, %15
  %17 = getelementptr inbounds i8, ptr %0, i64 64
  %18 = load double, ptr %17, align 8, !tbaa !5
  %19 = fadd double %18, 1.000000e-10
  %20 = tail call double @log2(double noundef %19) #2
  %21 = fsub double %16, %20
  %22 = getelementptr inbounds i8, ptr %0, i64 72
  %23 = load double, ptr %22, align 8, !tbaa !5
  %24 = fadd double %23, 1.000000e-10
  %25 = tail call double @log2(double noundef %24) #2
  %26 = fsub double %21, %25
  %27 = getelementptr inbounds i8, ptr %0, i64 80
  %28 = load double, ptr %27, align 8, !tbaa !5
  %29 = fadd double %28, 1.000000e-10
  %30 = tail call double @log2(double noundef %29) #2
  %31 = fsub double %26, %30
  %32 = getelementptr inbounds i8, ptr %0, i64 88
  %33 = load double, ptr %32, align 8, !tbaa !5
  %34 = fadd double %33, 1.000000e-10
  %35 = tail call double @log2(double noundef %34) #2
  %36 = fsub double %31, %35
  %37 = getelementptr inbounds i8, ptr %0, i64 96
  %38 = load double, ptr %37, align 8, !tbaa !5
  %39 = fadd double %38, 1.000000e-10
  %40 = tail call double @log2(double noundef %39) #2
  %41 = fsub double %36, %40
  %42 = getelementptr inbounds i8, ptr %0, i64 104
  %43 = load double, ptr %42, align 8, !tbaa !5
  %44 = fadd double %43, 1.000000e-10
  %45 = tail call double @log2(double noundef %44) #2
  %46 = fsub double %41, %45
  %47 = getelementptr inbounds i8, ptr %0, i64 112
  %48 = load double, ptr %47, align 8, !tbaa !5
  %49 = fadd double %48, 1.000000e-10
  %50 = tail call double @log2(double noundef %49) #2
  %51 = fsub double %46, %50
  %52 = getelementptr inbounds i8, ptr %0, i64 120
  %53 = load double, ptr %52, align 8, !tbaa !5
  %54 = fadd double %53, 1.000000e-10
  %55 = tail call double @log2(double noundef %54) #2
  %56 = fsub double %51, %55
  %57 = getelementptr inbounds i8, ptr %0, i64 128
  %58 = load double, ptr %57, align 8, !tbaa !5
  %59 = fadd double %58, 1.000000e-10
  %60 = tail call double @log2(double noundef %59) #2
  %61 = fsub double %56, %60
  %62 = getelementptr inbounds i8, ptr %0, i64 136
  %63 = load double, ptr %62, align 8, !tbaa !5
  %64 = fadd double %63, 1.000000e-10
  %65 = tail call double @log2(double noundef %64) #2
  %66 = fsub double %61, %65
  %67 = getelementptr inbounds i8, ptr %0, i64 144
  %68 = load double, ptr %67, align 8, !tbaa !5
  %69 = fadd double %68, 1.000000e-10
  %70 = tail call double @log2(double noundef %69) #2
  %71 = fsub double %66, %70
  %72 = getelementptr inbounds i8, ptr %0, i64 152
  %73 = load double, ptr %72, align 8, !tbaa !5
  %74 = fadd double %73, 1.000000e-10
  %75 = tail call double @log2(double noundef %74) #2
  %76 = fsub double %71, %75
  %77 = getelementptr inbounds i8, ptr %0, i64 160
  %78 = load double, ptr %77, align 8, !tbaa !5
  %79 = fadd double %78, 1.000000e-10
  %80 = tail call double @log2(double noundef %79) #2
  %81 = fsub double %76, %80
  %82 = tail call i64 @get_runtime_entropy(ptr noundef nonnull %0)
  %83 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %82, ptr %83, align 8, !tbaa !9
  %84 = and i64 %82, 255
  %85 = uitofp nneg i64 %84 to double
  %86 = fmul double %85, 3.906250e-03
  %87 = fadd double %86, 1.000000e-10
  %88 = tail call double @log2(double noundef %87) #2
  %89 = fsub double %81, %88
  %90 = fdiv double %89, 1.700000e+01
  br label %91

91:                                               ; preds = %1, %.preheader
  %.012 = phi double [ %90, %.preheader ], [ 0.000000e+00, %1 ]
  ret double %.012
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @log2(double noundef) local_unnamed_addr #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 16}
!10 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !7, i64 40, !11, i64 168, !7, i64 176, !7, i64 304, !7, i64 432, !7, i64 560, !12, i64 688, !13, i64 704, !7, i64 712, !11, i64 1736}
!11 = !{!"long", !7, i64 0}
!12 = !{!"timeval", !11, i64 0, !11, i64 8}
!13 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass