; LLVM IR from catid/Zpng :: zstd (zstd_decompress)

; 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.ZSTD_customMem = type { ptr, ptr, ptr }
%struct.ZSTD_DCtx_s = type { ptr, ptr, ptr, ptr, %struct.ZSTD_entropyDTables_t, ptr, ptr, ptr, ptr, i64, %struct.ZSTD_frameHeader, i64, i32, i32, i32, i32, %struct.XXH64_state_s, i64, i32, i32, ptr, %struct.ZSTD_customMem, i64, i64, i64, i32, ptr, ptr, i32, ptr, i64, i64, i64, ptr, i64, i64, i64, i64, ptr, i32, i32, i32, [131080 x i8], [18 x i8] }
%struct.ZSTD_entropyDTables_t = type { [513 x %struct.ZSTD_seqSymbol], [257 x %struct.ZSTD_seqSymbol], [513 x %struct.ZSTD_seqSymbol], [4097 x i32], [512 x i32], [3 x i32] }
%struct.ZSTD_seqSymbol = type { i16, i8, i8, i32 }
%struct.ZSTD_frameHeader = type { i64, i64, i32, i32, i32, i32, i32 }
%struct.XXH64_state_s = type { i64, i64, i64, i64, i64, [4 x i64], i32, [2 x i32] }

; Function Attrs: nounwind uwtable
declare dso_local i64 @ZSTD_freeDDict(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @ZSTD_createDDict_advanced(ptr noundef, i64 noundef, i32 noundef, i32 noundef, ptr noundef byval(%struct.ZSTD_customMem) align 8) #0

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTD_DCtx_loadDictionary_advanced(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !11
  store i32 %4, ptr %11, align 4, !tbaa !11
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %12, i32 0, i32 28
  %14 = load i32, ptr %13, align 8, !tbaa !13
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %5
  store i64 -60, ptr %6, align 8
  br label %52

17:                                               ; preds = %5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %18, i32 0, i32 26
  %20 = load ptr, ptr %19, align 8, !tbaa !20
  %21 = call i64 @ZSTD_freeDDict(ptr noundef %20)
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %43

24:                                               ; preds = %17
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = icmp uge i64 %25, 8
  br i1 %26, label %27, label %43

27:                                               ; preds = %24
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = load i64, ptr %9, align 8, !tbaa !9
  %30 = load i32, ptr %10, align 4, !tbaa !11
  %31 = load i32, ptr %11, align 4, !tbaa !11
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %32, i32 0, i32 21
  %34 = call ptr @ZSTD_createDDict_advanced(ptr noundef %28, i64 noundef %29, i32 noundef %30, i32 noundef %31, ptr noundef byval(%struct.ZSTD_customMem) align 8 %33)
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %35, i32 0, i32 26
  store ptr %34, ptr %36, align 8, !tbaa !20
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %37, i32 0, i32 26
  %39 = load ptr, ptr %38, align 8, !tbaa !20
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %42

41:                                               ; preds = %27
  store i64 -64, ptr %6, align 8
  br label %52

42:                                               ; preds = %27
  br label %46

43:                                               ; preds = %24, %17
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %44, i32 0, i32 26
  store ptr null, ptr %45, align 8, !tbaa !20
  br label %46

46:                                               ; preds = %43, %42
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %47, i32 0, i32 26
  %49 = load ptr, ptr %48, align 8, !tbaa !20
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %50, i32 0, i32 27
  store ptr %49, ptr %51, align 8, !tbaa !21
  store i64 0, ptr %6, align 8
  br label %52

52:                                               ; preds = %46, %41, %16
  %53 = load i64, ptr %6, align 8
  ret i64 %53
}

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

!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", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 29032}
!14 = !{!"ZSTD_DCtx_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !15, i64 32, !6, i64 28744, !6, i64 28752, !6, i64 28760, !6, i64 28768, !10, i64 28776, !16, i64 28784, !10, i64 28824, !12, i64 28832, !12, i64 28836, !12, i64 28840, !12, i64 28844, !18, i64 28848, !10, i64 28936, !12, i64 28944, !12, i64 28948, !6, i64 28952, !19, i64 28960, !10, i64 28984, !10, i64 28992, !10, i64 29000, !12, i64 29008, !6, i64 29016, !6, i64 29024, !12, i64 29032, !6, i64 29040, !10, i64 29048, !10, i64 29056, !10, i64 29064, !6, i64 29072, !10, i64 29080, !10, i64 29088, !10, i64 29096, !10, i64 29104, !6, i64 29112, !12, i64 29120, !12, i64 29124, !12, i64 29128, !7, i64 29132, !7, i64 160212}
!15 = !{!"", !7, i64 0, !7, i64 4104, !7, i64 6160, !7, i64 10264, !7, i64 26652, !7, i64 28700}
!16 = !{!"", !17, i64 0, !17, i64 8, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32}
!17 = !{!"long long", !7, i64 0}
!18 = !{!"XXH64_state_s", !17, i64 0, !17, i64 8, !17, i64 16, !17, i64 24, !17, i64 32, !7, i64 40, !12, i64 72, !7, i64 76}
!19 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!14, !6, i64 29016}
!21 = !{!14, !6, i64 29024}


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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @ZSTD_createDDict_advanced(ptr noundef, i64 noundef, i32 noundef, i32 noundef, ptr noundef byval(%struct.ZSTD_customMem) align 8) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -64, 1) i64 @ZSTD_DCtx_loadDictionary_advanced(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %0, i64 29032
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %22

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 29016
  %10 = load ptr, ptr %9, align 8, !tbaa !17
  %11 = tail call i64 @ZSTD_freeDDict(ptr noundef %10)
  %12 = icmp ne ptr %1, null
  %13 = icmp ugt i64 %2, 7
  %or.cond = and i1 %12, %13
  br i1 %or.cond, label %14, label %18

14:                                               ; preds = %8
  %15 = getelementptr inbounds i8, ptr %0, i64 28960
  %16 = tail call ptr @ZSTD_createDDict_advanced(ptr noundef nonnull %1, i64 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef nonnull byval(%struct.ZSTD_customMem) align 8 %15)
  store ptr %16, ptr %9, align 8, !tbaa !17
  %17 = icmp eq ptr %16, null
  br i1 %17, label %22, label %19

18:                                               ; preds = %8
  store ptr null, ptr %9, align 8, !tbaa !17
  br label %19

19:                                               ; preds = %14, %18
  %20 = phi ptr [ %16, %14 ], [ null, %18 ]
  %21 = getelementptr inbounds i8, ptr %0, i64 29024
  store ptr %20, ptr %21, align 8, !tbaa !18
  br label %22

22:                                               ; preds = %14, %5, %19
  %.0 = phi i64 [ 0, %19 ], [ -60, %5 ], [ -64, %14 ]
  ret i64 %.0
}

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

!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, !14, i64 29032}
!6 = !{!"ZSTD_DCtx_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !7, i64 28744, !7, i64 28752, !7, i64 28760, !7, i64 28768, !11, i64 28776, !12, i64 28784, !11, i64 28824, !14, i64 28832, !14, i64 28836, !14, i64 28840, !14, i64 28844, !15, i64 28848, !11, i64 28936, !14, i64 28944, !14, i64 28948, !7, i64 28952, !16, i64 28960, !11, i64 28984, !11, i64 28992, !11, i64 29000, !14, i64 29008, !7, i64 29016, !7, i64 29024, !14, i64 29032, !7, i64 29040, !11, i64 29048, !11, i64 29056, !11, i64 29064, !7, i64 29072, !11, i64 29080, !11, i64 29088, !11, i64 29096, !11, i64 29104, !7, i64 29112, !14, i64 29120, !14, i64 29124, !14, i64 29128, !8, i64 29132, !8, i64 160212}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !8, i64 0, !8, i64 4104, !8, i64 6160, !8, i64 10264, !8, i64 26652, !8, i64 28700}
!11 = !{!"long", !8, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 8, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32}
!13 = !{!"long long", !8, i64 0}
!14 = !{!"int", !8, i64 0}
!15 = !{!"XXH64_state_s", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !8, i64 40, !14, i64 72, !8, i64 76}
!16 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16}
!17 = !{!6, !7, i64 29016}
!18 = !{!6, !7, i64 29024}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass