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

; 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 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 noundef i32 @_ZNK10R3Polyline7IsPointEv(ptr noundef nonnull align 8 dereferenceable(96) %0) unnamed_addr #1 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %class.R3Polyline, ptr %6, i32 0, i32 4
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  br label %42

11:                                               ; preds = %1
  %12 = getelementptr inbounds %class.R3Polyline, ptr %6, i32 0, i32 4
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %16

15:                                               ; preds = %11
  store i32 1, ptr %2, align 4
  br label %42

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !17
  br label %17

17:                                               ; preds = %36, %16
  %18 = load i32, ptr %4, align 4, !tbaa !17
  %19 = getelementptr inbounds %class.R3Polyline, ptr %6, i32 0, i32 4
  %20 = load i32, ptr %19, align 8, !tbaa !9
  %21 = icmp slt i32 %18, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %17
  store i32 2, ptr %5, align 4
  br label %39

23:                                               ; preds = %17
  %24 = getelementptr inbounds %class.R3Polyline, ptr %6, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !18
  %26 = getelementptr inbounds %class.R3Point, ptr %25, i64 0
  %27 = getelementptr inbounds %class.R3Polyline, ptr %6, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  %29 = load i32, ptr %4, align 4, !tbaa !17
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %class.R3Point, ptr %28, i64 %30
  %32 = call noundef i32 @_Z10R3ContainsRK7R3PointS1_(ptr noundef nonnull align 8 dereferenceable(24) %26, ptr noundef nonnull align 8 dereferenceable(24) %31)
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %35, label %34

34:                                               ; preds = %23
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %39

35:                                               ; preds = %23
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %4, align 4, !tbaa !17
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %4, align 4, !tbaa !17
  br label %17, !llvm.loop !19

39:                                               ; preds = %34, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %40 = load i32, ptr %5, align 4
  switch i32 %40, label %44 [
    i32 2, label %41
    i32 1, label %42
  ]

41:                                               ; preds = %39
  store i32 1, ptr %2, align 4
  br label %42

42:                                               ; preds = %41, %39, %15, %10
  %43 = load i32, ptr %2, align 4
  ret i32 %43

44:                                               ; preds = %39
  unreachable
}

declare noundef i32 @_Z10R3ContainsRK7R3PointS1_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) #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 = { 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, !13, i64 32}
!10 = !{!"_ZTS10R3Polyline", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !14, i64 40}
!11 = !{!"_ZTS7R3Curve", !12, i64 0}
!12 = !{!"_ZTS7R3Shape"}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTS5R3Box", !15, i64 0, !16, i64 8, !16, i64 32}
!15 = !{!"_ZTS7R3Solid", !12, i64 0}
!16 = !{!"_ZTS7R3Point", !7, i64 0}
!17 = !{!13, !13, i64 0}
!18 = !{!10, !6, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"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 uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZNK10R3Polyline7IsPointEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(96) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %switch = icmp ult i32 %3, 2
  br i1 %switch, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %.not89 = icmp slt i32 %3, 2
  br i1 %.not89, label %._crit_edge, label %.lr.ph

5:                                                ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %6 = load i32, ptr %2, align 8, !tbaa !5
  %7 = sext i32 %6 to i64
  %.not8.not = icmp slt i64 %indvars.iv.next, %7
  br i1 %.not8.not, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !16

.lr.ph:                                           ; preds = %.preheader, %5
  %indvars.iv = phi i64 [ %indvars.iv.next, %5 ], [ 1, %.preheader ]
  %8 = load ptr, ptr %4, align 8, !tbaa !18
  %9 = getelementptr inbounds %class.R3Point, ptr %8, i64 %indvars.iv
  %10 = tail call noundef i32 @_Z10R3ContainsRK7R3PointS1_(ptr noundef nonnull align 8 dereferenceable(24) %8, ptr noundef nonnull align 8 dereferenceable(24) %9)
  %.not = icmp ne i32 %10, 0
  br i1 %.not, label %5, label %._crit_edge.loopexit

._crit_edge.loopexit:                             ; preds = %.lr.ph, %5
  %11 = zext i1 %.not to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %1, %.preheader, %._crit_edge.loopexit
  %.1 = phi i32 [ 1, %.preheader ], [ %11, %._crit_edge.loopexit ], [ %3, %1 ]
  ret i32 %.1
}

declare noundef i32 @_Z10R3ContainsRK7R3PointS1_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1

attributes #0 = { 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 #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" }

!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 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!6, !9, i64 8}


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