; LLVM IR from DanEngelbrecht/longtail :: lib/zstd/ext/decompress (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_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.XXH64_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, 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.XXH64_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 }

@repStartValue = external hidden constant [3 x i32], align 4

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

; Function Attrs: nounwind uwtable
declare hidden i64 @ZSTD_startingInputLength(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTD_decompressBegin(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = icmp ne ptr @ZSTD_trace_decompress_begin, null
  br i1 %3, label %4, label %7

4:                                                ; preds = %1
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call i64 @ZSTD_trace_decompress_begin(ptr noundef %5)
  br label %8

7:                                                ; preds = %1
  br label %8

8:                                                ; preds = %7, %4
  %9 = phi i64 [ %6, %4 ], [ 0, %7 ]
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %10, i32 0, i32 59
  store i64 %9, ptr %11, align 8, !tbaa !9
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %12, i32 0, i32 20
  %14 = load i32, ptr %13, align 8, !tbaa !19
  %15 = call i64 @ZSTD_startingInputLength(i32 noundef %14)
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %16, i32 0, i32 10
  store i64 %15, ptr %17, align 8, !tbaa !20
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %18, i32 0, i32 15
  store i32 0, ptr %19, align 4, !tbaa !21
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %20, i32 0, i32 12
  store i64 0, ptr %21, align 8, !tbaa !22
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %22, i32 0, i32 13
  store i64 0, ptr %23, align 8, !tbaa !23
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %24, i32 0, i32 6
  store ptr null, ptr %25, align 8, !tbaa !24
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %26, i32 0, i32 7
  store ptr null, ptr %27, align 8, !tbaa !25
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %28, i32 0, i32 8
  store ptr null, ptr %29, align 8, !tbaa !26
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %30, i32 0, i32 9
  store ptr null, ptr %31, align 8, !tbaa !27
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %32, i32 0, i32 4
  %34 = getelementptr inbounds %struct.ZSTD_entropyDTables_t, ptr %33, i32 0, i32 3
  %35 = getelementptr inbounds [4097 x i32], ptr %34, i64 0, i64 0
  store i32 201326604, ptr %35, align 8, !tbaa !28
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %36, i32 0, i32 17
  store i32 0, ptr %37, align 4, !tbaa !29
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %38, i32 0, i32 16
  store i32 0, ptr %39, align 8, !tbaa !30
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %40, i32 0, i32 32
  store i32 0, ptr %41, align 8, !tbaa !31
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %42, i32 0, i32 14
  store i32 3, ptr %43, align 8, !tbaa !32
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %44, i32 0, i32 28
  store i32 1, ptr %45, align 8, !tbaa !33
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %46, i32 0, i32 4
  %48 = getelementptr inbounds %struct.ZSTD_entropyDTables_t, ptr %47, i32 0, i32 4
  %49 = getelementptr inbounds [3 x i32], ptr %48, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %49, ptr align 4 @repStartValue, i64 12, i1 false)
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %50, i32 0, i32 4
  %52 = getelementptr inbounds %struct.ZSTD_entropyDTables_t, ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds [513 x %struct.ZSTD_seqSymbol], ptr %52, i64 0, i64 0
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %54, i32 0, i32 0
  store ptr %53, ptr %55, align 8, !tbaa !34
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %56, i32 0, i32 4
  %58 = getelementptr inbounds %struct.ZSTD_entropyDTables_t, ptr %57, i32 0, i32 2
  %59 = getelementptr inbounds [513 x %struct.ZSTD_seqSymbol], ptr %58, i64 0, i64 0
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %60, i32 0, i32 1
  store ptr %59, ptr %61, align 8, !tbaa !35
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %62, i32 0, i32 4
  %64 = getelementptr inbounds %struct.ZSTD_entropyDTables_t, ptr %63, i32 0, i32 1
  %65 = getelementptr inbounds [257 x %struct.ZSTD_seqSymbol], ptr %64, i64 0, i64 0
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %66, i32 0, i32 2
  store ptr %65, ptr %67, align 8, !tbaa !36
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %68, i32 0, i32 4
  %70 = getelementptr inbounds %struct.ZSTD_entropyDTables_t, ptr %69, i32 0, i32 3
  %71 = getelementptr inbounds [4097 x i32], ptr %70, i64 0, i64 0
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %72, i32 0, i32 3
  store ptr %71, ptr %73, align 8, !tbaa !37
  ret i64 0
}

