; LLVM IR from Mithreindeir/VelocityRaptor :: VelocityRaptor/src (vrShapeCreate)

; 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.vrVec2 = type { float, float }
%struct.vrShapeMold = type { i32, %struct.vrVec2, %union.anon }
%union.anon = type { %struct.vrPolygonMold }
%struct.vrPolygonMold = type { ptr, i32, i32 }

@currentMold = external hidden global ptr, align 8

; 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
define dso_local void @vrAddVertex(<2 x float> %0) #1 {
  %2 = alloca %struct.vrVec2, align 4
  store <2 x float> %0, ptr %2, align 4
  %3 = load ptr, ptr @currentMold, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.vrShapeMold, ptr %3, i32 0, i32 2
  %5 = getelementptr inbounds %struct.vrPolygonMold, ptr %4, i32 0, i32 1
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr %5, align 8, !tbaa !9
  %8 = load ptr, ptr @currentMold, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.vrShapeMold, ptr %8, i32 0, i32 2
  %10 = getelementptr inbounds %struct.vrPolygonMold, ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = icmp sgt i32 %11, 1
  br i1 %12, label %13, label %28

13:                                               ; preds = %1
  %14 = load ptr, ptr @currentMold, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.vrShapeMold, ptr %14, i32 0, i32 2
  %16 = getelementptr inbounds %struct.vrPolygonMold, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = load ptr, ptr @currentMold, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.vrShapeMold, ptr %18, i32 0, i32 2
  %20 = getelementptr inbounds %struct.vrPolygonMold, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = mul i64 %22, 8
  %24 = call ptr @realloc(ptr noundef %17, i64 noundef %23) #4
  %25 = load ptr, ptr @currentMold, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.vrShapeMold, ptr %25, i32 0, i32 2
  %27 = getelementptr inbounds %struct.vrPolygonMold, ptr %26, i32 0, i32 0
  store ptr %24, ptr %27, align 8, !tbaa !9
  br label %33

28:                                               ; preds = %1
  %29 = call noalias ptr @malloc(i64 noundef 8) #5
  %30 = load ptr, ptr @currentMold, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.vrShapeMold, ptr %30, i32 0, i32 2
  %32 = getelementptr inbounds %struct.vrPolygonMold, ptr %31, i32 0, i32 0
  store ptr %29, ptr %32, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %28, %13
  %34 = load ptr, ptr @currentMold, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.vrShapeMold, ptr %34, i32 0, i32 2
  %36 = getelementptr inbounds %struct.vrPolygonMold, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !9
  %38 = load ptr, ptr @currentMold, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.vrShapeMold, ptr %38, i32 0, i32 2
  %40 = getelementptr inbounds %struct.vrPolygonMold, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 8, !tbaa !9
  %42 = sub nsw i32 %41, 1
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds %struct.vrVec2, ptr %37, i64 %43
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %44, ptr align 4 %2, i64 8, i1 false), !tbaa.struct !10
  ret void
}

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { nounwind allocsize(1) "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 allocsize(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 #4 = { nounwind allocsize(1) }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!7, !7, i64 0}
!10 = !{i64 0, i64 4, !11, i64 4, i64 4, !11}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, 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.vrVec2 = type { float, float }

@currentMold = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nounwind willreturn uwtable
define dso_local void @vrAddVertex(<2 x float> %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @currentMold, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 24
  %4 = load i32, ptr %3, align 8, !tbaa !9
  %5 = add nsw i32 %4, 1
  store i32 %5, ptr %3, align 8, !tbaa !9
  %6 = icmp sgt i32 %4, 0
  br i1 %6, label %7, label %15

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %2, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = zext nneg i32 %5 to i64
  %11 = shl nuw nsw i64 %10, 3
  %12 = tail call ptr @realloc(ptr noundef %9, i64 noundef %11) #3
  %13 = load ptr, ptr @currentMold, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  store ptr %12, ptr %14, align 8, !tbaa !9
  %.phi.trans.insert = getelementptr inbounds i8, ptr %13, i64 24
  %.pre = load i32, ptr %.phi.trans.insert, align 8, !tbaa !9
  br label %18

15:                                               ; preds = %1
  %16 = tail call noalias dereferenceable_or_null(8) ptr @malloc(i64 noundef 8) #4
  %17 = getelementptr inbounds i8, ptr %2, i64 16
  store ptr %16, ptr %17, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %15, %7
  %19 = phi i32 [ %5, %15 ], [ %.pre, %7 ]
  %20 = phi ptr [ %16, %15 ], [ %12, %7 ]
  %21 = sext i32 %19 to i64
  %22 = getelementptr %struct.vrVec2, ptr %20, i64 %21
  %23 = getelementptr i8, ptr %22, i64 -8
  store <2 x float> %0, ptr %23, align 4
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nounwind willreturn 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 nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(1) }
attributes #4 = { nounwind allocsize(0) }

!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 = !{!7, !7, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass