; LLVM IR from indygreg/python-zstandard :: zstd (zstd)

; 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, [640 x i32], ptr, ptr, ptr, ptr, i64, %struct.ZSTD_frameHeader, i64, i64, i32, i32, i32, i32, %struct.XXH_NAMESPACEXXH64_state_s, i64, i32, i32, i32, ptr, %struct.ZSTD_customMem, i64, i64, i64, i32, i32, ptr, ptr, i32, i32, i32, ptr, i32, i32, i32, i32, ptr, i64, i64, i64, ptr, i64, i64, i64, i64, i32, i32, i32, %struct.ZSTD_outBuffer_s, ptr, ptr, i32, [65568 x i8], [18 x i8], i64 }
%struct.ZSTD_entropyDTables_t = type { [513 x %struct.ZSTD_seqSymbol], [257 x %struct.ZSTD_seqSymbol], [513 x %struct.ZSTD_seqSymbol], [4097 x i32], [3 x i32], [157 x i32] }
%struct.ZSTD_seqSymbol = type { i16, i8, i8, i32 }
%struct.ZSTD_frameHeader = type { i64, i64, i32, i32, i32, i32, i32, i32, i32 }
%struct.XXH_NAMESPACEXXH64_state_s = type { i64, [4 x i64], [4 x i64], i32, i32, i64 }
%struct.ZSTD_outBuffer_s = type { ptr, i64, i64 }

; 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
declare hidden void @ZSTD_clearDict(ptr noundef) #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
  br label %12

12:                                               ; preds = %5
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %13, i32 0, i32 39
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %26

17:                                               ; preds = %12
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  store i64 -60, ptr %6, align 8
  br label %68

26:                                               ; preds = %12
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ZSTD_clearDict(ptr noundef %28)
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %67

31:                                               ; preds = %27
  %32 = load i64, ptr %9, align 8, !tbaa !9
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %34, label %67

34:                                               ; preds = %31
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load i64, ptr %9, align 8, !tbaa !9
  %37 = load i32, ptr %10, align 4, !tbaa !11
  %38 = load i32, ptr %11, align 4, !tbaa !11
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %39, i32 0, i32 24
  %41 = call ptr @ZSTD_createDDict_advanced(ptr noundef %35, i64 noundef %36, i32 noundef %37, i32 noundef %38, ptr noundef byval(%struct.ZSTD_customMem) align 8 %40)
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %42, i32 0, i32 30
  store ptr %41, ptr %43, align 8, !tbaa !21
  br label %44

44:                                               ; preds = %34
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %45, i32 0, i32 30
  %47 = load ptr, ptr %46, align 8, !tbaa !21
  %48 = icmp eq ptr %47, null
  br i1 %48, label %49, label %58

49:                                               ; preds = %44
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  store i64 -64, ptr %6, align 8
  br label %68

58:                                               ; preds = %44
  br label %59

59:                                               ; preds = %58
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %60, i32 0, i32 30
  %62 = load ptr, ptr %61, align 8, !tbaa !21
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %63, i32 0, i32 31
  store ptr %62, ptr %64, align 8, !tbaa !22
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %65, i32 0, i32 34
  store i32 -1, ptr %66, align 8, !tbaa !23
  br label %67

67:                                               ; preds = %59, %31, %27
  store i64 0, ptr %6, align 8
  br label %68

