; LLVM IR from hoodoer/ENNEoS :: enneosEncoder/genotype.ll (ZN7CGenome13MutateWeightsEddd)

; 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.CGenome = type <{ i32, [4 x i8], %"class.std::vector", %"class.std::vector.0", ptr, i32, [4 x i8], double, double, double, i32, i32, i32, [4 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<SNeuronGene, std::allocator<SNeuronGene>>::_Vector_impl" }
%"struct.std::_Vector_base<SNeuronGene, std::allocator<SNeuronGene>>::_Vector_impl" = type { %"struct.std::_Vector_base<SNeuronGene, std::allocator<SNeuronGene>>::_Vector_impl_data" }
%"struct.std::_Vector_base<SNeuronGene, std::allocator<SNeuronGene>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<SLinkGene, std::allocator<SLinkGene>>::_Vector_impl" }
%"struct.std::_Vector_base<SLinkGene, std::allocator<SLinkGene>>::_Vector_impl" = type { %"struct.std::_Vector_base<SLinkGene, std::allocator<SLinkGene>>::_Vector_impl_data" }
%"struct.std::_Vector_base<SLinkGene, std::allocator<SLinkGene>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.SLinkGene = type <{ i8, [3 x i8], i32, i32, i32, double, i8, [7 x i8] }>

; 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: inlinehint mustprogress uwtable
declare dso_local noundef double @_Z13RandomClampedv() #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI9SLinkGeneSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(25) ptr @_ZNSt6vectorI9SLinkGeneSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_Z10RandDoublev() #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7CGenome13MutateWeightsEddd(ptr noundef nonnull align 8 dereferenceable(108) %0, double noundef %1, double noundef %2, double noundef %3) #4 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store double %2, ptr %7, align 8, !tbaa !9
  store double %3, ptr %8, align 8, !tbaa !9
  %10 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %11

11:                                               ; preds = %45, %4
  %12 = load i32, ptr %9, align 4, !tbaa !11
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds %class.CGenome, ptr %10, i32 0, i32 3
  %15 = call noundef i64 @_ZNKSt6vectorI9SLinkGeneSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %14) #6
  %16 = icmp ult i64 %13, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %48

18:                                               ; preds = %11
  %19 = call noundef double @_Z10RandDoublev()
  %20 = load double, ptr %6, align 8, !tbaa !9
  %21 = fcmp olt double %19, %20
  br i1 %21, label %22, label %44

22:                                               ; preds = %18
  %23 = call noundef double @_Z10RandDoublev()
  %24 = load double, ptr %7, align 8, !tbaa !9
  %25 = fcmp olt double %23, %24
  br i1 %25, label %26, label %33

26:                                               ; preds = %22
  %27 = call noundef double @_Z13RandomClampedv()
  %28 = getelementptr inbounds %class.CGenome, ptr %10, i32 0, i32 3
  %29 = load i32, ptr %9, align 4, !tbaa !11
  %30 = zext i32 %29 to i64
  %31 = call noundef nonnull align 8 dereferenceable(25) ptr @_ZNSt6vectorI9SLinkGeneSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %28, i64 noundef %30) #6
  %32 = getelementptr inbounds %struct.SLinkGene, ptr %31, i32 0, i32 5
  store double %27, ptr %32, align 8, !tbaa !13
  br label %43

33:                                               ; preds = %22
  %34 = call noundef double @_Z13RandomClampedv()
  %35 = load double, ptr %8, align 8, !tbaa !9
  %36 = getelementptr inbounds %class.CGenome, ptr %10, i32 0, i32 3
  %37 = load i32, ptr %9, align 4, !tbaa !11
  %38 = zext i32 %37 to i64
  %39 = call noundef nonnull align 8 dereferenceable(25) ptr @_ZNSt6vectorI9SLinkGeneSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %36, i64 noundef %38) #6
  %40 = getelementptr inbounds %struct.SLinkGene, ptr %39, i32 0, i32 5
  %41 = load double, ptr %40, align 8, !tbaa !13
  %42 = call double @llvm.fmuladd.f64(double %34, double %35, double %41)
  store double %42, ptr %40, align 8, !tbaa !13
  br label %43

43:                                               ; preds = %33, %26
  br label %44

44:                                               ; preds = %43, %18
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %9, align 4, !tbaa !11
  %47 = add i32 %46, 1
  store i32 %47, ptr %9, align 4, !tbaa !11
  br label %11, !llvm.loop !16

48:                                               ; preds = %17
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #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 = { 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 #4 = { 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 16}
!14 = !{!"_ZTS9SLinkGene", !15, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !10, i64 16, !15, i64 24}
!15 = !{!"bool", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_Z13RandomClampedv() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI9SLinkGeneSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(25) ptr @_ZNSt6vectorI9SLinkGeneSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_Z10RandDoublev() local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7CGenome13MutateWeightsEddd(ptr noundef nonnull align 8 dereferenceable(108) %0, double noundef %1, double noundef %2, double noundef %3) local_unnamed_addr #3 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = tail call noundef i64 @_ZNKSt6vectorI9SLinkGeneSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #5
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %17, %4
  ret void

.lr.ph:                                           ; preds = %4, %17
  %7 = phi i64 [ %19, %17 ], [ 0, %4 ]
  %.08 = phi i32 [ %18, %17 ], [ 0, %4 ]
  %8 = tail call noundef double @_Z10RandDoublev()
  %9 = fcmp olt double %8, %1
  br i1 %9, label %.sink.split, label %17

.sink.split:                                      ; preds = %.lr.ph
  %10 = tail call noundef double @_Z10RandDoublev()
  %11 = fcmp olt double %10, %2
  %12 = tail call noundef double @_Z13RandomClampedv()
  %13 = tail call noundef nonnull align 8 dereferenceable(25) ptr @_ZNSt6vectorI9SLinkGeneSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %7) #5
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %15 = load double, ptr %14, align 8
  %16 = tail call double @llvm.fmuladd.f64(double %12, double %3, double %15)
  %.sink = select i1 %11, double %12, double %16
  store double %.sink, ptr %14, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %.sink.split, %.lr.ph
  %18 = add i32 %.08, 1
  %19 = zext i32 %18 to i64
  %20 = tail call noundef i64 @_ZNKSt6vectorI9SLinkGeneSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #5
  %21 = icmp ugt i64 %20, %19
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !12
}

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

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass