; LLVM IR from TobiasKozel/VAE :: external/tracy/common/tracy_lz4hc.ll (ZN5tracy14LZ4_saveDictHCEPNS_14LZ4_streamHC_uEPci)

; 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.tracy::LZ4HC_CCtx_internal" = type { [32768 x i32], [65536 x i16], ptr, ptr, ptr, i32, i32, i32, i16, i8, i8, ptr }

; 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: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN5tracy14LZ4_saveDictHCEPNS_14LZ4_streamHC_uEPci(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %10, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = getelementptr inbounds %"struct.tracy::LZ4HC_CCtx_internal", ptr %11, i32 0, i32 2
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %"struct.tracy::LZ4HC_CCtx_internal", ptr %14, i32 0, i32 3
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %"struct.tracy::LZ4HC_CCtx_internal", ptr %17, i32 0, i32 5
  %19 = load i32, ptr %18, align 8, !tbaa !15
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds i8, ptr %16, i64 %20
  %22 = ptrtoint ptr %13 to i64
  %23 = ptrtoint ptr %21 to i64
  %24 = sub i64 %22, %23
  %25 = trunc i64 %24 to i32
  store i32 %25, ptr %8, align 4, !tbaa !9
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = icmp sgt i32 %26, 65536
  br i1 %27, label %28, label %29

28:                                               ; preds = %3
  store i32 65536, ptr %6, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %28, %3
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = icmp slt i32 %30, 4
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %32, %29
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = icmp sgt i32 %34, %35
  br i1 %36, label %37, label %39

37:                                               ; preds = %33
  %38 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %38, ptr %6, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %37, %33
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %43

42:                                               ; preds = %39
  br label %43

43:                                               ; preds = %42, %39
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = icmp sgt i32 %44, 0
  br i1 %45, label %46, label %57

46:                                               ; preds = %43
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.tracy::LZ4HC_CCtx_internal", ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = sub i64 0, %52
  %54 = getelementptr inbounds i8, ptr %50, i64 %53
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %47, ptr align 1 %54, i64 %56, i1 false)
  br label %57

57:                                               ; preds = %46, %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %"struct.tracy::LZ4HC_CCtx_internal", ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %59, align 8, !tbaa !11
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %"struct.tracy::LZ4HC_CCtx_internal", ptr %61, i32 0, i32 3
  %63 = load ptr, ptr %62, align 8, !tbaa !14
  %64 = ptrtoint ptr %60 to i64
  %65 = ptrtoint ptr %63 to i64
  %66 = sub i64 %64, %65
  %67 = trunc i64 %66 to i32
  store i32 %67, ptr %9, align 4, !tbaa !9
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds i8, ptr %68, i64 %70
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = getelementptr inbounds %"struct.tracy::LZ4HC_CCtx_internal", ptr %72, i32 0, i32 2
  store ptr %71, ptr %73, align 8, !tbaa !11
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds %"struct.tracy::LZ4HC_CCtx_internal", ptr %74, i32 0, i32 2
  %76 = load ptr, ptr %75, align 8, !tbaa !11
  %77 = load i32, ptr %9, align 4, !tbaa !9
  %78 = zext i32 %77 to i64
  %79 = sub i64 0, %78
  %80 = getelementptr inbounds i8, ptr %76, i64 %79
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = getelementptr inbounds %"struct.tracy::LZ4HC_CCtx_internal", ptr %81, i32 0, i32 3
  store ptr %80, ptr %82, align 8, !tbaa !14
  %83 = load i32, ptr %9, align 4, !tbaa !9
  %84 = load i32, ptr %6, align 4, !tbaa !9
  %85 = sub i32 %83, %84
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = getelementptr inbounds %"struct.tracy::LZ4HC_CCtx_internal", ptr %86, i32 0, i32 5
  store i32 %85, ptr %87, align 8, !tbaa !15
  %88 = load i32, ptr %9, align 4, !tbaa !9
  %89 = load i32, ptr %6, align 4, !tbaa !9
  %90 = sub i32 %88, %89
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = getelementptr inbounds %"struct.tracy::LZ4HC_CCtx_internal", ptr %91, i32 0, i32 6
  store i32 %90, ptr %92, align 4, !tbaa !16
  %93 = load ptr, ptr %7, align 8, !tbaa !5
  %94 = getelementptr inbounds %"struct.tracy::LZ4HC_CCtx_internal", ptr %93, i32 0, i32 7
  %95 = load i32, ptr %94, align 8, !tbaa !17
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = getelementptr inbounds %"struct.tracy::LZ4HC_CCtx_internal", ptr %96, i32 0, i32 5
  %98 = load i32, ptr %97, align 8, !tbaa !15
  %99 = icmp ult i32 %95, %98
  br i1 %99, label %100, label %106

100:                                              ; preds = %57
  %101 = load ptr, ptr %7, align 8, !tbaa !5
  %102 = getelementptr inbounds %"struct.tracy::LZ4HC_CCtx_internal", ptr %101, i32 0, i32 5
  %103 = load i32, ptr %102, align 8, !tbaa !15
  %104 = load ptr, ptr %7, align 8, !tbaa !5
  %105 = getelementptr inbounds %"struct.tracy::LZ4HC_CCtx_internal", ptr %104, i32 0, i32 7
  store i32 %103, ptr %105, align 8, !tbaa !17
  br label %106

106:                                              ; preds = %100, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %107 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i32 %107
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 262144}
!12 = !{!"_ZTSN5tracy19LZ4HC_CCtx_internalE", !7, i64 0, !7, i64 131072, !6, i64 262144, !6, i64 262152, !6, i64 262160, !10, i64 262168, !10, i64 262172, !10, i64 262176, !13, i64 262180, !7, i64 262182, !7, i64 262183, !6, i64 262184}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !6, i64 262152}
!15 = !{!12, !10, i64 262168}
!16 = !{!12, !10, i64 262172}
!17 = !{!12, !10, i64 262176}


; 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 nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_ZN5tracy14LZ4_saveDictHCEPNS_14LZ4_streamHC_uEPci(ptr nocapture noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 262144
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 262152
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %0, i64 262168
  %9 = load i32, ptr %8, align 8, !tbaa !13
  %10 = zext i32 %9 to i64
  %11 = getelementptr inbounds i8, ptr %7, i64 %10
  %12 = ptrtoint ptr %5 to i64
  %13 = ptrtoint ptr %11 to i64
  %14 = sub i64 %12, %13
  %15 = trunc i64 %14 to i32
  %16 = tail call i32 @llvm.umin.i32(i32 %2, i32 65536)
  %17 = icmp slt i32 %2, 4
  %spec.store.select1 = select i1 %17, i32 0, i32 %16
  %spec.select = tail call i32 @llvm.smin.i32(i32 %spec.store.select1, i32 %15)
  %18 = icmp sgt i32 %spec.select, 0
  br i1 %18, label %19, label %23

19:                                               ; preds = %3
  %20 = zext nneg i32 %spec.select to i64
  %21 = sub nsw i64 0, %20
  %22 = getelementptr inbounds i8, ptr %5, i64 %21
  tail call void @llvm.memmove.p0.p0.i64(ptr align 1 %1, ptr nonnull align 1 %22, i64 %20, i1 false)
  %.pre = load ptr, ptr %4, align 8, !tbaa !5
  %.pre36 = load ptr, ptr %6, align 8, !tbaa !12
  %.pre37 = ptrtoint ptr %.pre to i64
  br label %23

23:                                               ; preds = %19, %3
  %.pre-phi = phi i64 [ %.pre37, %19 ], [ %12, %3 ]
  %24 = phi ptr [ %.pre36, %19 ], [ %7, %3 ]
  %25 = ptrtoint ptr %24 to i64
  %26 = sub i64 %.pre-phi, %25
  %27 = trunc i64 %26 to i32
  %28 = sext i32 %spec.select to i64
  %29 = getelementptr inbounds i8, ptr %1, i64 %28
  store ptr %29, ptr %4, align 8, !tbaa !5
  %30 = and i64 %26, 4294967295
  %31 = sub nsw i64 0, %30
  %32 = getelementptr inbounds i8, ptr %29, i64 %31
  store ptr %32, ptr %6, align 8, !tbaa !12
  %33 = sub i32 %27, %spec.select
  store i32 %33, ptr %8, align 8, !tbaa !13
  %34 = getelementptr inbounds i8, ptr %0, i64 262172
  store i32 %33, ptr %34, align 4, !tbaa !14
  %35 = getelementptr inbounds i8, ptr %0, i64 262176
  %36 = load i32, ptr %35, align 8, !tbaa !15
  %37 = icmp ult i32 %36, %33
  br i1 %37, label %38, label %39

38:                                               ; preds = %23
  store i32 %33, ptr %35, align 8, !tbaa !15
  br label %39

39:                                               ; preds = %38, %23
  ret i32 %spec.select
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #2

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) 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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !9, i64 262144}
!6 = !{!"_ZTSN5tracy19LZ4HC_CCtx_internalE", !7, i64 0, !7, i64 131072, !9, i64 262144, !9, i64 262152, !9, i64 262160, !10, i64 262168, !10, i64 262172, !10, i64 262176, !11, i64 262180, !7, i64 262182, !7, i64 262183, !9, i64 262184}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!6, !9, i64 262152}
!13 = !{!6, !10, i64 262168}
!14 = !{!6, !10, i64 262172}
!15 = !{!6, !10, i64 262176}


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