; LLVM IR from csviragh/robotsim :: src/utilities (math_utils)

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

@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [33 x i8], align 1
@randomizeGaussDouble.uniRand = external hidden global double, align 8
@randomizeGaussDouble.uniRand2 = external hidden global double, align 8
@randomizeGaussDouble.Theta = external hidden global double, align 8
@randomizeGaussDouble.Rho = external hidden global double, align 8

; Function Attrs: nounwind uwtable
declare dso_local double @randomizeDouble(double noundef, double noundef) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local double @randomizeGaussDouble(double noundef %0, double noundef %1) #0 {
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  store double %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !5
  %5 = load double, ptr %4, align 8, !tbaa !5
  %6 = fcmp olt double %5, 0.000000e+00
  br i1 %6, label %7, label %10

7:                                                ; preds = %2
  %8 = load ptr, ptr @stderr, align 8, !tbaa !9
  %9 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef @.str.1) #4
  call void @exit(i32 noundef -3) #5
  unreachable

10:                                               ; preds = %2
  br label %11

11:                                               ; preds = %13, %10
  %12 = call double @randomizeDouble(double noundef 0.000000e+00, double noundef 1.000000e+00)
  store double %12, ptr @randomizeGaussDouble.uniRand, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %11
  %14 = load double, ptr @randomizeGaussDouble.uniRand, align 8, !tbaa !5
  %15 = fcmp oeq double %14, 1.000000e+00
  br i1 %15, label %11, label %16, !llvm.loop !11

16:                                               ; preds = %13
  %17 = call double @randomizeDouble(double noundef 0.000000e+00, double noundef 1.000000e+00)
  store double %17, ptr @randomizeGaussDouble.uniRand2, align 8, !tbaa !5
  %18 = load double, ptr @randomizeGaussDouble.uniRand2, align 8, !tbaa !5
  %19 = fmul double 0x401921FB54442D18, %18
  store double %19, ptr @randomizeGaussDouble.Theta, align 8, !tbaa !5
  %20 = load double, ptr @randomizeGaussDouble.uniRand, align 8, !tbaa !5
  %21 = fsub double 1.000000e+00, %20
  %22 = call double @log(double noundef %21) #4
  %23 = fmul double -2.000000e+00, %22
  %24 = call double @sqrt(double noundef %23) #4
  store double %24, ptr @randomizeGaussDouble.Rho, align 8, !tbaa !5
  %25 = load double, ptr %3, align 8, !tbaa !5
  %26 = load double, ptr %4, align 8, !tbaa !5
  %27 = load double, ptr @randomizeGaussDouble.Rho, align 8, !tbaa !5
  %28 = fmul double %26, %27
  %29 = load double, ptr @randomizeGaussDouble.Theta, align 8, !tbaa !5
  %30 = call double @cos(double noundef %29) #4
  %31 = call double @llvm.fmuladd.f64(double %28, double %30, double %25)
  ret double %31
}

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

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

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

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

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 = { 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 = { noreturn 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }
attributes #5 = { noreturn 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, !10, i64 0}
!10 = !{!"any pointer", !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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [33 x i8], align 1
@randomizeGaussDouble.uniRand = external hidden local_unnamed_addr global double, align 8
@randomizeGaussDouble.uniRand2 = external hidden local_unnamed_addr global double, align 8
@randomizeGaussDouble.Theta = external hidden local_unnamed_addr global double, align 8
@randomizeGaussDouble.Rho = external hidden local_unnamed_addr global double, align 8

; Function Attrs: nounwind uwtable
declare dso_local double @randomizeDouble(double noundef, double noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local double @randomizeGaussDouble(double noundef %0, double noundef %1) local_unnamed_addr #0 {
  %3 = fcmp olt double %1, 0.000000e+00
  br i1 %3, label %4, label %.preheader

4:                                                ; preds = %2
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.1) #5
  tail call void @exit(i32 noundef -3) #6
  unreachable

.preheader:                                       ; preds = %2, %.preheader
  %7 = tail call double @randomizeDouble(double noundef 0.000000e+00, double noundef 1.000000e+00)
  store double %7, ptr @randomizeGaussDouble.uniRand, align 8, !tbaa !9
  %8 = fcmp oeq double %7, 1.000000e+00
  br i1 %8, label %.preheader, label %9, !llvm.loop !11

9:                                                ; preds = %.preheader
  %10 = tail call double @randomizeDouble(double noundef 0.000000e+00, double noundef 1.000000e+00)
  store double %10, ptr @randomizeGaussDouble.uniRand2, align 8, !tbaa !9
  %11 = fmul double %10, 0x401921FB54442D18
  store double %11, ptr @randomizeGaussDouble.Theta, align 8, !tbaa !9
  %12 = load double, ptr @randomizeGaussDouble.uniRand, align 8, !tbaa !9
  %13 = fsub double 1.000000e+00, %12
  %14 = tail call double @log(double noundef %13) #7
  %15 = fmul double %14, -2.000000e+00
  %16 = tail call double @sqrt(double noundef %15) #7
  store double %16, ptr @randomizeGaussDouble.Rho, align 8, !tbaa !9
  %17 = fmul double %16, %1
  %18 = load double, ptr @randomizeGaussDouble.Theta, align 8, !tbaa !9
  %19 = tail call double @cos(double noundef %18) #7
  %20 = tail call double @llvm.fmuladd.f64(double %17, double %19, double %0)
  ret double %20
}

; 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

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

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

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 = { nofree 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 = { noreturn 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 = { 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { cold nounwind }
attributes #6 = { noreturn nounwind }
attributes #7 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass