; LLVM IR from ashishzero/karma :: src/modules/core/lin_maths.ll (Z17is_polygon_convexPK4Vec2j)

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

%union.Vec2 = type { %struct.anon.1 }
%struct.anon.1 = type { float, float }

; 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) #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
declare dso_local noundef zeroext i1 @_Z14triangle_is_cw4Vec2S_S_(<2 x float>, <2 x float>, <2 x float>) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z17is_polygon_convexPK4Vec2j(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %union.Vec2, align 4
  %7 = alloca %union.Vec2, align 4
  %8 = alloca %union.Vec2, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca %union.Vec2, align 4
  %12 = alloca %union.Vec2, align 4
  %13 = alloca %union.Vec2, 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 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %14

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

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

19:                                               ; preds = %14
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds %union.Vec2, ptr %20, i64 %22
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %23, i64 8, i1 false), !tbaa.struct !11
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = add i32 %25, 1
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = urem i32 %26, %27
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds %union.Vec2, ptr %24, i64 %29
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %30, i64 8, i1 false), !tbaa.struct !11
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = add i32 %32, 2
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = urem i32 %33, %34
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds %union.Vec2, ptr %31, i64 %36
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %37, i64 8, i1 false), !tbaa.struct !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %7, i64 8, i1 false), !tbaa.struct !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %8, i64 8, i1 false), !tbaa.struct !11
  %38 = getelementptr inbounds %union.Vec2, ptr %11, i32 0, i32 0
  %39 = load <2 x float>, ptr %38, align 4
  %40 = getelementptr inbounds %union.Vec2, ptr %12, i32 0, i32 0
  %41 = load <2 x float>, ptr %40, align 4
  %42 = getelementptr inbounds %union.Vec2, ptr %13, i32 0, i32 0
  %43 = load <2 x float>, ptr %42, align 4
  %44 = call noundef zeroext i1 @_Z14triangle_is_cw4Vec2S_S_(<2 x float> %39, <2 x float> %41, <2 x float> %43)
  br i1 %44, label %46, label %45

45:                                               ; preds = %19
  store i1 false, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %50

46:                                               ; preds = %19
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = add i32 %48, 1
  store i32 %49, ptr %9, align 4, !tbaa !9
  br label %14, !llvm.loop !13

50:                                               ; preds = %45, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %51 = load i32, ptr %10, align 4
  switch i32 %51, label %53 [
    i32 2, label %52
  ]

52:                                               ; preds = %50
  store i1 true, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %53

53:                                               ; preds = %52, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %54 = load i1, ptr %3, align 1
  ret i1 %54
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 8, !12}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%union.Vec2 = type { %struct.anon.1 }
%struct.anon.1 = type { float, float }

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z14triangle_is_cw4Vec2S_S_(<2 x float>, <2 x float>, <2 x float>) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z17is_polygon_convexPK4Vec2j(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = zext i32 %1 to i64
  br label %4

4:                                                ; preds = %5, %2
  %indvars.iv = phi i64 [ %indvars.iv.next, %5 ], [ 0, %2 ]
  %exitcond = icmp eq i64 %indvars.iv, %3
  br i1 %exitcond, label %.critedge, label %5

5:                                                ; preds = %4
  %6 = getelementptr inbounds %union.Vec2, ptr %0, i64 %indvars.iv
  %.sroa.010.0.copyload = load <2 x float>, ptr %6, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = icmp eq i64 %indvars.iv.next, %3
  %8 = and i64 %indvars.iv.next, 4294967295
  %9 = select i1 %7, i64 0, i64 %8
  %10 = getelementptr inbounds %union.Vec2, ptr %0, i64 %9
  %.sroa.09.0.copyload = load <2 x float>, ptr %10, align 4, !tbaa !5
  %11 = trunc nuw i64 %indvars.iv to i32
  %12 = add i32 %11, 2
  %13 = urem i32 %12, %1
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds %union.Vec2, ptr %0, i64 %14
  %.sroa.08.0.copyload = load <2 x float>, ptr %15, align 4, !tbaa !5
  %16 = tail call noundef zeroext i1 @_Z14triangle_is_cw4Vec2S_S_(<2 x float> %.sroa.010.0.copyload, <2 x float> %.sroa.09.0.copyload, <2 x float> %.sroa.08.0.copyload)
  br i1 %16, label %4, label %.critedge, !llvm.loop !8

.critedge:                                        ; preds = %4, %5
  %.not = icmp uge i64 %indvars.iv, %3
  ret i1 %.not
}

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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