; 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_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_customMem = type { ptr, ptr, ptr }
%struct.ZSTD_outBuffer_s = type { ptr, i64, i64 }

; Function Attrs: nounwind uwtable
declare hidden void @ZSTD_clearDict(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTD_DCtx_reset(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %11, label %8

8:                                                ; preds = %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp eq i32 %9, 3
  br i1 %10, label %11, label %18

11:                                               ; preds = %8, %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %12, i32 0, i32 39
  store i32 0, ptr %13, align 4, !tbaa !11
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %14, i32 0, i32 50
  store i32 0, ptr %15, align 4, !tbaa !20
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %16, i32 0, i32 28
  store i32 1, ptr %17, align 8, !tbaa !21
  br label %18

18:                                               ; preds = %11, %8
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = icmp eq i32 %19, 2
  br i1 %20, label %24, label %21

21:                                               ; preds = %18
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = icmp eq i32 %22, 3
  br i1 %23, label %24, label %43

24:                                               ; preds = %21, %18
  br label %25

25:                                               ; preds = %24
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %26, i32 0, i32 39
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %39

30:                                               ; preds = %25
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  store i64 -60, ptr %3, align 8
  br label %44

39:                                               ; preds = %25
  br label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ZSTD_clearDict(ptr noundef %41)
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ZSTD_DCtx_resetParameters(ptr noundef %42)
  br label %43

43:                                               ; preds = %40, %21
  store i64 0, ptr %3, align 8
  br label %44

44:                                               ; preds = %43, %38
  %45 = load i64, ptr %3, align 8
  ret i64 %45
}

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


; 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: nounwind uwtable
declare hidden void @ZSTD_clearDict(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -60, 1) i64 @ZSTD_DCtx_reset(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = and i32 %1, -3
  %or.cond = icmp eq i32 %3, 1
  br i1 %or.cond, label %4, label %8

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 30236
  store i32 0, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 30316
  store i32 0, ptr %6, align 4, !tbaa !18
  %7 = getelementptr inbounds i8, ptr %0, i64 30176
  store i32 1, ptr %7, align 8, !tbaa !19
  br label %8

8:                                                ; preds = %2, %4
  %9 = and i32 %1, -2
  %or.cond3 = icmp eq i32 %9, 2
  br i1 %or.cond3, label %10, label %14

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %0, i64 30236
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %13, label %14

13:                                               ; preds = %10
  tail call void @ZSTD_clearDict(ptr noundef nonnull %0)
  tail call void @ZSTD_DCtx_resetParameters(ptr noundef nonnull %0)
  br label %14

14:                                               ; preds = %13, %8, %10
  %.0 = phi i64 [ -60, %10 ], [ 0, %8 ], [ 0, %13 ]
  ret i64 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @ZSTD_DCtx_resetParameters(ptr noundef) local_unnamed_addr #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, !14, i64 30316}
!19 = !{!6, !14, i64 30176}


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