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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 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 void @gsk_gpak_write(ptr noundef %0, ptr noundef %1, i64 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca %struct.gsk_GPakAssetRef, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call i64 @_hash_djb2(ptr noundef %14)
  store i64 %15, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %16 = load i64, ptr %7, align 8, !tbaa !9
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.gsk_GPakContainer, ptr %17, i32 0, i32 1
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = urem i64 %16, %19
  store i64 %20, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #6
  call void @llvm.memset.p0.i64(ptr align 8 %9, i8 0, i64 32, i1 false)
  %21 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %9, i32 0, i32 0
  %22 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %22, ptr %21, align 8, !tbaa !13
  %23 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %9, i32 0, i32 1
  %24 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %9, i32 0, i32 2
  %25 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %9, i32 0, i32 3
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call noalias ptr @strdup(ptr noundef %26) #6
  %28 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %9, i32 0, i32 2
  store ptr %27, ptr %28, align 8, !tbaa !15
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.gsk_GPakContainer, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  %32 = load i64, ptr %8, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %31, i64 %32
  %34 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %33, i32 0, i32 0
  %35 = load i64, ptr %34, align 8, !tbaa !13
  %36 = icmp ne i64 %35, 0
  br i1 %36, label %37, label %64

37:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.gsk_GPakContainer, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !16
  %41 = load i64, ptr %8, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %40, i64 %41
  store ptr %42, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  store ptr null, ptr %11, align 8, !tbaa !5
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.gsk_GPakContainer, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !16
  %46 = load i64, ptr %8, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %45, i64 %46
  %48 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  store ptr %49, ptr %11, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %53, %37
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %58

53:                                               ; preds = %50
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %54, ptr %10, align 8, !tbaa !5
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %55, i32 0, i32 3
  %57 = load ptr, ptr %56, align 8, !tbaa !17
  store ptr %57, ptr %11, align 8, !tbaa !5
  br label %50, !llvm.loop !18

58:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %59 = call noalias ptr @malloc(i64 noundef 32) #7
  store ptr %59, ptr %12, align 8, !tbaa !5
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %60, ptr align 8 %9, i64 32, i1 false), !tbaa.struct !20
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %62, i32 0, i32 3
  store ptr %61, ptr %63, align 8, !tbaa !17
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  br label %70

64:                                               ; preds = %3
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.gsk_GPakContainer, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !16
  %68 = load i64, ptr %8, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %67, i64 %68
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %69, ptr align 8 %9, i64 32, i1 false), !tbaa.struct !20
  store i32 0, ptr %13, align 4
  br label %70

70:                                               ; preds = %64, %58
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  %71 = load i32, ptr %13, align 4
  switch i32 %71, label %73 [
    i32 0, label %72
    i32 1, label %72
  ]

72:                                               ; preds = %70, %70
  ret void

73:                                               ; preds = %70
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden i64 @_hash_djb2(ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #4

; 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) #5

attributes #0 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nounwind }
attributes #7 = { 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"gsk_GPakContainer", !6, i64 0, !10, i64 8}
!13 = !{!14, !10, i64 0}
!14 = !{!"gsk_GPakAssetRef", !10, i64 0, !7, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!14, !6, i64 16}
!16 = !{!12, !6, i64 0}
!17 = !{!14, !6, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{i64 0, i64 8, !9, i64 8, i64 1, !21, i64 16, i64 8, !5, i64 24, i64 8, !5}
!21 = !{!7, !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.gsk_GPakAssetRef = type { i64, i8, ptr, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local void @gsk_gpak_write(ptr nocapture noundef readonly %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = tail call i64 @_hash_djb2(ptr noundef %1)
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = urem i64 %4, %6
  %8 = tail call noalias ptr @strdup(ptr noundef %1) #3
  %9 = load ptr, ptr %0, align 8, !tbaa !11
  %10 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %9, i64 %7
  %11 = load i64, ptr %10, align 8, !tbaa !12
  %.not = icmp eq i64 %11, 0
  br i1 %.not, label %14, label %.preheader

.preheader:                                       ; preds = %3, %.preheader
  %.025 = phi ptr [ %.0, %.preheader ], [ %10, %3 ]
  %.0.in = getelementptr inbounds i8, ptr %.025, i64 24
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !14
  %.not26 = icmp eq ptr %.0, null
  br i1 %.not26, label %12, label %.preheader, !llvm.loop !15

12:                                               ; preds = %.preheader
  %.0.in.le = getelementptr inbounds i8, ptr %.025, i64 24
  %13 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #4
  store i64 %2, ptr %13, align 8, !tbaa !17
  %.sroa.6.0..0..sroa_idx = getelementptr inbounds i8, ptr %13, i64 8
  store i64 0, ptr %.sroa.6.0..0..sroa_idx, align 8
  %.sroa.68.0..0..sroa_idx = getelementptr inbounds i8, ptr %13, i64 16
  store ptr %8, ptr %.sroa.68.0..0..sroa_idx, align 8, !tbaa !18
  %.sroa.7.0..0..sroa_idx = getelementptr inbounds i8, ptr %13, i64 24
  store ptr null, ptr %.sroa.7.0..0..sroa_idx, align 8, !tbaa !18
  store ptr %13, ptr %.0.in.le, align 8, !tbaa !14
  br label %15

14:                                               ; preds = %3
  store i64 %2, ptr %10, align 8, !tbaa !17
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %10, i64 8
  store i64 0, ptr %.sroa.6.0..sroa_idx, align 8
  %.sroa.68.0..sroa_idx = getelementptr inbounds i8, ptr %10, i64 16
  store ptr %8, ptr %.sroa.68.0..sroa_idx, align 8, !tbaa !18
  %.sroa.7.0..sroa_idx = getelementptr inbounds i8, ptr %10, i64 24
  store ptr null, ptr %.sroa.7.0..sroa_idx, align 8, !tbaa !18
  br label %15

15:                                               ; preds = %14, %12
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden i64 @_hash_djb2(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #2

attributes #0 = { 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 #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 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 #3 = { nounwind }
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, !10, i64 8}
!6 = !{!"gsk_GPakContainer", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!13, !10, i64 0}
!13 = !{!"gsk_GPakAssetRef", !10, i64 0, !8, i64 8, !7, i64 16, !7, i64 24}
!14 = !{!13, !7, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!10, !10, i64 0}
!18 = !{!7, !7, i64 0}


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