; LLVM IR from buresjan/optim_lbm :: nomad/src/Math/ArrayOfDouble.ll (ZN9NOMAD_4_313ArrayOfDoubleC2ERKSt6vectorIdSaIdEE)

; 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.NOMAD_4_3::ArrayOfDouble" = type { ptr, i64, ptr }
%"class.NOMAD_4_3::Double" = type <{ ptr, double, i8, [7 x i8] }>

@_ZTVN9NOMAD_4_313ArrayOfDoubleE = external dso_local unnamed_addr constant { [9 x ptr] }, align 8

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

declare i32 @__gxx_personality_v0(...)

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

declare void @_ZN9NOMAD_4_36DoubleC1Ev(ptr noundef nonnull align 8 dereferenceable(17)) unnamed_addr #1

; Function Attrs: nounwind
declare void @_ZN9NOMAD_4_36DoubleD1Ev(ptr noundef nonnull align 8 dereferenceable(17)) unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.uadd.with.overflow.i64(i64, i64) #3

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #4

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPvm(ptr noundef, i64 noundef) #5

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9NOMAD_4_313ArrayOfDoubleC2ERKSt6vectorIdSaIdEE(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) unnamed_addr #6 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  store ptr getelementptr inbounds inrange(-16, 56) ({ [9 x ptr] }, ptr @_ZTVN9NOMAD_4_313ArrayOfDoubleE, i32 0, i32 0, i32 2), ptr %8, align 8, !tbaa !9
  %9 = getelementptr inbounds %"class.NOMAD_4_3::ArrayOfDouble", ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %10) #8
  store i64 %11, ptr %9, align 8, !tbaa !11
  %12 = getelementptr inbounds %"class.NOMAD_4_3::ArrayOfDouble", ptr %8, i32 0, i32 2
  store ptr null, ptr %12, align 8, !tbaa !14
  %13 = getelementptr inbounds %"class.NOMAD_4_3::ArrayOfDouble", ptr %8, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = icmp ugt i64 %14, 0
  br i1 %15, label %16, label %69

16:                                               ; preds = %2
  %17 = getelementptr inbounds %"class.NOMAD_4_3::ArrayOfDouble", ptr %8, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %18, i64 24)
  %20 = extractvalue { i64, i1 } %19, 1
  %21 = extractvalue { i64, i1 } %19, 0
  %22 = call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %21, i64 8)
  %23 = extractvalue { i64, i1 } %22, 1
  %24 = or i1 %20, %23
  %25 = extractvalue { i64, i1 } %22, 0
  %26 = select i1 %24, i64 -1, i64 %25
  %27 = call noalias noundef nonnull ptr @_Znam(i64 noundef %26) #9
  store i64 %18, ptr %27, align 16
  %28 = getelementptr inbounds i8, ptr %27, i64 8
  %29 = icmp eq i64 %18, 0
  br i1 %29, label %37, label %30

30:                                               ; preds = %16
  %31 = getelementptr inbounds %"class.NOMAD_4_3::Double", ptr %28, i64 %18
  br label %32

32:                                               ; preds = %34, %30
  %33 = phi ptr [ %28, %30 ], [ %35, %34 ]
  invoke void @_ZN9NOMAD_4_36DoubleC1Ev(ptr noundef nonnull align 8 dereferenceable(17) %33)
          to label %34 unwind label %45

34:                                               ; preds = %32
  %35 = getelementptr inbounds %"class.NOMAD_4_3::Double", ptr %33, i64 1
  %36 = icmp eq ptr %35, %31
  br i1 %36, label %37, label %32

37:                                               ; preds = %34, %16
  %38 = getelementptr inbounds %"class.NOMAD_4_3::ArrayOfDouble", ptr %8, i32 0, i32 2
  store ptr %28, ptr %38, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #8
  store i64 0, ptr %7, align 8, !tbaa !15
  br label %39

39:                                               ; preds = %65, %37
  %40 = load i64, ptr %7, align 8, !tbaa !15
  %41 = getelementptr inbounds %"class.NOMAD_4_3::ArrayOfDouble", ptr %8, i32 0, i32 1
  %42 = load i64, ptr %41, align 8, !tbaa !11
  %43 = icmp ult i64 %40, %42
  br i1 %43, label %55, label %44

44:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #8
  br label %68

45:                                               ; preds = %32
  %46 = landingpad { ptr, i32 }
          cleanup
  %47 = extractvalue { ptr, i32 } %46, 0
  store ptr %47, ptr %5, align 8
  %48 = extractvalue { ptr, i32 } %46, 1
  store i32 %48, ptr %6, align 4
  %49 = icmp eq ptr %28, %33
  br i1 %49, label %54, label %50

50:                                               ; preds = %50, %45
  %51 = phi ptr [ %33, %45 ], [ %52, %50 ]
  %52 = getelementptr inbounds %"class.NOMAD_4_3::Double", ptr %51, i64 -1
  call void @_ZN9NOMAD_4_36DoubleD1Ev(ptr noundef nonnull align 8 dereferenceable(17) %52) #8
  %53 = icmp eq ptr %52, %28
  br i1 %53, label %54, label %50

54:                                               ; preds = %50, %45
  call void @_ZdaPvm(ptr noundef %27, i64 noundef %26) #10
  br label %72

55:                                               ; preds = %39
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load i64, ptr %7, align 8, !tbaa !15
  %58 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %56, i64 noundef %57) #8
  %59 = load double, ptr %58, align 8, !tbaa !16
  %60 = getelementptr inbounds %"class.NOMAD_4_3::ArrayOfDouble", ptr %8, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !14
  %62 = load i64, ptr %7, align 8, !tbaa !15
  %63 = getelementptr inbounds %"class.NOMAD_4_3::Double", ptr %61, i64 %62
  %64 = call noundef nonnull align 8 dereferenceable(17) ptr @_ZN9NOMAD_4_36DoubleaSEd(ptr noundef nonnull align 8 dereferenceable(17) %63, double noundef %59)
  br label %65

65:                                               ; preds = %55
  %66 = load i64, ptr %7, align 8, !tbaa !15
  %67 = add i64 %66, 1
  store i64 %67, ptr %7, align 8, !tbaa !15
  br label %39, !llvm.loop !18

68:                                               ; preds = %44
  br label %71

69:                                               ; preds = %2
  %70 = getelementptr inbounds %"class.NOMAD_4_3::ArrayOfDouble", ptr %8, i32 0, i32 1
  store i64 0, ptr %70, align 8, !tbaa !11
  br label %71

71:                                               ; preds = %69, %68
  ret void

72:                                               ; preds = %54
  %73 = load ptr, ptr %5, align 8
  %74 = load i32, ptr %6, align 4
  %75 = insertvalue { ptr, i32 } poison, ptr %73, 0
  %76 = insertvalue { ptr, i32 } %75, i32 %74, 1
  resume { ptr, i32 } %76
}

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

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

declare noundef nonnull align 8 dereferenceable(17) ptr @_ZN9NOMAD_4_36DoubleaSEd(ptr noundef nonnull align 8 dereferenceable(17), double noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 "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 = { nobuiltin allocsize(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 = { nobuiltin 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 #6 = { 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 #7 = { 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 #8 = { nounwind }
attributes #9 = { builtin allocsize(0) }
attributes #10 = { builtin 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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"_ZTSN9NOMAD_4_313ArrayOfDoubleE", !13, i64 8, !6, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 16}
!15 = !{!13, !13, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%"class.NOMAD_4_3::Double" = type <{ ptr, double, i8, [7 x i8] }>

@_ZTVN9NOMAD_4_313ArrayOfDoubleE = external dso_local unnamed_addr constant { [9 x ptr] }, align 8

declare i32 @__gxx_personality_v0(...)

declare void @_ZN9NOMAD_4_36DoubleC1Ev(ptr noundef nonnull align 8 dereferenceable(17)) unnamed_addr #0

; Function Attrs: nounwind
declare void @_ZN9NOMAD_4_36DoubleD1Ev(ptr noundef nonnull align 8 dereferenceable(17)) unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.uadd.with.overflow.i64(i64, i64) #2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #3

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPvm(ptr noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9NOMAD_4_313ArrayOfDoubleC2ERKSt6vectorIdSaIdEE(ptr nocapture noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) unnamed_addr #5 align 2 personality ptr @__gxx_personality_v0 {
  store ptr getelementptr inbounds inrange(-16, 56) (i8, ptr @_ZTVN9NOMAD_4_313ArrayOfDoubleE, i64 16), ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = tail call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #7
  store i64 %4, ptr %3, align 8, !tbaa !8
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr null, ptr %5, align 8, !tbaa !13
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %34, label %6

6:                                                ; preds = %2
  %7 = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %4, i64 24)
  %8 = extractvalue { i64, i1 } %7, 1
  %9 = extractvalue { i64, i1 } %7, 0
  %10 = tail call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %9, i64 8)
  %11 = extractvalue { i64, i1 } %10, 1
  %12 = or i1 %8, %11
  %13 = extractvalue { i64, i1 } %10, 0
  %14 = select i1 %12, i64 -1, i64 %13
  %15 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %14) #8
  store i64 %4, ptr %15, align 16
  %.ptr12 = getelementptr inbounds i8, ptr %15, i64 8
  %16 = getelementptr inbounds %"class.NOMAD_4_3::Double", ptr %.ptr12, i64 %4
  br label %17

17:                                               ; preds = %18, %6
  %.idx = phi i64 [ 8, %6 ], [ %.add, %18 ]
  %.ptr.ptr = getelementptr inbounds i8, ptr %15, i64 %.idx
  invoke void @_ZN9NOMAD_4_36DoubleC1Ev(ptr noundef nonnull align 8 dereferenceable(17) %.ptr.ptr)
          to label %18 unwind label %22

18:                                               ; preds = %17
  %.add = add nuw nsw i64 %.idx, 24
  %.ptr11 = getelementptr inbounds i8, ptr %15, i64 %.add
  %19 = icmp eq ptr %.ptr11, %16
  br i1 %19, label %20, label %17

20:                                               ; preds = %18
  store ptr %.ptr12, ptr %5, align 8, !tbaa !13
  %21 = load i64, ptr %3, align 8, !tbaa !8
  %.not20 = icmp eq i64 %21, 0
  br i1 %.not20, label %.loopexit, label %.lr.ph

22:                                               ; preds = %17
  %23 = landingpad { ptr, i32 }
          cleanup
  %24 = icmp eq i64 %.idx, 8
  br i1 %24, label %.loopexit17, label %.preheader

.preheader:                                       ; preds = %22, %.preheader
  %.idx13 = phi i64 [ %.add14, %.preheader ], [ %.idx, %22 ]
  %.add14 = add nsw i64 %.idx13, -24
  %.ptr16 = getelementptr inbounds i8, ptr %15, i64 %.add14
  tail call void @_ZN9NOMAD_4_36DoubleD1Ev(ptr noundef nonnull align 8 dereferenceable(17) %.ptr16) #7
  %25 = icmp eq i64 %.add14, 8
  br i1 %25, label %.loopexit17, label %.preheader

.loopexit17:                                      ; preds = %.preheader, %22
  tail call void @_ZdaPvm(ptr noundef nonnull %15, i64 noundef %14) #9
  resume { ptr, i32 } %23

.lr.ph:                                           ; preds = %20, %.lr.ph
  %.019 = phi i64 [ %31, %.lr.ph ], [ 0, %20 ]
  %26 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.019) #7
  %27 = load double, ptr %26, align 8, !tbaa !14
  %28 = load ptr, ptr %5, align 8, !tbaa !13
  %29 = getelementptr inbounds %"class.NOMAD_4_3::Double", ptr %28, i64 %.019
  %30 = tail call noundef nonnull align 8 dereferenceable(17) ptr @_ZN9NOMAD_4_36DoubleaSEd(ptr noundef nonnull align 8 dereferenceable(17) %29, double noundef %27)
  %31 = add nuw i64 %.019, 1
  %32 = load i64, ptr %3, align 8, !tbaa !8
  %33 = icmp ult i64 %31, %32
  br i1 %33, label %.lr.ph, label %.loopexit, !llvm.loop !16

34:                                               ; preds = %2
  store i64 0, ptr %3, align 8, !tbaa !8
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %20, %34
  ret void
}

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

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

declare noundef nonnull align 8 dereferenceable(17) ptr @_ZN9NOMAD_4_36DoubleaSEd(ptr noundef nonnull align 8 dereferenceable(17), double noundef) local_unnamed_addr #0

attributes #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nobuiltin allocsize(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 = { nobuiltin 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 #5 = { 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 #6 = { 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 #7 = { nounwind }
attributes #8 = { builtin allocsize(0) }
attributes #9 = { builtin 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !10, i64 8}
!9 = !{!"_ZTSN9NOMAD_4_313ArrayOfDoubleE", !10, i64 8, !12, i64 16}
!10 = !{!"long", !11, i64 0}
!11 = !{!"omnipotent char", !7, i64 0}
!12 = !{!"any pointer", !11, i64 0}
!13 = !{!9, !12, i64 16}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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