; LLVM IR from alenic/realGA :: src/stat.ll (ZN4Stat12randGaussianEff)

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

@_ZZN4Stat12randGaussianEffE2y2 = external hidden global float, align 4
@_ZZN4Stat12randGaussianEffE8use_last = external hidden global i32, align 4

; Function Attrs: nounwind
declare i32 @rand() #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN4Stat12randGaussianEff(float noundef %0, float noundef %1) #2 align 2 {
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  store float %0, ptr %3, align 4, !tbaa !5
  store float %1, ptr %4, align 4, !tbaa !5
  %9 = load float, ptr %4, align 4, !tbaa !5
  %10 = fcmp olt float %9, 0x3E112E0BE0000000
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  store float 0x3E112E0BE0000000, ptr %4, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %11, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %13 = load i32, ptr @_ZZN4Stat12randGaussianEffE8use_last, align 4, !tbaa !9
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %17

15:                                               ; preds = %12
  %16 = load float, ptr @_ZZN4Stat12randGaussianEffE2y2, align 4, !tbaa !5
  store float %16, ptr %8, align 4, !tbaa !5
  store i32 0, ptr @_ZZN4Stat12randGaussianEffE8use_last, align 4, !tbaa !9
  br label %59

17:                                               ; preds = %12
  br label %18

18:                                               ; preds = %39, %17
  %19 = call i32 @rand() #5
  %20 = sitofp i32 %19 to float
  %21 = fpext float %20 to double
  %22 = fmul double 2.000000e+00, %21
  %23 = fdiv double %22, 0x41E0000000000000
  %24 = fsub double %23, 1.000000e+00
  %25 = fptrunc double %24 to float
  store float %25, ptr %5, align 4, !tbaa !5
  %26 = call i32 @rand() #5
  %27 = sitofp i32 %26 to float
  %28 = fpext float %27 to double
  %29 = fmul double 2.000000e+00, %28
  %30 = fdiv double %29, 0x41E0000000000000
  %31 = fsub double %30, 1.000000e+00
  %32 = fptrunc double %31 to float
  store float %32, ptr %6, align 4, !tbaa !5
  %33 = load float, ptr %5, align 4, !tbaa !5
  %34 = load float, ptr %5, align 4, !tbaa !5
  %35 = load float, ptr %6, align 4, !tbaa !5
  %36 = load float, ptr %6, align 4, !tbaa !5
  %37 = fmul float %35, %36
  %38 = call float @llvm.fmuladd.f32(float %33, float %34, float %37)
  store float %38, ptr %7, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %18
  %40 = load float, ptr %7, align 4, !tbaa !5
  %41 = fpext float %40 to double
  %42 = fcmp oge double %41, 1.000000e+00
  br i1 %42, label %18, label %43, !llvm.loop !11

43:                                               ; preds = %39
  %44 = load float, ptr %7, align 4, !tbaa !5
  %45 = call noundef float @_ZSt3logf(float noundef %44)
  %46 = fpext float %45 to double
  %47 = fmul double -2.000000e+00, %46
  %48 = load float, ptr %7, align 4, !tbaa !5
  %49 = fpext float %48 to double
  %50 = fdiv double %47, %49
  %51 = call double @sqrt(double noundef %50) #5
  %52 = fptrunc double %51 to float
  store float %52, ptr %7, align 4, !tbaa !5
  %53 = load float, ptr %5, align 4, !tbaa !5
  %54 = load float, ptr %7, align 4, !tbaa !5
  %55 = fmul float %53, %54
  store float %55, ptr %8, align 4, !tbaa !5
  %56 = load float, ptr %6, align 4, !tbaa !5
  %57 = load float, ptr %7, align 4, !tbaa !5
  %58 = fmul float %56, %57
  store float %58, ptr @_ZZN4Stat12randGaussianEffE2y2, align 4, !tbaa !5
  store i32 1, ptr @_ZZN4Stat12randGaussianEffE8use_last, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %43, %15
  %60 = load float, ptr %3, align 4, !tbaa !5
  %61 = load float, ptr %8, align 4, !tbaa !5
  %62 = load float, ptr %4, align 4, !tbaa !5
  %63 = call float @llvm.fmuladd.f32(float %61, float %62, float %60)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret float %63
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt3logf(float noundef) #4

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint 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 #5 = { 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

@_ZZN4Stat12randGaussianEffE2y2 = external hidden local_unnamed_addr global float, align 4
@_ZZN4Stat12randGaussianEffE8use_last = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef float @_ZN4Stat12randGaussianEff(float noundef %0, float noundef %1) local_unnamed_addr #2 align 2 {
  %3 = load i32, ptr @_ZZN4Stat12randGaussianEffE8use_last, align 4, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %.preheader, label %4

4:                                                ; preds = %2
  %5 = load float, ptr @_ZZN4Stat12randGaussianEffE2y2, align 4, !tbaa !9
  br label %33

.preheader:                                       ; preds = %2, %.preheader
  %6 = tail call i32 @rand() #5
  %7 = sitofp i32 %6 to float
  %8 = fpext float %7 to double
  %9 = fmul double %8, 2.000000e+00
  %10 = fmul double %9, 0x3E00000000000000
  %11 = fadd double %10, -1.000000e+00
  %12 = fptrunc double %11 to float
  %13 = tail call i32 @rand() #5
  %14 = sitofp i32 %13 to float
  %15 = fpext float %14 to double
  %16 = fmul double %15, 2.000000e+00
  %17 = fmul double %16, 0x3E00000000000000
  %18 = fadd double %17, -1.000000e+00
  %19 = fptrunc double %18 to float
  %20 = fmul float %19, %19
  %21 = tail call float @llvm.fmuladd.f32(float %12, float %12, float %20)
  %22 = fcmp ult float %21, 1.000000e+00
  br i1 %22, label %23, label %.preheader, !llvm.loop !11

23:                                               ; preds = %.preheader
  %24 = fpext float %21 to double
  %25 = tail call noundef float @_ZSt3logf(float noundef %21)
  %26 = fpext float %25 to double
  %27 = fmul double %26, -2.000000e+00
  %28 = fdiv double %27, %24
  %29 = tail call double @sqrt(double noundef %28) #5
  %30 = fptrunc double %29 to float
  %31 = fmul float %12, %30
  %32 = fmul float %19, %30
  store float %32, ptr @_ZZN4Stat12randGaussianEffE2y2, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %23, %4
  %storemerge = phi i32 [ 1, %23 ], [ 0, %4 ]
  %.0 = phi float [ %31, %23 ], [ %5, %4 ]
  %34 = fcmp olt float %1, 0x3E112E0BE0000000
  %.015 = select i1 %34, float 0x3E112E0BE0000000, float %1
  store i32 %storemerge, ptr @_ZZN4Stat12randGaussianEffE8use_last, align 4, !tbaa !5
  %35 = tail call float @llvm.fmuladd.f32(float %.0, float %.015, float %0)
  ret float %35
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt3logf(float noundef) local_unnamed_addr #4

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { 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 #4 = { inlinehint 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 #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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