; LLVM IR from jdeokkim/ferox :: src (geometry)

; 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.frVector2_ = type { float, float }
%struct.frShape_ = type { i32, %union.frShapeData_, %struct.frMaterial_, float }
%union.frShapeData_ = type { %struct.anon.0 }
%struct.anon.0 = type { %struct.frVertices_, %struct.frVertices_ }
%struct.frVertices_ = type { [8 x %struct.frVector2_], i32 }
%struct.frMaterial_ = type { float, 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: nounwind uwtable
declare dso_local i32 @frGetShapeType(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local <2 x float> @frGetPolygonNormal(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca %struct.frVector2_, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = call i32 @frGetShapeType(ptr noundef %6)
  %8 = icmp ne i32 %7, 2
  br i1 %8, label %20, label %9

9:                                                ; preds = %2
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = icmp slt i32 %10, 0
  br i1 %11, label %20, label %12

12:                                               ; preds = %9
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.frShape_, ptr %14, i32 0, i32 1
  %16 = getelementptr inbounds %struct.anon.0, ptr %15, i32 0, i32 1
  %17 = getelementptr inbounds %struct.frVertices_, ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = icmp sge i32 %13, %18
  br i1 %19, label %20, label %23

20:                                               ; preds = %12, %9, %2
  %21 = getelementptr inbounds %struct.frVector2_, ptr %3, i32 0, i32 0
  store float 0.000000e+00, ptr %21, align 4, !tbaa !12
  %22 = getelementptr inbounds %struct.frVector2_, ptr %3, i32 0, i32 1
  store float 0.000000e+00, ptr %22, align 4, !tbaa !15
  br label %31

23:                                               ; preds = %12
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.frShape_, ptr %24, i32 0, i32 1
  %26 = getelementptr inbounds %struct.anon.0, ptr %25, i32 0, i32 1
  %27 = getelementptr inbounds %struct.frVertices_, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [8 x %struct.frVector2_], ptr %27, i64 0, i64 %29
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 %30, i64 8, i1 false), !tbaa.struct !16
  br label %31

31:                                               ; preds = %23, %20
  %32 = load <2 x float>, ptr %3, align 4
  ret <2 x float> %32
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nounwind 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"frVector2_", !14, i64 0, !14, i64 4}
!14 = !{!"float", !7, i64 0}
!15 = !{!13, !14, i64 4}
!16 = !{i64 0, i64 4, !17, i64 4, i64 4, !17}
!17 = !{!14, !14, i64 0}


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

; Function Attrs: nounwind uwtable
declare dso_local i32 @frGetShapeType(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local <2 x float> @frGetPolygonNormal(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = tail call i32 @frGetShapeType(ptr noundef %0)
  %4 = icmp ne i32 %3, 2
  %5 = icmp slt i32 %1, 0
  %or.cond = or i1 %5, %4
  br i1 %or.cond, label %13, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 136
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not = icmp sgt i32 %8, %1
  br i1 %.not, label %9, label %13

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 72
  %11 = zext nneg i32 %1 to i64
  %12 = getelementptr inbounds [8 x %struct.frVector2_], ptr %10, i64 0, i64 %11
  %.sroa.0.0.copyload = load <2 x float>, ptr %12, align 4
  br label %13

13:                                               ; preds = %2, %6, %9
  %.sroa.0.0 = phi <2 x float> [ %.sroa.0.0.copyload, %9 ], [ zeroinitializer, %6 ], [ zeroinitializer, %2 ]
  ret <2 x float> %.sroa.0.0
}

attributes #0 = { 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 = { nounwind 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/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass