; LLVM IR from NavInfoNC/nc-geo :: src/static_polygon.ll (Z21Polygon_calculateAreaP5Pointm)

; 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.Point = type { i32, i32 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z21Polygon_calculateAreaP5Pointm(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store i64 0, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %8 = load i64, ptr %4, align 8, !tbaa !9
  %9 = sub i64 %8, 1
  store i64 %9, ptr %7, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %45, %2
  %11 = load i64, ptr %6, align 8, !tbaa !9
  %12 = load i64, ptr %4, align 8, !tbaa !9
  %13 = icmp ult i64 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %48

15:                                               ; preds = %10
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.Point, ptr %16, i64 %17
  %19 = getelementptr inbounds %struct.Point, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = sext i32 %20 to i64
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load i64, ptr %7, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.Point, ptr %22, i64 %23
  %25 = getelementptr inbounds %struct.Point, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !16
  %27 = sext i32 %26 to i64
  %28 = mul nsw i64 %21, %27
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load i64, ptr %7, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.Point, ptr %29, i64 %30
  %32 = getelementptr inbounds %struct.Point, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 4, !tbaa !13
  %34 = sext i32 %33 to i64
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load i64, ptr %6, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.Point, ptr %35, i64 %36
  %38 = getelementptr inbounds %struct.Point, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !16
  %40 = sext i32 %39 to i64
  %41 = mul nsw i64 %34, %40
  %42 = sub nsw i64 %28, %41
  %43 = load i64, ptr %5, align 8, !tbaa !11
  %44 = add nsw i64 %43, %42
  store i64 %44, ptr %5, align 8, !tbaa !11
  br label %45

45:                                               ; preds = %15
  %46 = load i64, ptr %6, align 8, !tbaa !9
  %47 = add i64 %46, 1
  store i64 %47, ptr %6, align 8, !tbaa !9
  store i64 %46, ptr %7, align 8, !tbaa !9
  br label %10, !llvm.loop !17

48:                                               ; preds = %14
  %49 = load i64, ptr %5, align 8, !tbaa !11
  %50 = sdiv i64 %49, 2
  store i64 %50, ptr %5, align 8, !tbaa !11
  %51 = load i64, ptr %5, align 8, !tbaa !11
  %52 = icmp sgt i64 %51, 0
  br i1 %52, label %53, label %55

53:                                               ; preds = %48
  %54 = load i64, ptr %5, align 8, !tbaa !11
  br label %58

55:                                               ; preds = %48
  %56 = load i64, ptr %5, align 8, !tbaa !11
  %57 = sub nsw i64 0, %56
  br label %58

58:                                               ; preds = %55, %53
  %59 = phi i64 [ %54, %53 ], [ %57, %55 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i64 %59
}

; 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 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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTS5Point", !15, i64 0, !15, i64 4}
!15 = !{!"int", !7, i64 0}
!16 = !{!14, !15, i64 4}
!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"

%struct.Point = type { i32, i32 }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef range(i64 -4611686018427387904, 4611686018427387905) i64 @_Z21Polygon_calculateAreaP5Pointm(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %3 = getelementptr %struct.Point, ptr %0, i64 %1
  %.phi.trans.insert = getelementptr i8, ptr %3, i64 -8
  %.phi.trans.insert21 = getelementptr i8, ptr %3, i64 -4
  %.pre = load i32, ptr %.phi.trans.insert21, align 4, !tbaa !5
  %.pre22 = load i32, ptr %.phi.trans.insert, align 4, !tbaa !10
  %xtraiter = and i64 %1, 1
  %4 = icmp eq i64 %1, 1
  br i1 %4, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %1, -2
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi i64 [ poison, %.lr.ph.preheader ], [ %45, %.lr.ph ]
  %.unr = phi i32 [ %.pre22, %.lr.ph.preheader ], [ %34, %.lr.ph ]
  %.unr23 = phi i32 [ %.pre, %.lr.ph.preheader ], [ %40, %.lr.ph ]
  %.01619.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %46, %.lr.ph ]
  %.01718.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %45, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %5 = getelementptr inbounds %struct.Point, ptr %0, i64 %.01619.unr
  %6 = load i32, ptr %5, align 4, !tbaa !10
  %7 = sext i32 %6 to i64
  %8 = sext i32 %.unr23 to i64
  %9 = mul nsw i64 %8, %7
  %10 = sext i32 %.unr to i64
  %11 = getelementptr inbounds i8, ptr %5, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = mul nsw i64 %13, %10
  %15 = add i64 %9, %.01718.unr
  %16 = sub i64 %15, %14
  br label %._crit_edge.loopexit

._crit_edge.loopexit:                             ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.lcssa = phi i64 [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %16, %.lr.ph.epil ]
  %17 = sdiv i64 %.lcssa, 2
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %.017.lcssa = phi i64 [ 0, %2 ], [ %17, %._crit_edge.loopexit ]
  %18 = tail call i64 @llvm.abs.i64(i64 %.017.lcssa, i1 true)
  ret i64 %18

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %19 = phi i32 [ %.pre22, %.lr.ph.preheader.new ], [ %34, %.lr.ph ]
  %20 = phi i32 [ %.pre, %.lr.ph.preheader.new ], [ %40, %.lr.ph ]
  %.01619 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %46, %.lr.ph ]
  %.01718 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %45, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %21 = getelementptr inbounds %struct.Point, ptr %0, i64 %.01619
  %22 = load i32, ptr %21, align 4, !tbaa !10
  %23 = sext i32 %22 to i64
  %24 = sext i32 %20 to i64
  %25 = mul nsw i64 %24, %23
  %26 = sext i32 %19 to i64
  %27 = getelementptr inbounds i8, ptr %21, i64 4
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = mul nsw i64 %29, %26
  %31 = add i64 %25, %.01718
  %32 = or disjoint i64 %.01619, 1
  %33 = getelementptr inbounds %struct.Point, ptr %0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !10
  %35 = sext i32 %34 to i64
  %36 = sext i32 %28 to i64
  %37 = mul nsw i64 %36, %35
  %38 = sext i32 %22 to i64
  %39 = getelementptr inbounds i8, ptr %33, i64 4
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = mul nsw i64 %41, %38
  %43 = add i64 %31, %37
  %44 = add i64 %30, %42
  %45 = sub i64 %43, %44
  %46 = add nuw i64 %.01619, 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 %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !11
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.abs.i64(i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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 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, !7, i64 4}
!6 = !{!"_ZTS5Point", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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