declare extern_weak i64 @ZSTD_trace_decompress_begin(ptr noundef) #2

attributes #0 = { nocallback nofree 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" }

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


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

@repStartValue = external hidden local_unnamed_addr constant [3 x i32], align 4

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

; Function Attrs: nounwind uwtable
declare hidden i64 @ZSTD_startingInputLength(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @ZSTD_decompressBegin(ptr noundef %0) local_unnamed_addr #1 {
  %.not = icmp eq ptr @ZSTD_trace_decompress_begin, null
  br i1 %.not, label %4, label %2

2:                                                ; preds = %1
  %3 = tail call i64 @ZSTD_trace_decompress_begin(ptr noundef %0) #4
  br label %4

4:                                                ; preds = %1, %2
  %5 = phi i64 [ %3, %2 ], [ 0, %1 ]
  %6 = getelementptr inbounds i8, ptr %0, i64 95968
  store i64 %5, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 30104
  %8 = load i32, ptr %7, align 8, !tbaa !18
  %9 = tail call i64 @ZSTD_startingInputLength(i32 noundef %8)
  %10 = getelementptr inbounds i8, ptr %0, i64 29920
  store i64 %9, ptr %10, align 8, !tbaa !19
  %11 = getelementptr inbounds i8, ptr %0, i64 29976
  %12 = getelementptr inbounds i8, ptr %0, i64 29888
  %13 = getelementptr inbounds i8, ptr %0, i64 32
  %14 = getelementptr inbounds i8, ptr %0, i64 10296
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %12, i8 0, i64 32, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %11, i8 0, i64 16, i1 false)
  store i32 201326604, ptr %14, align 8, !tbaa !20
  %15 = getelementptr inbounds i8, ptr %0, i64 30200
  store i32 0, ptr %15, align 8, !tbaa !21
  %16 = getelementptr inbounds i8, ptr %0, i64 29992
  store <4 x i32> <i32 3, i32 0, i32 0, i32 0>, ptr %16, align 8, !tbaa !20
  %17 = getelementptr inbounds i8, ptr %0, i64 30176
  store i32 1, ptr %17, align 8, !tbaa !22
  %18 = getelementptr inbounds i8, ptr %0, i64 26684
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %18, ptr noundef nonnull align 4 dereferenceable(12) @repStartValue, i64 12, i1 false)
  store ptr %13, ptr %0, align 8, !tbaa !23
  %19 = getelementptr inbounds i8, ptr %0, i64 6192
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %19, ptr %20, align 8, !tbaa !24
  %21 = getelementptr inbounds i8, ptr %0, i64 4136
  %22 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %21, ptr %22, align 8, !tbaa !25
  %23 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %14, ptr %23, align 8, !tbaa !26
  ret i64 0
}

declare extern_weak i64 @ZSTD_trace_decompress_begin(ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { mustprogress nocallback nofree 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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, !13, i64 95968}
!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, !13, i64 95968}
!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 = !{!"XXH64_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 30104}
!19 = !{!6, !11, i64 29920}
!20 = !{!14, !14, i64 0}
!21 = !{!6, !14, i64 30200}
!22 = !{!6, !14, i64 30176}
!23 = !{!6, !7, i64 0}
!24 = !{!6, !7, i64 8}
!25 = !{!6, !7, i64 16}
!26 = !{!6, !7, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass