; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Shapes/R3Polyline.ll (ZN10R3Polyline18SetVertexParameterEid)

; 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.R3Polyline = type { %class.R3Curve, ptr, ptr, ptr, i32, %class.R3Box }
%class.R3Curve = type { %class.R3Shape }
%class.R3Shape = type { ptr }
%class.R3Box = type { %class.R3Solid, %class.R3Point, %class.R3Point }
%class.R3Solid = type { %class.R3Shape }
%class.R3Point = type { [3 x double] }

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10R3Polyline18SetVertexParameterEid(ptr noundef nonnull align 8 dereferenceable(96) %0, i32 noundef %1, double noundef %2) unnamed_addr #3 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !11
  %9 = load ptr, ptr %4, align 8
  %10 = getelementptr inbounds %class.R3Polyline, ptr %9, i32 0, i32 4
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  br label %87

14:                                               ; preds = %3
  %15 = getelementptr inbounds %class.R3Polyline, ptr %9, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !20
  %17 = icmp ne ptr %16, null
  br i1 %17, label %80, label %18

18:                                               ; preds = %14
  %19 = getelementptr inbounds %class.R3Polyline, ptr %9, i32 0, i32 4
  %20 = load i32, ptr %19, align 8, !tbaa !13
  %21 = sext i32 %20 to i64
  %22 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %21, i64 8)
  %23 = extractvalue { i64, i1 } %22, 1
  %24 = extractvalue { i64, i1 } %22, 0
  %25 = select i1 %23, i64 -1, i64 %24
  %26 = call noalias noundef nonnull ptr @_Znam(i64 noundef %25) #4
  %27 = getelementptr inbounds %class.R3Polyline, ptr %9, i32 0, i32 2
  store ptr %26, ptr %27, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %46, %18
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %33, label %32

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

33:                                               ; preds = %28
  %34 = load double, ptr %6, align 8, !tbaa !11
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = sitofp i32 %35 to double
  %37 = fmul double %34, %36
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = sitofp i32 %38 to double
  %40 = fdiv double %37, %39
  %41 = getelementptr inbounds %class.R3Polyline, ptr %9, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !20
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds double, ptr %42, i64 %44
  store double %40, ptr %45, align 8, !tbaa !11
  br label %46

46:                                               ; preds = %33
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %7, align 4, !tbaa !9
  br label %28, !llvm.loop !21

49:                                               ; preds = %32
  %50 = load double, ptr %6, align 8, !tbaa !11
  %51 = getelementptr inbounds %class.R3Polyline, ptr %9, i32 0, i32 2
  %52 = load ptr, ptr %51, align 8, !tbaa !20
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds double, ptr %52, i64 %54
  store double %50, ptr %55, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %56 = load i32, ptr %5, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %8, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %76, %49
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = getelementptr inbounds %class.R3Polyline, ptr %9, i32 0, i32 4
  %61 = load i32, ptr %60, align 8, !tbaa !13
  %62 = icmp slt i32 %59, %61
  br i1 %62, label %64, label %63

63:                                               ; preds = %58
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %79

64:                                               ; preds = %58
  %65 = load i32, ptr %8, align 4, !tbaa !9
  %66 = load i32, ptr %5, align 4, !tbaa !9
  %67 = sub nsw i32 %65, %66
  %68 = sitofp i32 %67 to double
  %69 = load double, ptr %6, align 8, !tbaa !11
  %70 = fadd double %68, %69
  %71 = getelementptr inbounds %class.R3Polyline, ptr %9, i32 0, i32 2
  %72 = load ptr, ptr %71, align 8, !tbaa !20
  %73 = load i32, ptr %8, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds double, ptr %72, i64 %74
  store double %70, ptr %75, align 8, !tbaa !11
  br label %76

76:                                               ; preds = %64
  %77 = load i32, ptr %8, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %8, align 4, !tbaa !9
  br label %58, !llvm.loop !23

79:                                               ; preds = %63
  br label %87

80:                                               ; preds = %14
  %81 = load double, ptr %6, align 8, !tbaa !11
  %82 = getelementptr inbounds %class.R3Polyline, ptr %9, i32 0, i32 2
  %83 = load ptr, ptr %82, align 8, !tbaa !20
  %84 = load i32, ptr %5, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds double, ptr %83, i64 %85
  store double %81, ptr %86, align 8, !tbaa !11
  br label %87

87:                                               ; preds = %80, %79, %13
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { builtin allocsize(0) }
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, !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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !10, i64 32}
!14 = !{!"_ZTS10R3Polyline", !15, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !17, i64 40}
!15 = !{!"_ZTS7R3Curve", !16, i64 0}
!16 = !{!"_ZTS7R3Shape"}
!17 = !{!"_ZTS5R3Box", !18, i64 0, !19, i64 8, !19, i64 32}
!18 = !{!"_ZTS7R3Solid", !16, i64 0}
!19 = !{!"_ZTS7R3Point", !7, i64 0}
!20 = !{!14, !6, i64 16}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10R3Polyline18SetVertexParameterEid(ptr nocapture noundef nonnull align 8 dereferenceable(96) %0, i32 noundef %1, double noundef %2) unnamed_addr #1 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !16
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %10, label %49

10:                                               ; preds = %7
  %11 = sext i32 %5 to i64
  %12 = icmp slt i32 %5, 0
  %13 = shl nsw i64 %11, 3
  %14 = select i1 %12, i64 -1, i64 %13
  %15 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %14) #2
  store ptr %15, ptr %8, align 8, !tbaa !16
  %16 = icmp sgt i32 %1, 0
  br i1 %16, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %10
  %17 = uitofp nneg i32 %1 to double
  %wide.trip.count = zext nneg i32 %1 to i64
  %min.iters.check = icmp eq i32 %1, 1
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %wide.trip.count, 2147483646
  %broadcast.splatinsert = insertelement <2 x double> poison, double %2, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert32 = insertelement <2 x double> poison, double %17, i64 0
  %broadcast.splat33 = shufflevector <2 x double> %broadcast.splatinsert32, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <2 x i32> [ <i32 0, i32 1>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %18 = uitofp <2 x i32> %vec.ind to <2 x double>
  %19 = fmul <2 x double> %broadcast.splat, %18
  %20 = fdiv <2 x double> %19, %broadcast.splat33
  %21 = getelementptr inbounds double, ptr %15, i64 %index
  store <2 x double> %20, ptr %21, align 8, !tbaa !17
  %index.next = add nuw i64 %index, 2
  %vec.ind.next = add <2 x i32> %vec.ind, <i32 2, i32 2>
  %22 = icmp eq i64 %index.next, %n.vec
  br i1 %22, label %middle.block, label %vector.body, !llvm.loop !19

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %10
  %23 = sext i32 %1 to i64
  %24 = getelementptr inbounds double, ptr %15, i64 %23
  store double %2, ptr %24, align 8, !tbaa !17
  %.023 = add nsw i32 %1, 1
  %25 = icmp slt i32 %.023, %5
  br i1 %25, label %.lr.ph26.preheader, label %.loopexit

.lr.ph26.preheader:                               ; preds = %._crit_edge
  %26 = sext i32 %.023 to i64
  %27 = add i32 %5, -2
  %28 = sub i32 %27, %1
  %29 = zext i32 %28 to i64
  %30 = add nuw nsw i64 %29, 1
  %min.iters.check36 = icmp ult i32 %28, 3
  br i1 %min.iters.check36, label %.lr.ph26.preheader52, label %vector.ph37

.lr.ph26.preheader52:                             ; preds = %middle.block34, %.lr.ph26.preheader
  %indvars.iv28.ph = phi i64 [ %26, %.lr.ph26.preheader ], [ %ind.end, %middle.block34 ]
  br label %.lr.ph26

vector.ph37:                                      ; preds = %.lr.ph26.preheader
  %n.vec39 = and i64 %30, 8589934588
  %ind.end = add nsw i64 %n.vec39, %26
  %.splatinsert = insertelement <2 x i32> poison, i32 %.023, i64 0
  %.splat = shufflevector <2 x i32> %.splatinsert, <2 x i32> poison, <2 x i32> zeroinitializer
  %induction = add <2 x i32> %.splat, <i32 0, i32 1>
  %broadcast.splatinsert46 = insertelement <2 x i32> poison, i32 %1, i64 0
  %broadcast.splat47 = shufflevector <2 x i32> %broadcast.splatinsert46, <2 x i32> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert48 = insertelement <2 x double> poison, double %2, i64 0
  %broadcast.splat49 = shufflevector <2 x double> %broadcast.splatinsert48, <2 x double> poison, <2 x i32> zeroinitializer
  %invariant.gep = getelementptr double, ptr %15, i64 %26
  br label %vector.body41

vector.body41:                                    ; preds = %vector.body41, %vector.ph37
  %index42 = phi i64 [ 0, %vector.ph37 ], [ %index.next50, %vector.body41 ]
  %vec.ind43 = phi <2 x i32> [ %induction, %vector.ph37 ], [ %vec.ind.next45, %vector.body41 ]
  %step.add = add <2 x i32> %vec.ind43, <i32 2, i32 2>
  %31 = sub <2 x i32> %vec.ind43, %broadcast.splat47
  %32 = sub <2 x i32> %step.add, %broadcast.splat47
  %33 = sitofp <2 x i32> %31 to <2 x double>
  %34 = sitofp <2 x i32> %32 to <2 x double>
  %35 = fadd <2 x double> %broadcast.splat49, %33
  %36 = fadd <2 x double> %broadcast.splat49, %34
  %gep = getelementptr double, ptr %invariant.gep, i64 %index42
  %37 = getelementptr inbounds i8, ptr %gep, i64 16
  store <2 x double> %35, ptr %gep, align 8, !tbaa !17
  store <2 x double> %36, ptr %37, align 8, !tbaa !17
  %index.next50 = add nuw i64 %index42, 4
  %vec.ind.next45 = add <2 x i32> %vec.ind43, <i32 4, i32 4>
  %38 = icmp eq i64 %index.next50, %n.vec39
  br i1 %38, label %middle.block34, label %vector.body41, !llvm.loop !23

middle.block34:                                   ; preds = %vector.body41
  %cmp.n51 = icmp eq i64 %30, %n.vec39
  br i1 %cmp.n51, label %.loopexit, label %.lr.ph26.preheader52

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %39 = trunc nuw nsw i64 %indvars.iv to i32
  %40 = uitofp nneg i32 %39 to double
  %41 = fmul double %40, %2
  %42 = fdiv double %41, %17
  %43 = getelementptr inbounds double, ptr %15, i64 %indvars.iv
  store double %42, ptr %43, align 8, !tbaa !17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !24

.lr.ph26:                                         ; preds = %.lr.ph26.preheader52, %.lr.ph26
  %indvars.iv28 = phi i64 [ %indvars.iv.next29, %.lr.ph26 ], [ %indvars.iv28.ph, %.lr.ph26.preheader52 ]
  %44 = trunc i64 %indvars.iv28 to i32
  %45 = sub i32 %44, %1
  %46 = sitofp i32 %45 to double
  %47 = fadd double %46, %2
  %48 = getelementptr inbounds double, ptr %15, i64 %indvars.iv28
  store double %47, ptr %48, align 8, !tbaa !17
  %indvars.iv.next29 = add nsw i64 %indvars.iv28, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next29 to i32
  %exitcond31.not = icmp eq i32 %5, %lftr.wideiv
  br i1 %exitcond31.not, label %.loopexit, label %.lr.ph26, !llvm.loop !25

49:                                               ; preds = %7
  %50 = sext i32 %1 to i64
  %51 = getelementptr inbounds double, ptr %9, i64 %50
  store double %2, ptr %51, align 8, !tbaa !17
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph26, %middle.block34, %._crit_edge, %3, %49
  ret void
}

attributes #0 = { 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 #1 = { 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 = { builtin allocsize(0) }

!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, !12, i64 32}
!6 = !{!"_ZTS10R3Polyline", !7, i64 0, !9, i64 8, !9, i64 16, !9, i64 24, !12, i64 32, !13, i64 40}
!7 = !{!"_ZTS7R3Curve", !8, i64 0}
!8 = !{!"_ZTS7R3Shape"}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"int", !10, i64 0}
!13 = !{!"_ZTS5R3Box", !14, i64 0, !15, i64 8, !15, i64 32}
!14 = !{!"_ZTS7R3Solid", !8, i64 0}
!15 = !{!"_ZTS7R3Point", !10, i64 0}
!16 = !{!6, !9, i64 16}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !10, i64 0}
!19 = distinct !{!19, !20, !21, !22}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!"llvm.loop.isvectorized", i32 1}
!22 = !{!"llvm.loop.unroll.runtime.disable"}
!23 = distinct !{!23, !20, !21, !22}
!24 = distinct !{!24, !20, !22, !21}
!25 = distinct !{!25, !20, !22, !21}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass