; LLVM IR from sp-nitech/SPTK :: src/generation (normal_distributed_random_value_generation)

; 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"

%"class.sptk::NormalDistributedRandomValueGeneration" = type { %"class.sptk::RandomGenerationInterface", i32, i64, i8, double, double, double }
%"class.sptk::RandomGenerationInterface" = type { ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4sptk38NormalDistributedRandomValueGeneration3GetEPd(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %1) unnamed_addr #0 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8
  %7 = load ptr, ptr %5, align 8, !tbaa !5
  %8 = icmp eq ptr null, %7
  br i1 %8, label %9, label %10

9:                                                ; preds = %2
  store i1 false, ptr %3, align 1
  br label %71

10:                                               ; preds = %2
  %11 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 3
  %12 = load i8, ptr %11, align 8, !tbaa !9, !range !16, !noundef !17
  %13 = trunc i8 %12 to i1
  br i1 %13, label %14, label %62

14:                                               ; preds = %10
  %15 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 3
  store i8 0, ptr %15, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %44, %14
  %17 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 2
  %18 = call noundef double @_ZN12_GLOBAL__N_122PseudoRandomGenerationEPm(ptr noundef %17)
  %19 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %18, double -1.000000e+00)
  %20 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 4
  store double %19, ptr %20, align 8, !tbaa !18
  %21 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 2
  %22 = call noundef double @_ZN12_GLOBAL__N_122PseudoRandomGenerationEPm(ptr noundef %21)
  %23 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %22, double -1.000000e+00)
  %24 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 5
  store double %23, ptr %24, align 8, !tbaa !19
  %25 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 4
  %26 = load double, ptr %25, align 8, !tbaa !18
  %27 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 4
  %28 = load double, ptr %27, align 8, !tbaa !18
  %29 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 5
  %30 = load double, ptr %29, align 8, !tbaa !19
  %31 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 5
  %32 = load double, ptr %31, align 8, !tbaa !19
  %33 = fmul double %30, %32
  %34 = call double @llvm.fmuladd.f64(double %26, double %28, double %33)
  %35 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 6
  store double %34, ptr %35, align 8, !tbaa !20
  br label %36

36:                                               ; preds = %16
  %37 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 6
  %38 = load double, ptr %37, align 8, !tbaa !20
  %39 = fcmp oeq double 0.000000e+00, %38
  br i1 %39, label %44, label %40

40:                                               ; preds = %36
  %41 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 6
  %42 = load double, ptr %41, align 8, !tbaa !20
  %43 = fcmp ole double 1.000000e+00, %42
  br label %44

44:                                               ; preds = %40, %36
  %45 = phi i1 [ true, %36 ], [ %43, %40 ]
  br i1 %45, label %16, label %46, !llvm.loop !21

46:                                               ; preds = %44
  %47 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 6
  %48 = load double, ptr %47, align 8, !tbaa !20
  %49 = call double @log(double noundef %48) #4
  %50 = fmul double -2.000000e+00, %49
  %51 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 6
  %52 = load double, ptr %51, align 8, !tbaa !20
  %53 = fdiv double %50, %52
  %54 = call double @sqrt(double noundef %53) #4
  %55 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 6
  store double %54, ptr %55, align 8, !tbaa !20
  %56 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 4
  %57 = load double, ptr %56, align 8, !tbaa !18
  %58 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 6
  %59 = load double, ptr %58, align 8, !tbaa !20
  %60 = fmul double %57, %59
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  store double %60, ptr %61, align 8, !tbaa !23
  br label %70

62:                                               ; preds = %10
  %63 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 3
  store i8 1, ptr %63, align 8, !tbaa !9
  %64 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 5
  %65 = load double, ptr %64, align 8, !tbaa !19
  %66 = getelementptr inbounds %"class.sptk::NormalDistributedRandomValueGeneration", ptr %6, i32 0, i32 6
  %67 = load double, ptr %66, align 8, !tbaa !20
  %68 = fmul double %65, %67
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  store double %68, ptr %69, align 8, !tbaa !23
  br label %70

70:                                               ; preds = %62, %46
  store i1 true, ptr %3, align 1
  br label %71

71:                                               ; preds = %70, %9
  %72 = load i1, ptr %3, align 1
  ret i1 %72
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef double @_ZN12_GLOBAL__N_122PseudoRandomGenerationEPm(ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: nounwind
declare double @sqrt(double noundef) #3

; Function Attrs: nounwind
declare double @log(double noundef) #3

attributes #0 = { mustprogress 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 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #4 = { 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++ TBAA"}
!9 = !{!10, !14, i64 24}
!10 = !{!"_ZTSN4sptk38NormalDistributedRandomValueGenerationE", !11, i64 0, !12, i64 8, !13, i64 16, !14, i64 24, !15, i64 32, !15, i64 40, !15, i64 48}
!11 = !{!"_ZTSN4sptk25RandomGenerationInterfaceE"}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!10, !15, i64 32}
!19 = !{!10, !15, i64 40}
!20 = !{!10, !15, i64 48}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!15, !15, i64 0}


; 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: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN4sptk38NormalDistributedRandomValueGeneration3GetEPd(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef writeonly %1) unnamed_addr #0 align 2 {
  %3 = icmp ne ptr %1, null
  br i1 %3, label %4, label %35

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i8, ptr %5, align 8, !tbaa !5, !range !14, !noundef !15
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %8, label %28

8:                                                ; preds = %4
  store i8 0, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  br label %.critedge

.critedge:                                        ; preds = %.critedge, %8
  %13 = tail call noundef double @_ZN12_GLOBAL__N_122PseudoRandomGenerationEPm(ptr noundef nonnull %9)
  %14 = tail call double @llvm.fmuladd.f64(double %13, double 2.000000e+00, double -1.000000e+00)
  store double %14, ptr %10, align 8, !tbaa !16
  %15 = tail call noundef double @_ZN12_GLOBAL__N_122PseudoRandomGenerationEPm(ptr noundef nonnull %9)
  %16 = tail call double @llvm.fmuladd.f64(double %15, double 2.000000e+00, double -1.000000e+00)
  store double %16, ptr %11, align 8, !tbaa !17
  %17 = load double, ptr %10, align 8, !tbaa !16
  %18 = fmul double %16, %16
  %19 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %18)
  store double %19, ptr %12, align 8, !tbaa !18
  %20 = fcmp une double %19, 0.000000e+00
  %21 = fcmp ult double %19, 1.000000e+00
  %or.cond = and i1 %20, %21
  br i1 %or.cond, label %22, label %.critedge, !llvm.loop !19

22:                                               ; preds = %.critedge
  %23 = tail call double @log(double noundef %19) #3
  %24 = fmul double %23, -2.000000e+00
  %25 = load double, ptr %12, align 8, !tbaa !18
  %26 = fdiv double %24, %25
  %27 = tail call double @sqrt(double noundef %26) #3
  store double %27, ptr %12, align 8, !tbaa !18
  br label %32

28:                                               ; preds = %4
  store i8 1, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %0, i64 40
  %30 = load double, ptr %29, align 8, !tbaa !17
  %31 = getelementptr inbounds i8, ptr %0, i64 48
  br label %32

32:                                               ; preds = %28, %22
  %.sink10 = phi ptr [ %31, %28 ], [ %10, %22 ]
  %.sink = phi double [ %30, %28 ], [ %27, %22 ]
  %33 = load double, ptr %.sink10, align 8, !tbaa !21
  %34 = fmul double %.sink, %33
  store double %34, ptr %1, align 8, !tbaa !21
  br label %35

35:                                               ; preds = %2, %32
  ret i1 %3
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef double @_ZN12_GLOBAL__N_122PseudoRandomGenerationEPm(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

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

attributes #0 = { mustprogress 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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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, !12, i64 24}
!6 = !{!"_ZTSN4sptk38NormalDistributedRandomValueGenerationE", !7, i64 0, !8, i64 8, !11, i64 16, !12, i64 24, !13, i64 32, !13, i64 40, !13, i64 48}
!7 = !{!"_ZTSN4sptk25RandomGenerationInterfaceE"}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"bool", !9, i64 0}
!13 = !{!"double", !9, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!6, !13, i64 32}
!17 = !{!6, !13, i64 40}
!18 = !{!6, !13, i64 48}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!13, !13, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass