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

@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 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %3, i32 0, i32 19
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = call i64 @ZSTD_startingInputLength(i32 noundef %5)
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %7, i32 0, i32 9
  store i64 %6, ptr %8, align 8, !tbaa !18
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %9, i32 0, i32 13
  store i32 0, ptr %10, align 4, !tbaa !19
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %11, i32 0, i32 11
  store i64 0, ptr %12, align 8, !tbaa !20
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %13, i32 0, i32 5
  store ptr null, ptr %14, align 8, !tbaa !21
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %15, i32 0, i32 6
  store ptr null, ptr %16, align 8, !tbaa !22
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %17, i32 0, i32 7
  store ptr null, ptr %18, align 8, !tbaa !23
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %19, i32 0, i32 8
  store ptr null, ptr %20, align 8, !tbaa !24
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %21, i32 0, i32 4
  %23 = getelementptr inbounds %struct.ZSTD_entropyDTables_t, ptr %22, i32 0, i32 3
  %24 = getelementptr inbounds [4097 x i32], ptr %23, i64 0, i64 0
  store i32 201326604, ptr %24, align 8, !tbaa !25
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %25, i32 0, i32 15
  store i32 0, ptr %26, align 4, !tbaa !26
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %27, i32 0, i32 14
  store i32 0, ptr %28, align 8, !tbaa !27
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %29, i32 0, i32 18
  store i32 0, ptr %30, align 8, !tbaa !28
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %31, i32 0, i32 4
  %33 = getelementptr inbounds %struct.ZSTD_entropyDTables_t, ptr %32, i32 0, i32 5
  %34 = getelementptr inbounds [3 x i32], ptr %33, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %34, ptr align 4 @repStartValue, i64 12, i1 false)
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %35, i32 0, i32 4
  %37 = getelementptr inbounds %struct.ZSTD_entropyDTables_t, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds [513 x %struct.ZSTD_seqSymbol], ptr %37, i64 0, i64 0
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %39, i32 0, i32 0
  store ptr %38, ptr %40, align 8, !tbaa !29
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %41, i32 0, i32 4
  %43 = getelementptr inbounds %struct.ZSTD_entropyDTables_t, ptr %42, i32 0, i32 2
  %44 = getelementptr inbounds [513 x %struct.ZSTD_seqSymbol], ptr %43, i64 0, i64 0
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %45, i32 0, i32 1
  store ptr %44, ptr %46, align 8, !tbaa !30
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %47, i32 0, i32 4
  %49 = getelementptr inbounds %struct.ZSTD_entropyDTables_t, ptr %48, i32 0, i32 1
  %50 = getelementptr inbounds [257 x %struct.ZSTD_seqSymbol], ptr %49, i64 0, i64 0
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %51, i32 0, i32 2
  store ptr %50, ptr %52, align 8, !tbaa !31
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %53, i32 0, i32 4
  %55 = getelementptr inbounds %struct.ZSTD_entropyDTables_t, ptr %54, i32 0, i32 3
  %56 = getelementptr inbounds [4097 x i32], ptr %55, i64 0, i64 0
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ZSTD_DCtx_s, ptr %57, i32 0, i32 3
  store ptr %56, ptr %58, align 8, !tbaa !32
  ret i64 0
}

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

!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, !15, i64 28948}
!10 = !{!"ZSTD_DCtx_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !6, i64 28744, !6, i64 28752, !6, i64 28760, !6, i64 28768, !12, i64 28776, !13, i64 28784, !12, i64 28824, !15, i64 28832, !15, i64 28836, !15, i64 28840, !15, i64 28844, !16, i64 28848, !12, i64 28936, !15, i64 28944, !15, i64 28948, !6, i64 28952, !17, i64 28960, !12, i64 28984, !12, i64 28992, !12, i64 29000, !15, i64 29008, !6, i64 29016, !6, i64 29024, !15, i64 29032, !6, i64 29040, !12, i64 29048, !12, i64 29056, !12, i64 29064, !6, i64 29072, !12, i64 29080, !12, i64 29088, !12, i64 29096, !12, i64 29104, !6, i64 29112, !15, i64 29120, !15, i64 29124, !15, i64 29128, !7, i64 29132, !7, i64 160212}
!11 = !{!"", !7, i64 0, !7, i64 4104, !7, i64 6160, !7, i64 10264, !7, i64 26652, !7, i64 28700}
!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}
!14 = !{!"long long", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!"XXH64_state_s", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !7, i64 40, !15, i64 72, !7, i64 76}
!17 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!10, !12, i64 28776}
!19 = !{!10, !15, i64 28836}
!20 = !{!10, !12, i64 28824}
!21 = !{!10, !6, i64 28744}
!22 = !{!10, !6, i64 28752}
!23 = !{!10, !6, i64 28760}
!24 = !{!10, !6, i64 28768}
!25 = !{!15, !15, i64 0}
!26 = !{!10, !15, i64 28844}
!27 = !{!10, !15, i64 28840}
!28 = !{!10, !15, i64 28944}
!29 = !{!10, !6, i64 0}
!30 = !{!10, !6, i64 8}
!31 = !{!10, !6, i64 16}
!32 = !{!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 {
  %2 = getelementptr inbounds i8, ptr %0, i64 28948
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = tail call i64 @ZSTD_startingInputLength(i32 noundef %3)
  %5 = getelementptr inbounds i8, ptr %0, i64 28776
  store i64 %4, ptr %5, align 8, !tbaa !17
  %6 = getelementptr inbounds i8, ptr %0, i64 28836
  store i32 0, ptr %6, align 4, !tbaa !18
  %7 = getelementptr inbounds i8, ptr %0, i64 28824
  store i64 0, ptr %7, align 8, !tbaa !19
  %8 = getelementptr inbounds i8, ptr %0, i64 28744
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = getelementptr inbounds i8, ptr %0, i64 10296
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %8, i8 0, i64 32, i1 false)
  store i32 201326604, ptr %10, align 8, !tbaa !20
  %11 = getelementptr inbounds i8, ptr %0, i64 28844
  store i32 0, ptr %11, align 4, !tbaa !21
  %12 = getelementptr inbounds i8, ptr %0, i64 28840
  store i32 0, ptr %12, align 8, !tbaa !22
  %13 = getelementptr inbounds i8, ptr %0, i64 28944
  store i32 0, ptr %13, align 8, !tbaa !23
  %14 = getelementptr inbounds i8, ptr %0, i64 28732
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %14, ptr noundef nonnull align 4 dereferenceable(12) @repStartValue, i64 12, i1 false)
  store ptr %9, ptr %0, align 8, !tbaa !24
  %15 = getelementptr inbounds i8, ptr %0, i64 6192
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %15, ptr %16, align 8, !tbaa !25
  %17 = getelementptr inbounds i8, ptr %0, i64 4136
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %17, ptr %18, align 8, !tbaa !26
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %10, ptr %19, align 8, !tbaa !27
  ret i64 0
}

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

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 28948}
!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, !11, i64 28776}
!18 = !{!6, !14, i64 28836}
!19 = !{!6, !11, i64 28824}
!20 = !{!14, !14, i64 0}
!21 = !{!6, !14, i64 28844}
!22 = !{!6, !14, i64 28840}
!23 = !{!6, !14, i64 28944}
!24 = !{!6, !7, i64 0}
!25 = !{!6, !7, i64 8}
!26 = !{!6, !7, i64 16}
!27 = !{!6, !7, i64 24}


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