; LLVM IR from gabekz/GoodsackEngine :: goodsack/gsk/gsk/asset/gpak (gpak)

; 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.gsk_GPakContainer = type { ptr, i64 }
%struct.gsk_GPakAssetRef = type { i64, i8, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local { ptr, i64 } @gsk_gpak_init(i64 noundef %0) #0 {
  %2 = alloca %struct.gsk_GPakContainer, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  %5 = load i64, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.gsk_GPakContainer, ptr %2, i32 0, i32 1
  store i64 %5, ptr %6, align 8, !tbaa !9
  %7 = getelementptr inbounds %struct.gsk_GPakContainer, ptr %2, i32 0, i32 1
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = mul i64 32, %8
  %10 = call noalias ptr @malloc(i64 noundef %9) #3
  %11 = getelementptr inbounds %struct.gsk_GPakContainer, ptr %2, i32 0, i32 0
  store ptr %10, ptr %11, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %29, %1
  %13 = load i64, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.gsk_GPakContainer, ptr %2, i32 0, i32 1
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = icmp ult i64 %13, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %32

18:                                               ; preds = %12
  %19 = getelementptr inbounds %struct.gsk_GPakContainer, ptr %2, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %20, i64 %21
  %23 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %22, i32 0, i32 0
  store i64 0, ptr %23, align 8, !tbaa !13
  %24 = getelementptr inbounds %struct.gsk_GPakContainer, ptr %2, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = load i64, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %25, i64 %26
  %28 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %27, i32 0, i32 3
  store ptr null, ptr %28, align 8, !tbaa !15
  br label %29

29:                                               ; preds = %18
  %30 = load i64, ptr %4, align 8, !tbaa !5
  %31 = add i64 %30, 1
  store i64 %31, ptr %4, align 8, !tbaa !5
  br label %12, !llvm.loop !16

32:                                               ; preds = %17
  %33 = load { ptr, i64 }, ptr %2, align 8
  ret { ptr, i64 } %33
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

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 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind allocsize(0) }
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, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"gsk_GPakContainer", !11, i64 0, !6, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"gsk_GPakAssetRef", !6, i64 0, !7, i64 8, !11, i64 16, !11, i64 24}
!15 = !{!14, !11, i64 24}
!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"

%struct.gsk_GPakAssetRef = type { i64, i8, ptr, ptr }

; Function Attrs: nofree nounwind memory(write, argmem: none, inaccessiblemem: readwrite) uwtable
define dso_local { ptr, i64 } @gsk_gpak_init(i64 noundef %0) local_unnamed_addr #0 {
  %2 = shl i64 %0, 5
  %3 = tail call noalias ptr @malloc(i64 noundef %2) #2
  %.not = icmp eq i64 %0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %xtraiter = and i64 %0, 3
  %4 = icmp ult i64 %0, 4
  br i1 %4, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %0, -4
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.09.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %19, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.09.epil = phi i64 [ %7, %.lr.ph.epil ], [ %.09.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %5 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %3, i64 %.09.epil
  store i64 0, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 24
  store ptr null, ptr %6, align 8, !tbaa !11
  %7 = add nuw i64 %.09.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !12

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %1
  %.fca.0.insert = insertvalue { ptr, i64 } poison, ptr %3, 0
  %.fca.1.insert = insertvalue { ptr, i64 } %.fca.0.insert, i64 %0, 1
  ret { ptr, i64 } %.fca.1.insert

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.09 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %19, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %8 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %3, i64 %.09
  store i64 0, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 24
  store ptr null, ptr %9, align 8, !tbaa !11
  %10 = or disjoint i64 %.09, 1
  %11 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %3, i64 %10
  store i64 0, ptr %11, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 24
  store ptr null, ptr %12, align 8, !tbaa !11
  %13 = or disjoint i64 %.09, 2
  %14 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %3, i64 %13
  store i64 0, ptr %14, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 24
  store ptr null, ptr %15, align 8, !tbaa !11
  %16 = or disjoint i64 %.09, 3
  %17 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %3, i64 %16
  store i64 0, ptr %17, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 24
  store ptr null, ptr %18, align 8, !tbaa !11
  %19 = add nuw i64 %.09, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !14
}

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

attributes #0 = { nofree nounwind memory(write, argmem: none, inaccessiblemem: readwrite) 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 = { 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 #2 = { 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, !7, i64 0}
!6 = !{!"gsk_GPakAssetRef", !7, i64 0, !8, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 24}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.unroll.disable"}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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