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

; 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.R3Point = type { [3 x double] }

; 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: mustprogress uwtable
define dso_local void @_ZNK18R3CatmullRomSpline7OutlineEd(ptr noundef nonnull align 8 dereferenceable(104) %0, double noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca %class.R3Point, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 100, ptr %5, align 4, !tbaa !11
  %10 = load double, ptr %4, align 8, !tbaa !9
  %11 = fcmp oeq double %10, 0.000000e+00
  br i1 %11, label %12, label %23

12:                                               ; preds = %2
  %13 = load ptr, ptr %9, align 8, !tbaa !13
  %14 = getelementptr inbounds ptr, ptr %13, i64 68
  %15 = load ptr, ptr %14, align 8
  %16 = call noundef double %15(ptr noundef nonnull align 8 dereferenceable(96) %9)
  %17 = load ptr, ptr %9, align 8, !tbaa !13
  %18 = getelementptr inbounds ptr, ptr %17, i64 67
  %19 = load ptr, ptr %18, align 8
  %20 = call noundef double %19(ptr noundef nonnull align 8 dereferenceable(96) %9)
  %21 = fsub double %16, %20
  %22 = fdiv double %21, 1.000000e+02
  store double %22, ptr %4, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %12, %2
  %24 = load double, ptr %4, align 8, !tbaa !9
  %25 = fcmp oeq double %24, 0.000000e+00
  br i1 %25, label %26, label %27

26:                                               ; preds = %23
  store i32 1, ptr %6, align 4
  br label %50

27:                                               ; preds = %23
  call void @glBegin(i32 noundef 3)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %28 = load ptr, ptr %9, align 8, !tbaa !13
  %29 = getelementptr inbounds ptr, ptr %28, i64 67
  %30 = load ptr, ptr %29, align 8
  %31 = call noundef double %30(ptr noundef nonnull align 8 dereferenceable(96) %9)
  store double %31, ptr %7, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %45, %27
  %33 = load double, ptr %7, align 8, !tbaa !9
  %34 = load ptr, ptr %9, align 8, !tbaa !13
  %35 = getelementptr inbounds ptr, ptr %34, i64 68
  %36 = load ptr, ptr %35, align 8
  %37 = call noundef double %36(ptr noundef nonnull align 8 dereferenceable(96) %9)
  %38 = fcmp ole double %33, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %32
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %49

40:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 24, ptr %8) #4
  %41 = load double, ptr %7, align 8, !tbaa !9
  %42 = load ptr, ptr %9, align 8, !tbaa !13
  %43 = getelementptr inbounds ptr, ptr %42, i64 71
  %44 = load ptr, ptr %43, align 8
  call void %44(ptr dead_on_unwind writable sret(%class.R3Point) align 8 %8, ptr noundef nonnull align 8 dereferenceable(104) %9, double noundef %41)
  call void @_Z11R3LoadPointRK7R3Point(ptr noundef nonnull align 8 dereferenceable(24) %8)
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #4
  br label %45

45:                                               ; preds = %40
  %46 = load double, ptr %4, align 8, !tbaa !9
  %47 = load double, ptr %7, align 8, !tbaa !9
  %48 = fadd double %47, %46
  store double %48, ptr %7, align 8, !tbaa !9
  br label %32, !llvm.loop !15

49:                                               ; preds = %39
  call void @glEnd()
  store i32 0, ptr %6, align 4
  br label %50

50:                                               ; preds = %49, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %51 = load i32, ptr %6, align 4
  switch i32 %51, label %53 [
    i32 0, label %52
    i32 1, label %52
  ]

52:                                               ; preds = %50, %50
  ret void

53:                                               ; preds = %50
  unreachable
}

declare void @glBegin(i32 noundef) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z11R3LoadPointRK7R3Point(ptr noundef nonnull align 8 dereferenceable(24)) #3

declare void @glEnd() #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 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 = { 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, !14, i64 0}
!14 = !{!"vtable pointer", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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.R3Point = type { [3 x double] }

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK18R3CatmullRomSpline7OutlineEd(ptr noundef nonnull align 8 dereferenceable(104) %0, double noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca %class.R3Point, align 8
  %4 = fcmp oeq double %1, 0.000000e+00
  br i1 %4, label %5, label %16

5:                                                ; preds = %2
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 544
  %8 = load ptr, ptr %7, align 8
  %9 = tail call noundef double %8(ptr noundef nonnull align 8 dereferenceable(96) %0)
  %10 = load ptr, ptr %0, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 536
  %12 = load ptr, ptr %11, align 8
  %13 = tail call noundef double %12(ptr noundef nonnull align 8 dereferenceable(96) %0)
  %14 = fsub double %9, %13
  %15 = fdiv double %14, 1.000000e+02
  br label %16

16:                                               ; preds = %5, %2
  %.07 = phi double [ %15, %5 ], [ %1, %2 ]
  %17 = fcmp oeq double %.07, 0.000000e+00
  br i1 %17, label %37, label %18

18:                                               ; preds = %16
  tail call void @glBegin(i32 noundef 3)
  %19 = load ptr, ptr %0, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 536
  %21 = load ptr, ptr %20, align 8
  %22 = tail call noundef double %21(ptr noundef nonnull align 8 dereferenceable(96) %0)
  %23 = load ptr, ptr %0, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 544
  %25 = load ptr, ptr %24, align 8
  %26 = tail call noundef double %25(ptr noundef nonnull align 8 dereferenceable(96) %0)
  %27 = fcmp ugt double %22, %26
  br i1 %27, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %18
  call void @glEnd()
  br label %37

.lr.ph:                                           ; preds = %18, %.lr.ph
  %.09 = phi double [ %31, %.lr.ph ], [ %22, %18 ]
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #4
  %28 = load ptr, ptr %0, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 568
  %30 = load ptr, ptr %29, align 8
  call void %30(ptr dead_on_unwind nonnull writable sret(%class.R3Point) align 8 %3, ptr noundef nonnull align 8 dereferenceable(104) %0, double noundef %.09)
  call void @_Z11R3LoadPointRK7R3Point(ptr noundef nonnull align 8 dereferenceable(24) %3)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  %31 = fadd double %.07, %.09
  %32 = load ptr, ptr %0, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 544
  %34 = load ptr, ptr %33, align 8
  %35 = call noundef double %34(ptr noundef nonnull align 8 dereferenceable(96) %0)
  %36 = fcmp ugt double %31, %35
  br i1 %36, label %._crit_edge, label %.lr.ph, !llvm.loop !8

37:                                               ; preds = %16, %._crit_edge
  ret void
}

declare void @glBegin(i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z11R3LoadPointRK7R3Point(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #3

declare void @glEnd() local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 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 = { 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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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