; LLVM IR from gzc/CLRS :: C33-Computational-Geometry/exercise_code/convex_polygon.ll (Z15isConvexPolygonP5Pointi)

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_Z9directionRK5PointS1_S1_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #0

; 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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z15isConvexPolygonP5Pointi(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %class.Point, align 4
  %11 = alloca %class.Point, align 4
  %12 = alloca %class.Point, align 4
  %13 = alloca float, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  store i8 0, ptr %7, align 1, !tbaa !11
  store i8 0, ptr %6, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %64, %2
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 2, ptr %9, align 4
  br label %67

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds %class.Point, ptr %20, i64 %22
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %23, i64 8, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = srem i32 %26, %27
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds %class.Point, ptr %24, i64 %29
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %30, i64 8, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = add nsw i32 %32, 2
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = srem i32 %33, %34
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %class.Point, ptr %31, i64 %36
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %37, i64 8, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %38 = call noundef float @_Z9directionRK5PointS1_S1_(ptr noundef nonnull align 4 dereferenceable(8) %11, ptr noundef nonnull align 4 dereferenceable(8) %10, ptr noundef nonnull align 4 dereferenceable(8) %12)
  store float %38, ptr %13, align 4, !tbaa !14
  %39 = load float, ptr %13, align 4, !tbaa !14
  %40 = fcmp ogt float %39, 0.000000e+00
  br i1 %40, label %41, label %45

41:                                               ; preds = %19
  %42 = load i8, ptr %7, align 1, !tbaa !11, !range !16, !noundef !17
  %43 = trunc i8 %42 to i1
  br i1 %43, label %44, label %45

44:                                               ; preds = %41
  store i1 false, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %61

45:                                               ; preds = %41, %19
  %46 = load float, ptr %13, align 4, !tbaa !14
  %47 = fcmp olt float %46, 0.000000e+00
  br i1 %47, label %48, label %52

48:                                               ; preds = %45
  %49 = load i8, ptr %6, align 1, !tbaa !11, !range !16, !noundef !17
  %50 = trunc i8 %49 to i1
  br i1 %50, label %51, label %52

51:                                               ; preds = %48
  store i1 false, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %61

52:                                               ; preds = %48, %45
  %53 = load float, ptr %13, align 4, !tbaa !14
  %54 = fcmp ogt float %53, 0.000000e+00
  br i1 %54, label %55, label %56

55:                                               ; preds = %52
  store i8 1, ptr %6, align 1, !tbaa !11
  br label %56

56:                                               ; preds = %55, %52
  %57 = load float, ptr %13, align 4, !tbaa !14
  %58 = fcmp olt float %57, 0.000000e+00
  br i1 %58, label %59, label %60

59:                                               ; preds = %56
  store i8 1, ptr %7, align 1, !tbaa !11
  br label %60

60:                                               ; preds = %59, %56
  store i32 0, ptr %9, align 4
  br label %61

61:                                               ; preds = %60, %51, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %62 = load i32, ptr %9, align 4
  switch i32 %62, label %67 [
    i32 0, label %63
  ]

63:                                               ; preds = %61
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %8, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %8, align 4, !tbaa !9
  br label %14, !llvm.loop !18

67:                                               ; preds = %61, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %68 = load i32, ptr %9, align 4
  switch i32 %68, label %77 [
    i32 2, label %69
  ]

69:                                               ; preds = %67
  %70 = load i8, ptr %6, align 1, !tbaa !11, !range !16, !noundef !17
  %71 = trunc i8 %70 to i1
  br i1 %71, label %76, label %72

72:                                               ; preds = %69
  %73 = load i8, ptr %7, align 1, !tbaa !11, !range !16, !noundef !17
  %74 = trunc i8 %73 to i1
  br i1 %74, label %76, label %75

75:                                               ; preds = %72
  store i1 false, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %77

76:                                               ; preds = %72, %69
  store i1 true, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %77

77:                                               ; preds = %76, %75, %67
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #4
  %78 = load i1, ptr %3, align 1
  ret i1 %78
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i64 0, i64 4, !14, i64 4, i64 4, !14}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !19}
!19 = !{!"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.Point = type { float, float }

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_Z9directionRK5PointS1_S1_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z15isConvexPolygonP5Pointi(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #2 {
  %3 = alloca %class.Point, align 8
  %4 = alloca %class.Point, align 8
  %5 = alloca %class.Point, align 8
  %.not40 = icmp sgt i32 %1, 0
  br i1 %.not40, label %.lr.ph.preheader, label %.thread

.lr.ph.preheader:                                 ; preds = %2
  %6 = zext nneg i32 %1 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %28
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %28 ]
  %.02542 = phi i8 [ 0, %.lr.ph.preheader ], [ %.126, %28 ]
  %.02941 = phi i8 [ 0, %.lr.ph.preheader ], [ %.130, %28 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %7 = getelementptr inbounds %class.Point, ptr %0, i64 %indvars.iv
  %8 = load i64, ptr %7, align 4
  store i64 %8, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %9 = icmp eq i64 %indvars.iv.next, %6
  %10 = and i64 %indvars.iv.next, 4294967295
  %11 = select i1 %9, i64 0, i64 %10
  %12 = getelementptr inbounds %class.Point, ptr %0, i64 %11
  %13 = load i64, ptr %12, align 4
  store i64 %13, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %14 = trunc i64 %indvars.iv to i32
  %15 = add i32 %14, 2
  %16 = urem i32 %15, %1
  %17 = zext nneg i32 %16 to i64
  %18 = getelementptr inbounds %class.Point, ptr %0, i64 %17
  %19 = load i64, ptr %18, align 4
  store i64 %19, ptr %5, align 8
  %20 = call noundef float @_Z9directionRK5PointS1_S1_(ptr noundef nonnull align 4 dereferenceable(8) %4, ptr noundef nonnull align 4 dereferenceable(8) %3, ptr noundef nonnull align 4 dereferenceable(8) %5)
  %21 = fcmp ogt float %20, 0.000000e+00
  br i1 %21, label %22, label %24

22:                                               ; preds = %.lr.ph
  %23 = trunc nuw i8 %.02542 to i1
  br i1 %23, label %.thread37, label %24

24:                                               ; preds = %22, %.lr.ph
  %25 = fcmp olt float %20, 0.000000e+00
  br i1 %25, label %26, label %28

26:                                               ; preds = %24
  %27 = trunc nuw i8 %.02941 to i1
  br i1 %27, label %.thread37, label %28

.thread37:                                        ; preds = %26, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %.thread

28:                                               ; preds = %24, %26
  %.126 = phi i8 [ %.02542, %24 ], [ 1, %26 ]
  %.130 = select i1 %21, i8 1, i8 %.02941
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  %exitcond.not = icmp eq i64 %indvars.iv.next, %6
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %28
  %29 = trunc nuw i8 %.130 to i1
  %30 = trunc nuw i8 %.126 to i1
  %brmerge = select i1 %29, i1 true, i1 %30
  br label %.thread

.thread:                                          ; preds = %._crit_edge, %2, %.thread37
  %.3 = phi i1 [ false, %.thread37 ], [ false, %2 ], [ %brmerge, %._crit_edge ]
  ret i1 %.3
}

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="64" "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 willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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