; LLVM IR from erayzesen/QuarkPhysics :: QuarkPhysics/polypartition/polypartition.ll (ZNK8TPPLPoly14GetOrientationEv)

; 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.TPPLPoly = type <{ ptr, i64, i8, [7 x i8] }>
%struct.TPPLPoint = type { double, double, i32 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZNK8TPPLPoly14GetOrientationEv(ptr noundef nonnull align 8 dereferenceable(17) %0) #0 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  store i64 0, ptr %4, align 8, !tbaa !11
  br label %9

9:                                                ; preds = %52, %1
  %10 = load i64, ptr %4, align 8, !tbaa !11
  %11 = getelementptr inbounds %class.TPPLPoly, ptr %8, i32 0, i32 1
  %12 = load i64, ptr %11, align 8, !tbaa !13
  %13 = icmp slt i64 %10, %12
  br i1 %13, label %14, label %55

14:                                               ; preds = %9
  %15 = load i64, ptr %4, align 8, !tbaa !11
  %16 = add nsw i64 %15, 1
  store i64 %16, ptr %5, align 8, !tbaa !11
  %17 = load i64, ptr %5, align 8, !tbaa !11
  %18 = getelementptr inbounds %class.TPPLPoly, ptr %8, i32 0, i32 1
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = icmp eq i64 %17, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %14
  store i64 0, ptr %5, align 8, !tbaa !11
  br label %22

22:                                               ; preds = %21, %14
  %23 = getelementptr inbounds %class.TPPLPoly, ptr %8, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = load i64, ptr %4, align 8, !tbaa !11
  %26 = getelementptr inbounds %struct.TPPLPoint, ptr %24, i64 %25
  %27 = getelementptr inbounds %struct.TPPLPoint, ptr %26, i32 0, i32 0
  %28 = load double, ptr %27, align 8, !tbaa !17
  %29 = getelementptr inbounds %class.TPPLPoly, ptr %8, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !16
  %31 = load i64, ptr %5, align 8, !tbaa !11
  %32 = getelementptr inbounds %struct.TPPLPoint, ptr %30, i64 %31
  %33 = getelementptr inbounds %struct.TPPLPoint, ptr %32, i32 0, i32 1
  %34 = load double, ptr %33, align 8, !tbaa !20
  %35 = getelementptr inbounds %class.TPPLPoly, ptr %8, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !16
  %37 = load i64, ptr %4, align 8, !tbaa !11
  %38 = getelementptr inbounds %struct.TPPLPoint, ptr %36, i64 %37
  %39 = getelementptr inbounds %struct.TPPLPoint, ptr %38, i32 0, i32 1
  %40 = load double, ptr %39, align 8, !tbaa !20
  %41 = getelementptr inbounds %class.TPPLPoly, ptr %8, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  %43 = load i64, ptr %5, align 8, !tbaa !11
  %44 = getelementptr inbounds %struct.TPPLPoint, ptr %42, i64 %43
  %45 = getelementptr inbounds %struct.TPPLPoint, ptr %44, i32 0, i32 0
  %46 = load double, ptr %45, align 8, !tbaa !17
  %47 = fmul double %40, %46
  %48 = fneg double %47
  %49 = call double @llvm.fmuladd.f64(double %28, double %34, double %48)
  %50 = load double, ptr %6, align 8, !tbaa !9
  %51 = fadd double %50, %49
  store double %51, ptr %6, align 8, !tbaa !9
  br label %52

52:                                               ; preds = %22
  %53 = load i64, ptr %4, align 8, !tbaa !11
  %54 = add nsw i64 %53, 1
  store i64 %54, ptr %4, align 8, !tbaa !11
  br label %9, !llvm.loop !21

55:                                               ; preds = %9
  %56 = load double, ptr %6, align 8, !tbaa !9
  %57 = fcmp ogt double %56, 0.000000e+00
  br i1 %57, label %58, label %59

58:                                               ; preds = %55
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %64

59:                                               ; preds = %55
  %60 = load double, ptr %6, align 8, !tbaa !9
  %61 = fcmp olt double %60, 0.000000e+00
  br i1 %61, label %62, label %63

62:                                               ; preds = %59
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %64

63:                                               ; preds = %59
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %64

64:                                               ; preds = %63, %62, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %65 = load i32, ptr %2, align 4
  ret i32 %65
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"_ZTS8TPPLPoly", !6, i64 0, !12, i64 8, !15, i64 16}
!15 = !{!"bool", !7, i64 0}
!16 = !{!14, !6, i64 0}
!17 = !{!18, !10, i64 0}
!18 = !{!"_ZTS9TPPLPoint", !10, i64 0, !10, i64 8, !19, i64 16}
!19 = !{!"int", !7, i64 0}
!20 = !{!18, !10, i64 8}
!21 = distinct !{!21, !22}
!22 = !{!"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"

%struct.TPPLPoint = type { double, double, i32 }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef range(i32 -1, 2) i32 @_ZNK8TPPLPoly14GetOrientationEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(17) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = icmp sgt i64 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %5 = load ptr, ptr %0, align 8, !tbaa !12
  br label %6

6:                                                ; preds = %.lr.ph, %6
  %.016 = phi double [ 0.000000e+00, %.lr.ph ], [ %20, %6 ]
  %.01315 = phi i64 [ 0, %.lr.ph ], [ %7, %6 ]
  %7 = add nuw nsw i64 %.01315, 1
  %8 = icmp eq i64 %7, %3
  %spec.store.select = select i1 %8, i64 0, i64 %7
  %9 = getelementptr inbounds %struct.TPPLPoint, ptr %5, i64 %.01315
  %10 = load double, ptr %9, align 8, !tbaa !13
  %11 = getelementptr inbounds %struct.TPPLPoint, ptr %5, i64 %spec.store.select
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = load double, ptr %12, align 8, !tbaa !17
  %14 = getelementptr inbounds i8, ptr %9, i64 8
  %15 = load double, ptr %14, align 8, !tbaa !17
  %16 = load double, ptr %11, align 8, !tbaa !13
  %17 = fneg double %15
  %18 = fmul double %16, %17
  %19 = tail call double @llvm.fmuladd.f64(double %10, double %13, double %18)
  %20 = fadd double %.016, %19
  %exitcond.not = icmp eq i64 %7, %3
  br i1 %exitcond.not, label %._crit_edge, label %6, !llvm.loop !18

._crit_edge:                                      ; preds = %6, %1
  %.0.lcssa = phi double [ 0.000000e+00, %1 ], [ %20, %6 ]
  %21 = fcmp ogt double %.0.lcssa, 0.000000e+00
  %22 = fcmp olt double %.0.lcssa, 0.000000e+00
  %. = sext i1 %22 to i32
  %.012 = select i1 %21, i32 1, i32 %.
  ret i32 %.012
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, 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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !10, i64 8}
!6 = !{!"_ZTS8TPPLPoly", !7, i64 0, !10, i64 8, !11, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTS9TPPLPoint", !15, i64 0, !15, i64 8, !16, i64 16}
!15 = !{!"double", !8, i64 0}
!16 = !{!"int", !8, i64 0}
!17 = !{!14, !15, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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