68:                                               ; preds = %67, %57, %25
  %69 = load i64, ptr %6, align 8
  ret i64 %69
}

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 30236}
!14 = !{!"ZSTD_DCtx_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !15, i64 32, !7, i64 27324, !6, i64 29888, !6, i64 29896, !6, i64 29904, !6, i64 29912, !10, i64 29920, !16, i64 29928, !10, i64 29976, !10, i64 29984, !12, i64 29992, !12, i64 29996, !12, i64 30000, !12, i64 30004, !18, i64 30008, !10, i64 30096, !12, i64 30104, !12, i64 30108, !12, i64 30112, !6, i64 30120, !19, i64 30128, !10, i64 30152, !10, i64 30160, !10, i64 30168, !12, i64 30176, !12, i64 30180, !6, i64 30184, !6, i64 30192, !12, i64 30200, !12, i64 30204, !12, i64 30208, !6, i64 30216, !12, i64 30224, !12, i64 30228, !12, i64 30232, !12, i64 30236, !6, i64 30240, !10, i64 30248, !10, i64 30256, !10, i64 30264, !6, i64 30272, !10, i64 30280, !10, i64 30288, !10, i64 30296, !10, i64 30304, !12, i64 30312, !12, i64 30316, !12, i64 30320, !20, i64 30328, !6, i64 30352, !6, i64 30360, !12, i64 30368, !7, i64 30372, !7, i64 95940, !10, i64 95960}
!15 = !{!"", !7, i64 0, !7, i64 4104, !7, i64 6160, !7, i64 10264, !7, i64 26652, !7, i64 26664}
!16 = !{!"", !17, i64 0, !17, i64 8, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40}
!17 = !{!"long long", !7, i64 0}
!18 = !{!"XXH_NAMESPACEXXH64_state_s", !10, i64 0, !7, i64 8, !7, i64 40, !12, i64 72, !12, i64 76, !10, i64 80}
!19 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!"ZSTD_outBuffer_s", !6, i64 0, !10, i64 8, !10, i64 16}
!21 = !{!14, !6, i64 30184}
!22 = !{!14, !6, i64 30192}
!23 = !{!14, !12, i64 30208}


; 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 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
declare hidden void @ZSTD_clearDict(ptr noundef) 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 30236
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %19

8:                                                ; preds = %5
  tail call void @ZSTD_clearDict(ptr noundef nonnull %0)
  %9 = icmp ne ptr %1, null
  %10 = icmp ne i64 %2, 0
  %or.cond = and i1 %9, %10
  br i1 %or.cond, label %11, label %19

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 30128
  %13 = 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 %12)
  %14 = getelementptr inbounds i8, ptr %0, i64 30184
  store ptr %13, ptr %14, align 8, !tbaa !18
  %15 = icmp eq ptr %13, null
  br i1 %15, label %19, label %16

16:                                               ; preds = %11
  %17 = getelementptr inbounds i8, ptr %0, i64 30192
  store ptr %13, ptr %17, align 8, !tbaa !19
  %18 = getelementptr inbounds i8, ptr %0, i64 30208
  store i32 -1, ptr %18, align 8, !tbaa !20
  br label %19

19:                                               ; preds = %8, %16, %11, %5
  %.0 = phi i64 [ -60, %5 ], [ -64, %11 ], [ 0, %16 ], [ 0, %8 ]
  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 30236}
!6 = !{!"ZSTD_DCtx_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !8, i64 27324, !7, i64 29888, !7, i64 29896, !7, i64 29904, !7, i64 29912, !11, i64 29920, !12, i64 29928, !11, i64 29976, !11, i64 29984, !14, i64 29992, !14, i64 29996, !14, i64 30000, !14, i64 30004, !15, i64 30008, !11, i64 30096, !14, i64 30104, !14, i64 30108, !14, i64 30112, !7, i64 30120, !16, i64 30128, !11, i64 30152, !11, i64 30160, !11, i64 30168, !14, i64 30176, !14, i64 30180, !7, i64 30184, !7, i64 30192, !14, i64 30200, !14, i64 30204, !14, i64 30208, !7, i64 30216, !14, i64 30224, !14, i64 30228, !14, i64 30232, !14, i64 30236, !7, i64 30240, !11, i64 30248, !11, i64 30256, !11, i64 30264, !7, i64 30272, !11, i64 30280, !11, i64 30288, !11, i64 30296, !11, i64 30304, !14, i64 30312, !14, i64 30316, !14, i64 30320, !17, i64 30328, !7, i64 30352, !7, i64 30360, !14, i64 30368, !8, i64 30372, !8, i64 95940, !11, i64 95960}
!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 26664}
!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, !14, i64 36, !14, i64 40}
!13 = !{!"long long", !8, i64 0}
!14 = !{!"int", !8, i64 0}
!15 = !{!"XXH_NAMESPACEXXH64_state_s", !11, i64 0, !8, i64 8, !8, i64 40, !14, i64 72, !14, i64 76, !11, i64 80}
!16 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16}
!17 = !{!"ZSTD_outBuffer_s", !7, i64 0, !11, i64 8, !11, i64 16}
!18 = !{!6, !7, i64 30184}
!19 = !{!6, !7, i64 30192}
!20 = !{!6, !14, i64 30208}


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