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

; 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.vrArray = type { ptr, i32, i32, i32, i32 }

; Function Attrs: nounwind
declare void @free(ptr noundef) #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: nounwind uwtable
define dso_local i32 @vrArrayErase(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.vrArray, ptr %10, i32 0, i32 3
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = icmp sgt i32 %9, %12
  br i1 %13, label %17, label %14

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

17:                                               ; preds = %14, %2
  store i32 -1, ptr %3, align 4
  br label %77

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.vrArray, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !13
  %22 = sext i32 %21 to i64
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.vrArray, ptr %23, i32 0, i32 3
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = sub nsw i32 %25, 1
  %27 = sext i32 %26 to i64
  %28 = call noalias ptr @calloc(i64 noundef %22, i64 noundef %27) #5
  store ptr %28, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %55, %18
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.vrArray, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !14
  %34 = icmp slt i32 %30, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %58

36:                                               ; preds = %29
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = icmp ne i32 %37, %38
  br i1 %39, label %40, label %54

40:                                               ; preds = %36
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.vrArray, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds ptr, ptr %43, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds ptr, ptr %48, i64 %50
  store ptr %47, ptr %51, align 8, !tbaa !5
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %7, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %40, %36
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %8, align 4, !tbaa !9
  br label %29, !llvm.loop !16

58:                                               ; preds = %35
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.vrArray, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !15
  call void @free(ptr noundef %61) #4
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.vrArray, ptr %62, i32 0, i32 0
  store ptr null, ptr %63, align 8, !tbaa !15
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.vrArray, ptr %65, i32 0, i32 0
  store ptr %64, ptr %66, align 8, !tbaa !15
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.vrArray, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %68, align 8, !tbaa !14
  %70 = add nsw i32 %69, -1
  store i32 %70, ptr %68, align 8, !tbaa !14
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.vrArray, ptr %71, i32 0, i32 3
  %73 = load i32, ptr %72, align 8, !tbaa !11
  %74 = add nsw i32 %73, -1
  store i32 %74, ptr %72, align 8, !tbaa !11
  %75 = load i32, ptr %5, align 4, !tbaa !9
  %76 = sub nsw i32 %75, 1
  store i32 %76, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %77

77:                                               ; preds = %58, %17
  %78 = load i32, ptr %3, align 4
  ret i32 %78
}

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

attributes #0 = { nounwind "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 = { 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 #3 = { nounwind allocsize(0,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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0,1) }

!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 = !{!12, !10, i64 16}
!12 = !{!"vrArray", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!13 = !{!12, !10, i64 12}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2147483647) i32 @vrArrayErase(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp slt i32 %4, %1
  %6 = icmp slt i32 %1, 0
  %or.cond = or i1 %6, %5
  br i1 %or.cond, label %46, label %7

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %10 = sext i32 %9 to i64
  %11 = add nsw i32 %4, -1
  %12 = sext i32 %11 to i64
  %13 = tail call noalias ptr @calloc(i64 noundef %10, i64 noundef %12) #3
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load i32, ptr %14, align 8, !tbaa !12
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %7
  %17 = zext nneg i32 %1 to i64
  %wide.trip.count = zext nneg i32 %15 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %18 = icmp eq i32 %15, 1
  br i1 %18, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa.loopexit:          ; preds = %45
  %19 = sext i32 %.1.1 to i64
  br label %._crit_edge.loopexit.unr-lcssa

._crit_edge.loopexit.unr-lcssa:                   ; preds = %._crit_edge.loopexit.unr-lcssa.loopexit, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.02327.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %19, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  %.not.epil = icmp eq i64 %indvars.iv.unr, %17
  %or.cond30 = select i1 %lcmp.mod.not, i1 true, i1 %.not.epil
  br i1 %or.cond30, label %._crit_edge, label %20

20:                                               ; preds = %._crit_edge.loopexit.unr-lcssa
  %21 = load ptr, ptr %0, align 8, !tbaa !13
  %22 = getelementptr inbounds ptr, ptr %21, i64 %indvars.iv.unr
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = getelementptr inbounds ptr, ptr %13, i64 %.02327.unr
  store ptr %23, ptr %24, align 8, !tbaa !14
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %20, %7
  %25 = load ptr, ptr %0, align 8, !tbaa !13
  tail call void @free(ptr noundef %25) #4
  store ptr %13, ptr %0, align 8, !tbaa !13
  %26 = load i32, ptr %14, align 8, !tbaa !12
  %27 = add nsw i32 %26, -1
  store i32 %27, ptr %14, align 8, !tbaa !12
  %28 = load i32, ptr %3, align 8, !tbaa !5
  %29 = add nsw i32 %28, -1
  store i32 %29, ptr %3, align 8, !tbaa !5
  %30 = add nsw i32 %1, -1
  br label %46

.lr.ph:                                           ; preds = %45, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %45 ]
  %.02327 = phi i32 [ 0, %.lr.ph.preheader.new ], [ %.1.1, %45 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %45 ]
  %.not = icmp eq i64 %indvars.iv, %17
  br i1 %.not, label %.lr.ph.1, label %31

31:                                               ; preds = %.lr.ph
  %32 = load ptr, ptr %0, align 8, !tbaa !13
  %33 = getelementptr inbounds ptr, ptr %32, i64 %indvars.iv
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = sext i32 %.02327 to i64
  %36 = getelementptr inbounds ptr, ptr %13, i64 %35
  store ptr %34, ptr %36, align 8, !tbaa !14
  %37 = add nsw i32 %.02327, 1
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph, %31
  %.1 = phi i32 [ %37, %31 ], [ %.02327, %.lr.ph ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %.not.1 = icmp eq i64 %indvars.iv.next, %17
  br i1 %.not.1, label %45, label %38

38:                                               ; preds = %.lr.ph.1
  %39 = load ptr, ptr %0, align 8, !tbaa !13
  %40 = getelementptr inbounds ptr, ptr %39, i64 %indvars.iv.next
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = sext i32 %.1 to i64
  %43 = getelementptr inbounds ptr, ptr %13, i64 %42
  store ptr %41, ptr %43, align 8, !tbaa !14
  %44 = add nsw i32 %.1, 1
  br label %45

45:                                               ; preds = %38, %.lr.ph.1
  %.1.1 = phi i32 [ %44, %38 ], [ %.1, %.lr.ph.1 ]
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa.loopexit, label %.lr.ph, !llvm.loop !15

46:                                               ; preds = %2, %._crit_edge
  %.024 = phi i32 [ %30, %._crit_edge ], [ -1, %2 ]
  ret i32 %.024
}

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

attributes #0 = { mustprogress nounwind willreturn allockind("free") 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 #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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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(0,1) }
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, !10, i64 16}
!6 = !{!"vrArray", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 12}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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