; LLVM IR from fritzsedlazeck/SURVIVOR :: src/simulator/Sim_reads.ll (Z11rand_normaldd)

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

@_ZZ11rand_normalddE2n2 = external hidden global double, align 8
@_ZZ11rand_normalddE9n2_cached = external hidden global i32, align 4

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z11rand_normaldd(double noundef %0, double noundef %1) #2 {
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  store double %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !5
  %12 = load i32, ptr @_ZZ11rand_normalddE9n2_cached, align 4, !tbaa !9
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %58, label %14

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  br label %15

15:                                               ; preds = %38, %14
  %16 = call i32 @rand() #4
  %17 = sitofp i32 %16 to double
  %18 = fmul double 2.000000e+00, %17
  %19 = fdiv double %18, 0x41DFFFFFFFC00000
  %20 = fsub double %19, 1.000000e+00
  store double %20, ptr %6, align 8, !tbaa !5
  %21 = call i32 @rand() #4
  %22 = sitofp i32 %21 to double
  %23 = fmul double 2.000000e+00, %22
  %24 = fdiv double %23, 0x41DFFFFFFFC00000
  %25 = fsub double %24, 1.000000e+00
  store double %25, ptr %7, align 8, !tbaa !5
  %26 = load double, ptr %6, align 8, !tbaa !5
  %27 = load double, ptr %6, align 8, !tbaa !5
  %28 = load double, ptr %7, align 8, !tbaa !5
  %29 = load double, ptr %7, align 8, !tbaa !5
  %30 = fmul double %28, %29
  %31 = call double @llvm.fmuladd.f64(double %26, double %27, double %30)
  store double %31, ptr %8, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %15
  %33 = load double, ptr %8, align 8, !tbaa !5
  %34 = fcmp oeq double %33, 0.000000e+00
  br i1 %34, label %38, label %35

35:                                               ; preds = %32
  %36 = load double, ptr %8, align 8, !tbaa !5
  %37 = fcmp ogt double %36, 1.000000e+00
  br label %38

38:                                               ; preds = %35, %32
  %39 = phi i1 [ true, %32 ], [ %37, %35 ]
  br i1 %39, label %15, label %40, !llvm.loop !11

40:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %41 = load double, ptr %8, align 8, !tbaa !5
  %42 = call double @log(double noundef %41) #4
  %43 = fmul double -2.000000e+00, %42
  %44 = load double, ptr %8, align 8, !tbaa !5
  %45 = fdiv double %43, %44
  %46 = call double @sqrt(double noundef %45) #4
  store double %46, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %47 = load double, ptr %6, align 8, !tbaa !5
  %48 = load double, ptr %9, align 8, !tbaa !5
  %49 = fmul double %47, %48
  store double %49, ptr %10, align 8, !tbaa !5
  %50 = load double, ptr %7, align 8, !tbaa !5
  %51 = load double, ptr %9, align 8, !tbaa !5
  %52 = fmul double %50, %51
  store double %52, ptr @_ZZ11rand_normalddE2n2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %53 = load double, ptr %10, align 8, !tbaa !5
  %54 = load double, ptr %5, align 8, !tbaa !5
  %55 = load double, ptr %4, align 8, !tbaa !5
  %56 = call double @llvm.fmuladd.f64(double %53, double %54, double %55)
  store double %56, ptr %11, align 8, !tbaa !5
  store i32 1, ptr @_ZZ11rand_normalddE9n2_cached, align 4, !tbaa !9
  %57 = load double, ptr %11, align 8, !tbaa !5
  store double %57, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %63

58:                                               ; preds = %2
  store i32 0, ptr @_ZZ11rand_normalddE9n2_cached, align 4, !tbaa !9
  %59 = load double, ptr @_ZZ11rand_normalddE2n2, align 8, !tbaa !5
  %60 = load double, ptr %5, align 8, !tbaa !5
  %61 = load double, ptr %4, align 8, !tbaa !5
  %62 = call double @llvm.fmuladd.f64(double %59, double %60, double %61)
  store double %62, ptr %3, align 8
  br label %63

63:                                               ; preds = %58, %40
  %64 = load double, ptr %3, align 8
  ret double %64
}

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"double", !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"

@_ZZ11rand_normalddE2n2 = external hidden local_unnamed_addr global double, align 8
@_ZZ11rand_normalddE9n2_cached = external hidden local_unnamed_addr global i32, align 4

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

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

.preheader:                                       ; preds = %2, %.preheader
  %4 = tail call i32 @rand() #4
  %5 = sitofp i32 %4 to double
  %6 = fmul double %5, 2.000000e+00
  %7 = fdiv double %6, 0x41DFFFFFFFC00000
  %8 = fadd double %7, -1.000000e+00
  %9 = tail call i32 @rand() #4
  %10 = sitofp i32 %9 to double
  %11 = fmul double %10, 2.000000e+00
  %12 = fdiv double %11, 0x41DFFFFFFFC00000
  %13 = fadd double %12, -1.000000e+00
  %14 = fmul double %13, %13
  %15 = tail call double @llvm.fmuladd.f64(double %8, double %8, double %14)
  %16 = fcmp oeq double %15, 0.000000e+00
  %17 = fcmp ogt double %15, 1.000000e+00
  %18 = or i1 %16, %17
  br i1 %18, label %.preheader, label %19, !llvm.loop !9

19:                                               ; preds = %.preheader
  %20 = tail call double @log(double noundef %15) #4
  %21 = fmul double %20, -2.000000e+00
  %22 = fdiv double %21, %15
  %23 = tail call double @sqrt(double noundef %22) #4
  %24 = fmul double %8, %23
  %25 = fmul double %13, %23
  store double %25, ptr @_ZZ11rand_normalddE2n2, align 8, !tbaa !11
  %26 = tail call double @llvm.fmuladd.f64(double %24, double %1, double %0)
  store i32 1, ptr @_ZZ11rand_normalddE9n2_cached, align 4, !tbaa !5
  br label %30

27:                                               ; preds = %2
  store i32 0, ptr @_ZZ11rand_normalddE9n2_cached, align 4, !tbaa !5
  %28 = load double, ptr @_ZZ11rand_normalddE2n2, align 8, !tbaa !11
  %29 = tail call double @llvm.fmuladd.f64(double %28, double %1, double %0)
  br label %30

30:                                               ; preds = %27, %19
  %.0 = phi double [ %29, %27 ], [ %26, %19 ]
  ret double %.0
}

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @log(double noundef) local_unnamed_addr #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 = { 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}


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