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

; 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"

%struct.R3MeshProperty = type { ptr, [1024 x i8], i32, ptr, double, double, double, double, double, 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 nounwind uwtable
define dso_local noundef double @_ZNK14R3MeshProperty7MaximumEv(ptr noundef nonnull align 8 dereferenceable(1096) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  %6 = getelementptr inbounds %struct.R3MeshProperty, ptr %5, i32 0, i32 7
  %7 = load double, ptr %6, align 8, !tbaa !9
  %8 = fcmp oeq double %7, -1.000000e+00
  br i1 %8, label %9, label %59

9:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store ptr %5, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.R3MeshProperty, ptr %10, i32 0, i32 7
  store double 0.000000e+00, ptr %11, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.R3MeshProperty, ptr %5, i32 0, i32 2
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %15, label %58

15:                                               ; preds = %9
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.R3MeshProperty, ptr %16, i32 0, i32 7
  store double 0xC7EFFFFFE0000000, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !14
  br label %18

18:                                               ; preds = %54, %15
  %19 = load i32, ptr %4, align 4, !tbaa !14
  %20 = getelementptr inbounds %struct.R3MeshProperty, ptr %5, i32 0, i32 2
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %57

24:                                               ; preds = %18
  %25 = getelementptr inbounds %struct.R3MeshProperty, ptr %5, i32 0, i32 3
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = load i32, ptr %4, align 4, !tbaa !14
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds double, ptr %26, i64 %28
  %30 = load double, ptr %29, align 8, !tbaa !16
  %31 = fcmp oeq double %30, -1.000000e+00
  br i1 %31, label %32, label %33

32:                                               ; preds = %24
  br label %54

33:                                               ; preds = %24
  %34 = getelementptr inbounds %struct.R3MeshProperty, ptr %5, i32 0, i32 3
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  %36 = load i32, ptr %4, align 4, !tbaa !14
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds double, ptr %35, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !16
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.R3MeshProperty, ptr %40, i32 0, i32 7
  %42 = load double, ptr %41, align 8, !tbaa !9
  %43 = fcmp ogt double %39, %42
  br i1 %43, label %44, label %53

44:                                               ; preds = %33
  %45 = getelementptr inbounds %struct.R3MeshProperty, ptr %5, i32 0, i32 3
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = load i32, ptr %4, align 4, !tbaa !14
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds double, ptr %46, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !16
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.R3MeshProperty, ptr %51, i32 0, i32 7
  store double %50, ptr %52, align 8, !tbaa !9
  br label %53

53:                                               ; preds = %44, %33
  br label %54

54:                                               ; preds = %53, %32
  %55 = load i32, ptr %4, align 4, !tbaa !14
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %4, align 4, !tbaa !14
  br label %18, !llvm.loop !17

57:                                               ; preds = %23
  br label %58

58:                                               ; preds = %57, %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  br label %59

59:                                               ; preds = %58, %1
  %60 = getelementptr inbounds %struct.R3MeshProperty, ptr %5, i32 0, i32 7
  %61 = load double, ptr %60, align 8, !tbaa !9
  ret double %61
}

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, !12, i64 1072}
!10 = !{!"_ZTS14R3MeshProperty", !6, i64 0, !7, i64 8, !11, i64 1032, !6, i64 1040, !12, i64 1048, !12, i64 1056, !12, i64 1064, !12, i64 1072, !12, i64 1080, !12, i64 1088}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!10, !11, i64 1032}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !6, i64 1040}
!16 = !{!12, !12, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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 nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef double @_ZNK14R3MeshProperty7MaximumEv(ptr nocapture noundef nonnull align 8 dereferenceable(1096) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 1072
  %3 = load double, ptr %2, align 8, !tbaa !5
  %4 = fcmp oeq double %3, -1.000000e+00
  br i1 %4, label %5, label %.loopexit

5:                                                ; preds = %1
  store double 0.000000e+00, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 1032
  %7 = load i32, ptr %6, align 8, !tbaa !12
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %9, label %.loopexit

9:                                                ; preds = %5
  store double 0xC7EFFFFFE0000000, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 1040
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %wide.trip.count = zext nneg i32 %7 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %12 = icmp eq i32 %7, 1
  br i1 %12, label %.loopexit.loopexit.unr-lcssa, label %.new

.new:                                             ; preds = %9
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %13

13:                                               ; preds = %27, %.new
  %indvars.iv = phi i64 [ 0, %.new ], [ %indvars.iv.next.1, %27 ]
  %14 = phi double [ 0xC7EFFFFFE0000000, %.new ], [ %28, %27 ]
  %niter = phi i64 [ 0, %.new ], [ %niter.next.1, %27 ]
  %15 = getelementptr inbounds double, ptr %11, i64 %indvars.iv
  %16 = load double, ptr %15, align 8, !tbaa !14
  %17 = fcmp une double %16, -1.000000e+00
  %18 = fcmp ogt double %16, %14
  %or.cond = select i1 %17, i1 %18, i1 false
  br i1 %or.cond, label %19, label %20

19:                                               ; preds = %13
  store double %16, ptr %2, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %19, %13
  %21 = phi double [ %16, %19 ], [ %14, %13 ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %22 = getelementptr inbounds double, ptr %11, i64 %indvars.iv.next
  %23 = load double, ptr %22, align 8, !tbaa !14
  %24 = fcmp une double %23, -1.000000e+00
  %25 = fcmp ogt double %23, %21
  %or.cond.1 = select i1 %24, i1 %25, i1 false
  br i1 %or.cond.1, label %26, label %27

26:                                               ; preds = %20
  store double %23, ptr %2, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %26, %20
  %28 = phi double [ %23, %26 ], [ %21, %20 ]
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %13, !llvm.loop !15

.loopexit.loopexit.unr-lcssa:                     ; preds = %27, %9
  %.lcssa.ph = phi double [ poison, %9 ], [ %28, %27 ]
  %indvars.iv.unr = phi i64 [ 0, %9 ], [ %indvars.iv.next.1, %27 ]
  %.unr = phi double [ 0xC7EFFFFFE0000000, %9 ], [ %28, %27 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.epil.preheader

.epil.preheader:                                  ; preds = %.loopexit.loopexit.unr-lcssa
  %29 = getelementptr inbounds double, ptr %11, i64 %indvars.iv.unr
  %30 = load double, ptr %29, align 8, !tbaa !14
  %31 = fcmp une double %30, -1.000000e+00
  %32 = fcmp ogt double %30, %.unr
  %or.cond.epil = select i1 %31, i1 %32, i1 false
  br i1 %or.cond.epil, label %33, label %.loopexit

33:                                               ; preds = %.epil.preheader
  store double %30, ptr %2, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %33, %.epil.preheader, %5, %1
  %34 = phi double [ 0.000000e+00, %5 ], [ %3, %1 ], [ %.lcssa.ph, %.loopexit.loopexit.unr-lcssa ], [ %30, %33 ], [ %.unr, %.epil.preheader ]
  ret double %34
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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" }

!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, !11, i64 1072}
!6 = !{!"_ZTS14R3MeshProperty", !7, i64 0, !8, i64 8, !10, i64 1032, !7, i64 1040, !11, i64 1048, !11, i64 1056, !11, i64 1064, !11, i64 1072, !11, i64 1080, !11, i64 1088}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!6, !10, i64 1032}
!13 = !{!6, !7, i64 1040}
!14 = !{!11, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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