; LLVM IR from RichtersFinger/ChainSimulation :: Chain.ll (ZN5Chain13loadFromChainEPS_)

; 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.Chain = type { double, double, double, double, double, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<ChainElement *, std::allocator<ChainElement *>>::_Vector_impl" }
%"struct.std::_Vector_base<ChainElement *, std::allocator<ChainElement *>>::_Vector_impl" = type { %"struct.std::_Vector_base<ChainElement *, std::allocator<ChainElement *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<ChainElement *, std::allocator<ChainElement *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%class.ChainElement = type { double, double, double, double, double, double, double, double, i8, ptr, ptr }

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

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

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

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

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

7:                                                ; preds = %85, %2
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds %class.Chain, ptr %6, i32 0, i32 5
  %11 = call noundef i64 @_ZNKSt6vectorIP12ChainElementSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %10) #2
  %12 = icmp ult i64 %9, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %88

14:                                               ; preds = %7
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %class.Chain, ptr %15, i32 0, i32 5
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %16, i64 noundef %18) #2
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds %class.ChainElement, ptr %20, i32 0, i32 0
  %22 = load double, ptr %21, align 8, !tbaa !11
  %23 = getelementptr inbounds %class.Chain, ptr %6, i32 0, i32 5
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %23, i64 noundef %25) #2
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds %class.ChainElement, ptr %27, i32 0, i32 0
  store double %22, ptr %28, align 8, !tbaa !11
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %class.Chain, ptr %29, i32 0, i32 5
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %30, i64 noundef %32) #2
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = getelementptr inbounds %class.ChainElement, ptr %34, i32 0, i32 1
  %36 = load double, ptr %35, align 8, !tbaa !15
  %37 = getelementptr inbounds %class.Chain, ptr %6, i32 0, i32 5
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %37, i64 noundef %39) #2
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  %42 = getelementptr inbounds %class.ChainElement, ptr %41, i32 0, i32 1
  store double %36, ptr %42, align 8, !tbaa !15
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %class.Chain, ptr %43, i32 0, i32 5
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %44, i64 noundef %46) #2
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  %49 = getelementptr inbounds %class.ChainElement, ptr %48, i32 0, i32 2
  %50 = load double, ptr %49, align 8, !tbaa !16
  %51 = getelementptr inbounds %class.Chain, ptr %6, i32 0, i32 5
  %52 = load i32, ptr %5, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %51, i64 noundef %53) #2
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  %56 = getelementptr inbounds %class.ChainElement, ptr %55, i32 0, i32 2
  store double %50, ptr %56, align 8, !tbaa !16
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %class.Chain, ptr %57, i32 0, i32 5
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %58, i64 noundef %60) #2
  %62 = load ptr, ptr %61, align 8, !tbaa !5
  %63 = getelementptr inbounds %class.ChainElement, ptr %62, i32 0, i32 3
  %64 = load double, ptr %63, align 8, !tbaa !17
  %65 = getelementptr inbounds %class.Chain, ptr %6, i32 0, i32 5
  %66 = load i32, ptr %5, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %65, i64 noundef %67) #2
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = getelementptr inbounds %class.ChainElement, ptr %69, i32 0, i32 3
  store double %64, ptr %70, align 8, !tbaa !17
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %class.Chain, ptr %71, i32 0, i32 5
  %73 = load i32, ptr %5, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %72, i64 noundef %74) #2
  %76 = load ptr, ptr %75, align 8, !tbaa !5
  %77 = getelementptr inbounds %class.ChainElement, ptr %76, i32 0, i32 6
  %78 = load double, ptr %77, align 8, !tbaa !18
  %79 = getelementptr inbounds %class.Chain, ptr %6, i32 0, i32 5
  %80 = load i32, ptr %5, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %79, i64 noundef %81) #2
  %83 = load ptr, ptr %82, align 8, !tbaa !5
  %84 = getelementptr inbounds %class.ChainElement, ptr %83, i32 0, i32 6
  store double %78, ptr %84, align 8, !tbaa !18
  br label %85

85:                                               ; preds = %14
  %86 = load i32, ptr %5, align 4, !tbaa !9
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %5, align 4, !tbaa !9
  br label %7, !llvm.loop !19

88:                                               ; preds = %13
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS12ChainElement", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !14, i64 64, !6, i64 72, !6, i64 80}
!13 = !{!"double", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!12, !13, i64 8}
!16 = !{!12, !13, i64 16}
!17 = !{!12, !13, i64 24}
!18 = !{!12, !13, i64 48}
!19 = distinct !{!19, !20}
!20 = !{!"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: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIP12ChainElementSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5Chain13loadFromChainEPS_(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  %4 = tail call noundef i64 @_ZNKSt6vectorIP12ChainElementSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #1
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %5 = getelementptr inbounds i8, ptr %1, i64 40
  br label %6

._crit_edge:                                      ; preds = %6, %2
  ret void

6:                                                ; preds = %.lr.ph, %6
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %6 ]
  %7 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %indvars.iv) #1
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = load double, ptr %8, align 8, !tbaa !9
  %10 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %indvars.iv) #1
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  store double %9, ptr %11, align 8, !tbaa !9
  %12 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %indvars.iv) #1
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  %15 = load double, ptr %14, align 8, !tbaa !13
  %16 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %indvars.iv) #1
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  store double %15, ptr %18, align 8, !tbaa !13
  %19 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %indvars.iv) #1
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  %22 = load double, ptr %21, align 8, !tbaa !14
  %23 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %indvars.iv) #1
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  store double %22, ptr %25, align 8, !tbaa !14
  %26 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %indvars.iv) #1
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 24
  %29 = load double, ptr %28, align 8, !tbaa !15
  %30 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %indvars.iv) #1
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i64 24
  store double %29, ptr %32, align 8, !tbaa !15
  %33 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %indvars.iv) #1
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 48
  %36 = load double, ptr %35, align 8, !tbaa !16
  %37 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12ChainElementSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %indvars.iv) #1
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i64 48
  store double %36, ptr %39, align 8, !tbaa !16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %40 = tail call noundef i64 @_ZNKSt6vectorIP12ChainElementSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #1
  %41 = icmp ugt i64 %40, %indvars.iv.next
  br i1 %41, label %6, label %._crit_edge, !llvm.loop !17
}

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 = { 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, !11, i64 0}
!10 = !{!"_ZTS12ChainElement", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !12, i64 64, !6, i64 72, !6, i64 80}
!11 = !{!"double", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!10, !11, i64 8}
!14 = !{!10, !11, i64 16}
!15 = !{!10, !11, i64 24}
!16 = !{!10, !11, i64 48}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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