; LLVM IR from modlfo/AudioEngine :: AudioEngine/JuceLibraryCode/modules/juce_core/zip/zlib/trees.ll (tr_stored_block)

; 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.internal_state = type { ptr, i32, ptr, i64, ptr, i32, i32, ptr, i32, i8, i32, i32, i32, i32, ptr, i64, ptr, ptr, i32, i32, i32, i32, i32, i64, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [573 x %struct.ct_data_s], [61 x %struct.ct_data_s], [39 x %struct.ct_data_s], %struct.tree_desc_s, %struct.tree_desc_s, %struct.tree_desc_s, [16 x i16], [573 x i32], i32, i32, [573 x i8], ptr, i32, i32, ptr, i64, i64, i32, i32, i16, i32 }
%struct.ct_data_s = type { %union.anon, %union.anon.0 }
%union.anon = type { i16 }
%union.anon.0 = type { i16 }
%struct.tree_desc_s = type { ptr, i32, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @_tr_stored_block(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 3, ptr %9, align 4, !tbaa !11
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.internal_state, ptr %11, i32 0, i32 57
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = load i32, ptr %9, align 4, !tbaa !11
  %15 = sub nsw i32 16, %14
  %16 = icmp sgt i32 %13, %15
  br i1 %16, label %17, label %83

17:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %18 = load i32, ptr %8, align 4, !tbaa !11
  %19 = add nsw i32 0, %18
  store i32 %19, ptr %10, align 4, !tbaa !11
  %20 = load i32, ptr %10, align 4, !tbaa !11
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.internal_state, ptr %21, i32 0, i32 57
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = shl i32 %20, %23
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.internal_state, ptr %25, i32 0, i32 56
  %27 = load i16, ptr %26, align 8, !tbaa !17
  %28 = zext i16 %27 to i32
  %29 = or i32 %28, %24
  %30 = trunc i32 %29 to i16
  store i16 %30, ptr %26, align 8, !tbaa !17
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.internal_state, ptr %31, i32 0, i32 56
  %33 = load i16, ptr %32, align 8, !tbaa !17
  %34 = zext i16 %33 to i32
  %35 = and i32 %34, 255
  %36 = trunc i32 %35 to i8
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.internal_state, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !18
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.internal_state, ptr %40, i32 0, i32 5
  %42 = load i32, ptr %41, align 8, !tbaa !19
  %43 = add i32 %42, 1
  store i32 %43, ptr %41, align 8, !tbaa !19
  %44 = zext i32 %42 to i64
  %45 = getelementptr inbounds i8, ptr %39, i64 %44
  store i8 %36, ptr %45, align 1, !tbaa !20
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.internal_state, ptr %46, i32 0, i32 56
  %48 = load i16, ptr %47, align 8, !tbaa !17
  %49 = zext i16 %48 to i32
  %50 = ashr i32 %49, 8
  %51 = trunc i32 %50 to i8
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.internal_state, ptr %52, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !18
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.internal_state, ptr %55, i32 0, i32 5
  %57 = load i32, ptr %56, align 8, !tbaa !19
  %58 = add i32 %57, 1
  store i32 %58, ptr %56, align 8, !tbaa !19
  %59 = zext i32 %57 to i64
  %60 = getelementptr inbounds i8, ptr %54, i64 %59
  store i8 %51, ptr %60, align 1, !tbaa !20
  %61 = load i32, ptr %10, align 4, !tbaa !11
  %62 = trunc i32 %61 to i16
  %63 = zext i16 %62 to i32
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.internal_state, ptr %64, i32 0, i32 57
  %66 = load i32, ptr %65, align 4, !tbaa !13
  %67 = sext i32 %66 to i64
  %68 = sub i64 16, %67
  %69 = trunc i64 %68 to i32
  %70 = ashr i32 %63, %69
  %71 = trunc i32 %70 to i16
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.internal_state, ptr %72, i32 0, i32 56
  store i16 %71, ptr %73, align 8, !tbaa !17
  %74 = load i32, ptr %9, align 4, !tbaa !11
  %75 = sext i32 %74 to i64
  %76 = sub i64 %75, 16
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.internal_state, ptr %77, i32 0, i32 57
  %79 = load i32, ptr %78, align 4, !tbaa !13
  %80 = sext i32 %79 to i64
  %81 = add i64 %80, %76
  %82 = trunc i64 %81 to i32
  store i32 %82, ptr %78, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %101

83:                                               ; preds = %4
  %84 = load i32, ptr %8, align 4, !tbaa !11
  %85 = add nsw i32 0, %84
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.internal_state, ptr %86, i32 0, i32 57
  %88 = load i32, ptr %87, align 4, !tbaa !13
  %89 = shl i32 %85, %88
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.internal_state, ptr %90, i32 0, i32 56
  %92 = load i16, ptr %91, align 8, !tbaa !17
  %93 = zext i16 %92 to i32
  %94 = or i32 %93, %89
  %95 = trunc i32 %94 to i16
  store i16 %95, ptr %91, align 8, !tbaa !17
  %96 = load i32, ptr %9, align 4, !tbaa !11
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.internal_state, ptr %97, i32 0, i32 57
  %99 = load i32, ptr %98, align 4, !tbaa !13
  %100 = add nsw i32 %99, %96
  store i32 %100, ptr %98, align 4, !tbaa !13
  br label %101

101:                                              ; preds = %83, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %102 = load ptr, ptr %5, align 8, !tbaa !5
  %103 = load ptr, ptr %6, align 8, !tbaa !5
  %104 = load i64, ptr %7, align 8, !tbaa !9
  %105 = trunc i64 %104 to i32
  call void @copy_block(ptr noundef %102, ptr noundef %103, i32 noundef %105, i32 noundef 1)
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare hidden void @copy_block(ptr noundef, ptr noundef, i32 noundef, i32 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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !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 5924}
!14 = !{!"internal_state", !6, i64 0, !12, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !12, i64 40, !12, i64 44, !6, i64 48, !12, i64 56, !7, i64 60, !12, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !6, i64 80, !10, i64 88, !6, i64 96, !6, i64 104, !12, i64 112, !12, i64 116, !12, i64 120, !12, i64 124, !12, i64 128, !10, i64 136, !12, i64 144, !12, i64 148, !12, i64 152, !12, i64 156, !12, i64 160, !12, i64 164, !12, i64 168, !12, i64 172, !12, i64 176, !12, i64 180, !12, i64 184, !12, i64 188, !12, i64 192, !7, i64 196, !7, i64 2488, !7, i64 2732, !15, i64 2888, !15, i64 2912, !15, i64 2936, !7, i64 2960, !7, i64 2992, !12, i64 5284, !12, i64 5288, !7, i64 5292, !6, i64 5872, !12, i64 5880, !12, i64 5884, !6, i64 5888, !10, i64 5896, !10, i64 5904, !12, i64 5912, !12, i64 5916, !16, i64 5920, !12, i64 5924}
!15 = !{!"tree_desc_s", !6, i64 0, !12, i64 8, !6, i64 16}
!16 = !{!"short", !7, i64 0}
!17 = !{!14, !16, i64 5920}
!18 = !{!14, !6, i64 16}
!19 = !{!14, !12, i64 40}
!20 = !{!7, !7, i64 0}


; 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
define dso_local void @_tr_stored_block(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 5924
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 13
  %8 = shl i32 %3, %6
  %9 = getelementptr inbounds i8, ptr %0, i64 5920
  %10 = load i16, ptr %9, align 8, !tbaa !14
  %11 = trunc i32 %8 to i16
  %12 = or i16 %10, %11
  store i16 %12, ptr %9, align 8, !tbaa !14
  br i1 %7, label %13, label %36

13:                                               ; preds = %4
  %14 = trunc i16 %12 to i8
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %0, i64 40
  %18 = load i32, ptr %17, align 8, !tbaa !16
  %19 = add i32 %18, 1
  store i32 %19, ptr %17, align 8, !tbaa !16
  %20 = zext i32 %18 to i64
  %21 = getelementptr inbounds i8, ptr %16, i64 %20
  store i8 %14, ptr %21, align 1, !tbaa !17
  %22 = load i16, ptr %9, align 8, !tbaa !14
  %23 = lshr i16 %22, 8
  %24 = trunc nuw i16 %23 to i8
  %25 = load ptr, ptr %15, align 8, !tbaa !15
  %26 = load i32, ptr %17, align 8, !tbaa !16
  %27 = add i32 %26, 1
  store i32 %27, ptr %17, align 8, !tbaa !16
  %28 = zext i32 %26 to i64
  %29 = getelementptr inbounds i8, ptr %25, i64 %28
  store i8 %24, ptr %29, align 1, !tbaa !17
  %30 = and i32 %3, 65535
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = sub i32 16, %31
  %33 = lshr i32 %30, %32
  %34 = trunc nuw i32 %33 to i16
  store i16 %34, ptr %9, align 8, !tbaa !14
  %35 = add i32 %31, -13
  br label %38

36:                                               ; preds = %4
  %37 = add nsw i32 %6, 3
  br label %38

38:                                               ; preds = %36, %13
  %storemerge = phi i32 [ %37, %36 ], [ %35, %13 ]
  store i32 %storemerge, ptr %5, align 4, !tbaa !5
  %39 = trunc i64 %2 to i32
  tail call void @copy_block(ptr noundef nonnull %0, ptr noundef %1, i32 noundef %39, i32 noundef 1)
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @copy_block(ptr noundef, ptr noundef, i32 noundef, i32 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, !10, i64 5924}
!6 = !{!"internal_state", !7, i64 0, !10, i64 8, !7, i64 16, !11, i64 24, !7, i64 32, !10, i64 40, !10, i64 44, !7, i64 48, !10, i64 56, !8, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !7, i64 80, !11, i64 88, !7, i64 96, !7, i64 104, !10, i64 112, !10, i64 116, !10, i64 120, !10, i64 124, !10, i64 128, !11, i64 136, !10, i64 144, !10, i64 148, !10, i64 152, !10, i64 156, !10, i64 160, !10, i64 164, !10, i64 168, !10, i64 172, !10, i64 176, !10, i64 180, !10, i64 184, !10, i64 188, !10, i64 192, !8, i64 196, !8, i64 2488, !8, i64 2732, !12, i64 2888, !12, i64 2912, !12, i64 2936, !8, i64 2960, !8, i64 2992, !10, i64 5284, !10, i64 5288, !8, i64 5292, !7, i64 5872, !10, i64 5880, !10, i64 5884, !7, i64 5888, !11, i64 5896, !11, i64 5904, !10, i64 5912, !10, i64 5916, !13, i64 5920, !10, i64 5924}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"tree_desc_s", !7, i64 0, !10, i64 8, !7, i64 16}
!13 = !{!"short", !8, i64 0}
!14 = !{!6, !13, i64 5920}
!15 = !{!6, !7, i64 16}
!16 = !{!6, !10, i64 40}
!17 = !{!8, !8, i64 0}


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