; 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 }

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [24 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @gsk_gpak_read(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call i64 @_hash_djb2(ptr noundef %11)
  store i64 %12, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.gsk_GPakContainer, ptr %14, i32 0, i32 1
  %16 = load i64, ptr %15, align 8, !tbaa !11
  %17 = urem i64 %13, %16
  store i64 %17, ptr %7, align 8, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.gsk_GPakContainer, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %20, i64 %21
  %23 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %22, i32 0, i32 0
  %24 = load i64, ptr %23, align 8, !tbaa !14
  %25 = icmp eq i64 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %2
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  call void (i32, ptr, i32, ptr, ...) @logger_log(i32 noundef 6, ptr noundef @.str, i32 noundef 91, ptr noundef @.str.1, ptr noundef %27)
  call void @exit(i32 noundef 1) #6
  unreachable

28:                                               ; preds = %2
  %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 !13
  %32 = load i64, ptr %7, 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 !14
  %36 = icmp ne i64 %35, 0
  br i1 %36, label %37, label %85

37:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %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 !13
  %41 = load i64, ptr %7, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %40, i64 %41
  store ptr %42, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %43, i32 0, i32 3
  %45 = load ptr, ptr %44, align 8, !tbaa !16
  store ptr %45, ptr %9, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %66, %37
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %71

49:                                               ; preds = %46
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %50, i32 0, i32 2
  %52 = load ptr, ptr %51, align 8, !tbaa !17
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = call i32 @strcmp(ptr noundef %52, ptr noundef %53) #7
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %60, label %56

56:                                               ; preds = %49
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %57, i32 0, i32 0
  %59 = load i64, ptr %58, align 8, !tbaa !14
  store i64 %59, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %84

60:                                               ; preds = %49
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %61, i32 0, i32 0
  %63 = load i64, ptr %62, align 8, !tbaa !14
  %64 = icmp eq i64 %63, 0
  br i1 %64, label %65, label %66

65:                                               ; preds = %60
  call void (i32, ptr, i32, ptr, ...) @logger_log(i32 noundef 5, ptr noundef @.str, i32 noundef 108, ptr noundef @.str.2)
  br label %66

66:                                               ; preds = %65, %60
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %67, ptr %8, align 8, !tbaa !5
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %68, i32 0, i32 3
  %70 = load ptr, ptr %69, align 8, !tbaa !16
  store ptr %70, ptr %9, align 8, !tbaa !5
  br label %46, !llvm.loop !18

71:                                               ; preds = %46
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %72, i32 0, i32 2
  %74 = load ptr, ptr %73, align 8, !tbaa !17
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = call i32 @strcmp(ptr noundef %74, ptr noundef %75) #7
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %80

78:                                               ; preds = %71
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  call void (i32, ptr, i32, ptr, ...) @logger_log(i32 noundef 5, ptr noundef @.str, i32 noundef 118, ptr noundef @.str.3, ptr noundef %79)
  store i64 0, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %84

80:                                               ; preds = %71
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.gsk_GPakAssetRef, ptr %81, i32 0, i32 0
  %83 = load i64, ptr %82, align 8, !tbaa !14
  store i64 %83, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %84

84:                                               ; preds = %80, %78, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %86

85:                                               ; preds = %28
  store i32 0, ptr %10, align 4
  br label %86

86:                                               ; preds = %85, %84
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %87 = load i32, ptr %10, align 4
  switch i32 %87, label %90 [
    i32 0, label %88
    i32 1, label %88
  ]

88:                                               ; preds = %86, %86
  %89 = load i64, ptr %3, align 8
  ret i64 %89

90:                                               ; preds = %86
  unreachable
}

declare void @logger_log(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync 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 = { "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 = { noreturn 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 #4 = { nounwind willreturn memory(read) "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 = { nounwind }
attributes #6 = { noreturn nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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 = !{!12, !6, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"gsk_GPakAssetRef", !10, i64 0, !7, i64 8, !6, i64 16, !6, i64 24}
!16 = !{!15, !6, i64 24}
!17 = !{!15, !6, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"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 }

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [24 x i8], align 1

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

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

.preheader:                                       ; preds = %2
  %.0.in27 = getelementptr inbounds i8, ptr %8, i64 24
  %.028 = load ptr, ptr %.0.in27, align 8, !tbaa !14
  %.not29 = icmp eq ptr %.028, null
  br i1 %.not29, label %._crit_edge, label %.lr.ph

11:                                               ; preds = %2
  tail call void (i32, ptr, i32, ptr, ...) @logger_log(i32 noundef 6, ptr noundef nonnull @.str, i32 noundef 91, ptr noundef nonnull @.str.1, ptr noundef %1) #4
  tail call void @exit(i32 noundef 1) #5
  unreachable

.lr.ph:                                           ; preds = %.preheader, %21
  %.031 = phi ptr [ %.0, %21 ], [ %.028, %.preheader ]
  %.02230 = phi ptr [ %.031, %21 ], [ %8, %.preheader ]
  %12 = getelementptr inbounds i8, ptr %.02230, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %14 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %13, ptr noundef nonnull dereferenceable(1) %1) #6
  %.not25 = icmp eq i32 %14, 0
  br i1 %.not25, label %15, label %17

15:                                               ; preds = %.lr.ph
  %16 = load i64, ptr %.02230, align 8, !tbaa !12
  br label %28

17:                                               ; preds = %.lr.ph
  %18 = load i64, ptr %.031, align 8, !tbaa !12
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  tail call void (i32, ptr, i32, ptr, ...) @logger_log(i32 noundef 5, ptr noundef nonnull @.str, i32 noundef 108, ptr noundef nonnull @.str.2) #4
  br label %21

21:                                               ; preds = %20, %17
  %.0.in = getelementptr inbounds i8, ptr %.031, i64 24
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !14
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %21, %.preheader
  %.022.lcssa = phi ptr [ %8, %.preheader ], [ %.031, %21 ]
  %22 = getelementptr inbounds i8, ptr %.022.lcssa, i64 16
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %23, ptr noundef nonnull dereferenceable(1) %1) #6
  %.not24 = icmp eq i32 %24, 0
  br i1 %.not24, label %26, label %25

25:                                               ; preds = %._crit_edge
  tail call void (i32, ptr, i32, ptr, ...) @logger_log(i32 noundef 5, ptr noundef nonnull @.str, i32 noundef 118, ptr noundef nonnull @.str.3, ptr noundef %1) #4
  br label %28

26:                                               ; preds = %._crit_edge
  %27 = load i64, ptr %.022.lcssa, align 8, !tbaa !12
  br label %28

28:                                               ; preds = %15, %25, %26
  %.023 = phi i64 [ %16, %15 ], [ 0, %25 ], [ %27, %26 ]
  ret i64 %.023
}

declare void @logger_log(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #3

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 = { "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 = { noreturn 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 #3 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { noreturn nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!13, !7, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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