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

; 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

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 uwtable
define dso_local void @_ZN9NOMAD_4_313ArrayOfDoubleC2EmRKNS_6DoubleE(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %1, ptr noundef nonnull align 8 dereferenceable(17) %2) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  store ptr getelementptr inbounds inrange(-16, 56) ({ [9 x ptr] }, ptr @_ZTVN9NOMAD_4_313ArrayOfDoubleE, i32 0, i32 0, i32 2), ptr %9, align 8, !tbaa !11
  %10 = getelementptr inbounds %"class.NOMAD_4_3::ArrayOfDouble", ptr %9, i32 0, i32 1
  %11 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %11, ptr %10, align 8, !tbaa !13
  %12 = getelementptr inbounds %"class.NOMAD_4_3::ArrayOfDouble", ptr %9, i32 0, i32 2
  store ptr null, ptr %12, align 8, !tbaa !15
  %13 = getelementptr inbounds %"class.NOMAD_4_3::ArrayOfDouble", ptr %9, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !13
  %15 = icmp ugt i64 %14, 0
  br i1 %15, label %16, label %61

16:                                               ; preds = %3
  %17 = getelementptr inbounds %"class.NOMAD_4_3::ArrayOfDouble", ptr %9, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !13
  %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) #8
  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 %50

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 %9, i32 0, i32 2
  store ptr %28, ptr %38, align 8, !tbaa !15
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = call noundef zeroext i1 @_ZNK9NOMAD_4_36Double9isDefinedEv(ptr noundef nonnull align 8 dereferenceable(17) %39)
  br i1 %40, label %41, label %60

41:                                               ; preds = %37
  %42 = getelementptr inbounds %"class.NOMAD_4_3::ArrayOfDouble", ptr %9, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = getelementptr inbounds %"class.NOMAD_4_3::ArrayOfDouble", ptr %9, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  %46 = getelementptr inbounds %"class.NOMAD_4_3::ArrayOfDouble", ptr %9, i32 0, i32 1
  %47 = load i64, ptr %46, align 8, !tbaa !13
  %48 = getelementptr inbounds %"class.NOMAD_4_3::Double", ptr %45, i64 %47
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZSt4fillIPN9NOMAD_4_36DoubleES1_EvT_S3_RKT0_(ptr noundef %43, ptr noundef %48, ptr noundef nonnull align 8 dereferenceable(17) %49)
  br label %60

50:                                               ; preds = %32
  %51 = landingpad { ptr, i32 }
          cleanup
  %52 = extractvalue { ptr, i32 } %51, 0
  store ptr %52, ptr %7, align 8
  %53 = extractvalue { ptr, i32 } %51, 1
  store i32 %53, ptr %8, align 4
  %54 = icmp eq ptr %28, %33
  br i1 %54, label %59, label %55

55:                                               ; preds = %55, %50
  %56 = phi ptr [ %33, %50 ], [ %57, %55 ]
  %57 = getelementptr inbounds %"class.NOMAD_4_3::Double", ptr %56, i64 -1
  call void @_ZN9NOMAD_4_36DoubleD1Ev(ptr noundef nonnull align 8 dereferenceable(17) %57) #9
  %58 = icmp eq ptr %57, %28
  br i1 %58, label %59, label %55

59:                                               ; preds = %55, %50
  call void @_ZdaPvm(ptr noundef %27, i64 noundef %26) #10
  br label %64

60:                                               ; preds = %41, %37
  br label %63

61:                                               ; preds = %3
  %62 = getelementptr inbounds %"class.NOMAD_4_3::ArrayOfDouble", ptr %9, i32 0, i32 1
  store i64 0, ptr %62, align 8, !tbaa !13
  br label %63

63:                                               ; preds = %61, %60
  ret void

64:                                               ; preds = %59
  %65 = load ptr, ptr %7, align 8
  %66 = load i32, ptr %8, align 4
  %67 = insertvalue { ptr, i32 } poison, ptr %65, 0
  %68 = insertvalue { ptr, i32 } %67, i32 %66, 1
  resume { ptr, i32 } %68
}

; 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 nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK9NOMAD_4_36Double9isDefinedEv(ptr noundef nonnull align 8 dereferenceable(17)) #6 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPN9NOMAD_4_36DoubleES1_EvT_S3_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 8 dereferenceable(17)) #7

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 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 = { 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 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 = { 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 #8 = { builtin allocsize(0) }
attributes #9 = { nounwind }
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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"_ZTSN9NOMAD_4_313ArrayOfDoubleE", !10, i64 8, !6, i64 16}
!15 = !{!14, !6, i64 16}


; 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 uwtable
define dso_local void @_ZN9NOMAD_4_313ArrayOfDoubleC2EmRKNS_6DoubleE(ptr nocapture noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %1, ptr noundef nonnull align 8 dereferenceable(17) %2) unnamed_addr #2 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
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %1, ptr %4, 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 %1, 0
  br i1 %.not, label %30, label %6

6:                                                ; preds = %3
  %7 = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %1, 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 %1, ptr %15, align 16
  %.ptr8 = getelementptr inbounds i8, ptr %15, i64 8
  %16 = getelementptr inbounds %"class.NOMAD_4_3::Double", ptr %.ptr8, i64 %1
  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 %26

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

20:                                               ; preds = %18
  store ptr %.ptr8, ptr %5, align 8, !tbaa !13
  %21 = tail call noundef zeroext i1 @_ZNK9NOMAD_4_36Double9isDefinedEv(ptr noundef nonnull align 8 dereferenceable(17) %2)
  br i1 %21, label %22, label %31

22:                                               ; preds = %20
  %23 = load ptr, ptr %5, align 8, !tbaa !13
  %24 = load i64, ptr %4, align 8, !tbaa !8
  %25 = getelementptr inbounds %"class.NOMAD_4_3::Double", ptr %23, i64 %24
  tail call void @_ZSt4fillIPN9NOMAD_4_36DoubleES1_EvT_S3_RKT0_(ptr noundef %23, ptr noundef %25, ptr noundef nonnull align 8 dereferenceable(17) %2)
  br label %31

26:                                               ; preds = %17
  %27 = landingpad { ptr, i32 }
          cleanup
  %28 = icmp eq i64 %.idx, 8
  br i1 %28, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %26, %.preheader
  %.idx9 = phi i64 [ %.add10, %.preheader ], [ %.idx, %26 ]
  %.add10 = add nsw i64 %.idx9, -24
  %.ptr12 = getelementptr inbounds i8, ptr %15, i64 %.add10
  tail call void @_ZN9NOMAD_4_36DoubleD1Ev(ptr noundef nonnull align 8 dereferenceable(17) %.ptr12) #9
  %29 = icmp eq i64 %.add10, 8
  br i1 %29, label %.loopexit, label %.preheader

.loopexit:                                        ; preds = %.preheader, %26
  tail call void @_ZdaPvm(ptr noundef nonnull %15, i64 noundef %14) #10
  resume { ptr, i32 } %27

30:                                               ; preds = %3
  store i64 0, ptr %4, align 8, !tbaa !8
  br label %31

31:                                               ; preds = %20, %22, %30
  ret void
}

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

; Function Attrs: mustprogress 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) local_unnamed_addr #4

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK9NOMAD_4_36Double9isDefinedEv(ptr noundef nonnull align 8 dereferenceable(17)) local_unnamed_addr #6 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPN9NOMAD_4_36DoubleES1_EvT_S3_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 8 dereferenceable(17)) local_unnamed_addr #7

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 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 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 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 = { 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 #8 = { builtin allocsize(0) }
attributes #9 = { nounwind }
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 = !{!"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}


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