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

; 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 @_Z32test_point_inside_convex_polygon4Vec2PS_i(<2 x float> %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca i1, align 1
  %5 = alloca %union.Vec2, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, 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
  %14 = alloca i32, align 4
  %15 = alloca %union.Vec2, align 4
  %16 = alloca %union.Vec2, align 4
  %17 = alloca %union.Vec2, align 4
  %18 = getelementptr inbounds %union.Vec2, ptr %5, i32 0, i32 0
  store <2 x float> %0, ptr %18, align 4
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %19 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %19, ptr %9, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %43, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = add nsw i32 %21, %22
  %24 = sdiv i32 %23, 2
  store i32 %24, ptr %10, align 4, !tbaa !9
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %union.Vec2, ptr %25, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %26, i64 8, i1 false), !tbaa.struct !11
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds %union.Vec2, ptr %27, i64 %29
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %30, i64 8, i1 false), !tbaa.struct !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %5, i64 8, i1 false), !tbaa.struct !11
  %31 = getelementptr inbounds %union.Vec2, ptr %11, i32 0, i32 0
  %32 = load <2 x float>, ptr %31, align 4
  %33 = getelementptr inbounds %union.Vec2, ptr %12, i32 0, i32 0
  %34 = load <2 x float>, ptr %33, align 4
  %35 = getelementptr inbounds %union.Vec2, ptr %13, i32 0, i32 0
  %36 = load <2 x float>, ptr %35, align 4
  %37 = call noundef zeroext i1 @_Z14triangle_is_cw4Vec2S_S_(<2 x float> %32, <2 x float> %34, <2 x float> %36)
  br i1 %37, label %38, label %40

38:                                               ; preds = %20
  %39 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %39, ptr %8, align 4, !tbaa !9
  br label %42

40:                                               ; preds = %20
  %41 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %41, ptr %9, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %40, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = add nsw i32 %44, 1
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = icmp slt i32 %45, %46
  br i1 %47, label %20, label %48, !llvm.loop !13

48:                                               ; preds = %43
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %55, label %51

51:                                               ; preds = %48
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = icmp eq i32 %52, %53
  br i1 %54, label %55, label %56

55:                                               ; preds = %51, %48
  store i1 false, ptr %4, align 1
  store i32 1, ptr %14, align 4
  br label %72

56:                                               ; preds = %51
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds %union.Vec2, ptr %57, i64 %59
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %15, ptr align 4 %60, i64 8, i1 false), !tbaa.struct !11
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load i32, ptr %9, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds %union.Vec2, ptr %61, i64 %63
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 4 %64, i64 8, i1 false), !tbaa.struct !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %17, ptr align 4 %5, i64 8, i1 false), !tbaa.struct !11
  %65 = getelementptr inbounds %union.Vec2, ptr %15, i32 0, i32 0
  %66 = load <2 x float>, ptr %65, align 4
  %67 = getelementptr inbounds %union.Vec2, ptr %16, i32 0, i32 0
  %68 = load <2 x float>, ptr %67, align 4
  %69 = getelementptr inbounds %union.Vec2, ptr %17, i32 0, i32 0
  %70 = load <2 x float>, ptr %69, align 4
  %71 = call noundef zeroext i1 @_Z14triangle_is_cw4Vec2S_S_(<2 x float> %66, <2 x float> %68, <2 x float> %70)
  store i1 %71, ptr %4, align 1
  store i32 1, ptr %14, align 4
  br label %72

72:                                               ; preds = %56, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %73 = load i1, ptr %4, align 1
  ret i1 %73
}

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 @_Z32test_point_inside_convex_polygon4Vec2PS_i(<2 x float> %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  br label %4

4:                                                ; preds = %4, %3
  %.025 = phi i32 [ %2, %3 ], [ %.025., %4 ]
  %.024 = phi i32 [ 0, %3 ], [ %..024, %4 ]
  %5 = add nsw i32 %.024, %.025
  %6 = sdiv i32 %5, 2
  %.sroa.05.0.copyload = load <2 x float>, ptr %1, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds %union.Vec2, ptr %1, i64 %7
  %.sroa.04.0.copyload = load <2 x float>, ptr %8, align 4, !tbaa !5
  %9 = tail call noundef zeroext i1 @_Z14triangle_is_cw4Vec2S_S_(<2 x float> %.sroa.05.0.copyload, <2 x float> %.sroa.04.0.copyload, <2 x float> %0)
  %.025. = select i1 %9, i32 %.025, i32 %6
  %..024 = select i1 %9, i32 %6, i32 %.024
  %10 = add nsw i32 %..024, 1
  %11 = icmp slt i32 %10, %.025.
  br i1 %11, label %4, label %12, !llvm.loop !8

12:                                               ; preds = %4
  %13 = icmp eq i32 %..024, 0
  %14 = icmp eq i32 %.025., %2
  %or.cond = or i1 %13, %14
  br i1 %or.cond, label %21, label %15

15:                                               ; preds = %12
  %16 = sext i32 %..024 to i64
  %17 = getelementptr inbounds %union.Vec2, ptr %1, i64 %16
  %.sroa.02.0.copyload = load <2 x float>, ptr %17, align 4, !tbaa !5
  %18 = sext i32 %.025. to i64
  %19 = getelementptr inbounds %union.Vec2, ptr %1, i64 %18
  %.sroa.01.0.copyload = load <2 x float>, ptr %19, align 4, !tbaa !5
  %20 = tail call noundef zeroext i1 @_Z14triangle_is_cw4Vec2S_S_(<2 x float> %.sroa.02.0.copyload, <2 x float> %.sroa.01.0.copyload, <2 x float> %0)
  br label %21

21:                                               ; preds = %12, %15
  %.0 = phi i1 [ %20, %15 ], [ false, %12 ]
  ret i1 %.0
}

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: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass