; LLVM IR from mkazhdan/DMG :: Util/ZLIB (inftrees)

; 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.z_stream_s = type { ptr, i32, i64, ptr, i32, i64, ptr, ptr, ptr, ptr, ptr, i32, i64, i64 }

@cplens = external hidden constant [31 x i32], align 16
@cplext = external hidden constant [31 x i32], align 16
@.str.2 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [31 x i8], align 1
@cpdist = external hidden constant [30 x i32], align 16
@cpdext = external hidden constant [30 x i32], align 16
@.str.4 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [33 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @huft_build(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @inflate_trees_dynamic(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8) #1 {
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca ptr, align 8
  %23 = alloca i32, align 4
  store i32 %0, ptr %11, align 4, !tbaa !5
  store i32 %1, ptr %12, align 4, !tbaa !5
  store ptr %2, ptr %13, align 8, !tbaa !9
  store ptr %3, ptr %14, align 8, !tbaa !9
  store ptr %4, ptr %15, align 8, !tbaa !9
  store ptr %5, ptr %16, align 8, !tbaa !9
  store ptr %6, ptr %17, align 8, !tbaa !9
  store ptr %7, ptr %18, align 8, !tbaa !9
  store ptr %8, ptr %19, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #2
  store i32 0, ptr %21, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #2
  %24 = load ptr, ptr %19, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.z_stream_s, ptr %24, i32 0, i32 8
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = load ptr, ptr %19, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.z_stream_s, ptr %27, i32 0, i32 10
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = call ptr %26(ptr noundef %29, i32 noundef 288, i32 noundef 4)
  store ptr %30, ptr %22, align 8, !tbaa !9
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %33

32:                                               ; preds = %9
  store i32 -4, ptr %10, align 4
  store i32 1, ptr %23, align 4
  br label %126

33:                                               ; preds = %9
  %34 = load ptr, ptr %13, align 8, !tbaa !9
  %35 = load i32, ptr %11, align 4, !tbaa !5
  %36 = load ptr, ptr %16, align 8, !tbaa !9
  %37 = load ptr, ptr %14, align 8, !tbaa !9
  %38 = load ptr, ptr %18, align 8, !tbaa !9
  %39 = load ptr, ptr %22, align 8, !tbaa !9
  %40 = call i32 @huft_build(ptr noundef %34, i32 noundef %35, i32 noundef 257, ptr noundef @cplens, ptr noundef @cplext, ptr noundef %36, ptr noundef %37, ptr noundef %38, ptr noundef %21, ptr noundef %39)
  store i32 %40, ptr %20, align 4, !tbaa !5
  %41 = load i32, ptr %20, align 4, !tbaa !5
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %47, label %43

43:                                               ; preds = %33
  %44 = load ptr, ptr %14, align 8, !tbaa !9
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = icmp eq i32 %45, 0
  br i1 %46, label %47, label %69

47:                                               ; preds = %43, %33
  %48 = load i32, ptr %20, align 4, !tbaa !5
  %49 = icmp eq i32 %48, -3
  br i1 %49, label %50, label %53

50:                                               ; preds = %47
  %51 = load ptr, ptr %19, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.z_stream_s, ptr %51, i32 0, i32 6
  store ptr @.str.2, ptr %52, align 8, !tbaa !15
  br label %60

53:                                               ; preds = %47
  %54 = load i32, ptr %20, align 4, !tbaa !5
  %55 = icmp ne i32 %54, -4
  br i1 %55, label %56, label %59

56:                                               ; preds = %53
  %57 = load ptr, ptr %19, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.z_stream_s, ptr %57, i32 0, i32 6
  store ptr @.str.3, ptr %58, align 8, !tbaa !15
  store i32 -3, ptr %20, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %56, %53
  br label %60

60:                                               ; preds = %59, %50
  %61 = load ptr, ptr %19, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.z_stream_s, ptr %61, i32 0, i32 9
  %63 = load ptr, ptr %62, align 8, !tbaa !16
  %64 = load ptr, ptr %19, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.z_stream_s, ptr %64, i32 0, i32 10
  %66 = load ptr, ptr %65, align 8, !tbaa !14
  %67 = load ptr, ptr %22, align 8, !tbaa !9
  call void %63(ptr noundef %66, ptr noundef %67)
  %68 = load i32, ptr %20, align 4, !tbaa !5
  store i32 %68, ptr %10, align 4
  store i32 1, ptr %23, align 4
  br label %126

69:                                               ; preds = %43
  %70 = load ptr, ptr %13, align 8, !tbaa !9
  %71 = load i32, ptr %11, align 4, !tbaa !5
  %72 = zext i32 %71 to i64
  %73 = getelementptr inbounds i32, ptr %70, i64 %72
  %74 = load i32, ptr %12, align 4, !tbaa !5
  %75 = load ptr, ptr %17, align 8, !tbaa !9
  %76 = load ptr, ptr %15, align 8, !tbaa !9
  %77 = load ptr, ptr %18, align 8, !tbaa !9
  %78 = load ptr, ptr %22, align 8, !tbaa !9
  %79 = call i32 @huft_build(ptr noundef %73, i32 noundef %74, i32 noundef 0, ptr noundef @cpdist, ptr noundef @cpdext, ptr noundef %75, ptr noundef %76, ptr noundef %77, ptr noundef %21, ptr noundef %78)
  store i32 %79, ptr %20, align 4, !tbaa !5
  %80 = load i32, ptr %20, align 4, !tbaa !5
  %81 = icmp ne i32 %80, 0
  br i1 %81, label %89, label %82

82:                                               ; preds = %69
  %83 = load ptr, ptr %15, align 8, !tbaa !9
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = icmp eq i32 %84, 0
  br i1 %85, label %86, label %118

86:                                               ; preds = %82
  %87 = load i32, ptr %11, align 4, !tbaa !5
  %88 = icmp ugt i32 %87, 257
  br i1 %88, label %89, label %118

89:                                               ; preds = %86, %69
  %90 = load i32, ptr %20, align 4, !tbaa !5
  %91 = icmp eq i32 %90, -3
  br i1 %91, label %92, label %95

92:                                               ; preds = %89
  %93 = load ptr, ptr %19, align 8, !tbaa !9
  %94 = getelementptr inbounds %struct.z_stream_s, ptr %93, i32 0, i32 6
  store ptr @.str.4, ptr %94, align 8, !tbaa !15
  br label %109

95:                                               ; preds = %89
  %96 = load i32, ptr %20, align 4, !tbaa !5
  %97 = icmp eq i32 %96, -5
  br i1 %97, label %98, label %101

98:                                               ; preds = %95
  %99 = load ptr, ptr %19, align 8, !tbaa !9
  %100 = getelementptr inbounds %struct.z_stream_s, ptr %99, i32 0, i32 6
  store ptr @.str.5, ptr %100, align 8, !tbaa !15
  store i32 -3, ptr %20, align 4, !tbaa !5
  br label %108

101:                                              ; preds = %95
  %102 = load i32, ptr %20, align 4, !tbaa !5
  %103 = icmp ne i32 %102, -4
  br i1 %103, label %104, label %107

104:                                              ; preds = %101
  %105 = load ptr, ptr %19, align 8, !tbaa !9
  %106 = getelementptr inbounds %struct.z_stream_s, ptr %105, i32 0, i32 6
  store ptr @.str.6, ptr %106, align 8, !tbaa !15
  store i32 -3, ptr %20, align 4, !tbaa !5
  br label %107

107:                                              ; preds = %104, %101
  br label %108

108:                                              ; preds = %107, %98
  br label %109

109:                                              ; preds = %108, %92
  %110 = load ptr, ptr %19, align 8, !tbaa !9
  %111 = getelementptr inbounds %struct.z_stream_s, ptr %110, i32 0, i32 9
  %112 = load ptr, ptr %111, align 8, !tbaa !16
  %113 = load ptr, ptr %19, align 8, !tbaa !9
  %114 = getelementptr inbounds %struct.z_stream_s, ptr %113, i32 0, i32 10
  %115 = load ptr, ptr %114, align 8, !tbaa !14
  %116 = load ptr, ptr %22, align 8, !tbaa !9
  call void %112(ptr noundef %115, ptr noundef %116)
  %117 = load i32, ptr %20, align 4, !tbaa !5
  store i32 %117, ptr %10, align 4
  store i32 1, ptr %23, align 4
  br label %126

118:                                              ; preds = %86, %82
  %119 = load ptr, ptr %19, align 8, !tbaa !9
  %120 = getelementptr inbounds %struct.z_stream_s, ptr %119, i32 0, i32 9
  %121 = load ptr, ptr %120, align 8, !tbaa !16
  %122 = load ptr, ptr %19, align 8, !tbaa !9
  %123 = getelementptr inbounds %struct.z_stream_s, ptr %122, i32 0, i32 10
  %124 = load ptr, ptr %123, align 8, !tbaa !14
  %125 = load ptr, ptr %22, align 8, !tbaa !9
  call void %121(ptr noundef %124, ptr noundef %125)
  store i32 0, ptr %10, align 4
  store i32 1, ptr %23, align 4
  br label %126

126:                                              ; preds = %118, %109, %60, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #2
  %127 = load i32, ptr %10, align 4
  ret i32 %127
}

attributes #0 = { nocallback nofree nosync 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 64}
!12 = !{!"z_stream_s", !10, i64 0, !6, i64 8, !13, i64 16, !10, i64 24, !6, i64 32, !13, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !6, i64 88, !13, i64 96, !13, i64 104}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !10, i64 80}
!15 = !{!12, !10, i64 48}
!16 = !{!12, !10, i64 72}


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

@cplens = external hidden constant [31 x i32], align 16
@cplext = external hidden constant [31 x i32], align 16
@.str.2 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [31 x i8], align 1
@cpdist = external hidden constant [30 x i32], align 16
@cpdext = external hidden constant [30 x i32], align 16
@.str.4 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [33 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @huft_build(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -4, 1) i32 @inflate_trees_dynamic(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7, ptr nocapture noundef %8) local_unnamed_addr #1 {
  %10 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %10) #2
  store i32 0, ptr %10, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %8, i64 64
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %8, i64 80
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = tail call ptr %12(ptr noundef %14, i32 noundef 288, i32 noundef 4) #2
  %16 = icmp eq ptr %15, null
  br i1 %16, label %37, label %17

17:                                               ; preds = %9
  %18 = call i32 @huft_build(ptr noundef %2, i32 noundef %0, i32 noundef 257, ptr noundef nonnull @cplens, ptr noundef nonnull @cplext, ptr noundef %5, ptr noundef %3, ptr noundef %7, ptr noundef nonnull %10, ptr noundef nonnull %15)
  switch i32 %18, label %22 [
    i32 0, label %19
    i32 -3, label %.sink.split52.sink.split
    i32 -4, label %.sink.split52
  ]

19:                                               ; preds = %17
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %19, %17
  br label %.sink.split52.sink.split

23:                                               ; preds = %19
  %24 = zext i32 %0 to i64
  %25 = getelementptr inbounds i32, ptr %2, i64 %24
  %26 = call i32 @huft_build(ptr noundef %25, i32 noundef %1, i32 noundef 0, ptr noundef nonnull @cpdist, ptr noundef nonnull @cpdext, ptr noundef %6, ptr noundef %4, ptr noundef %7, ptr noundef nonnull %10, ptr noundef nonnull %15)
  switch i32 %26, label %32 [
    i32 0, label %27
    i32 -3, label %.sink.split52.sink.split
    i32 -5, label %31
    i32 -4, label %.sink.split52
  ]

27:                                               ; preds = %23
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 0
  %30 = icmp ugt i32 %0, 257
  %or.cond = and i1 %30, %29
  br i1 %or.cond, label %32, label %.sink.split52

31:                                               ; preds = %23
  br label %.sink.split52.sink.split

32:                                               ; preds = %27, %23
  br label %.sink.split52.sink.split

.sink.split52.sink.split:                         ; preds = %31, %32, %23, %22, %17
  %.str.5.sink.sink = phi ptr [ @.str.3, %22 ], [ @.str.2, %17 ], [ @.str.5, %31 ], [ @.str.6, %32 ], [ @.str.4, %23 ]
  %33 = getelementptr inbounds i8, ptr %8, i64 48
  store ptr %.str.5.sink.sink, ptr %33, align 8, !tbaa !14
  br label %.sink.split52

.sink.split52:                                    ; preds = %.sink.split52.sink.split, %27, %23, %17
  %.0.ph = phi i32 [ %18, %17 ], [ %26, %23 ], [ 0, %27 ], [ -3, %.sink.split52.sink.split ]
  %34 = getelementptr inbounds i8, ptr %8, i64 72
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  %36 = load ptr, ptr %13, align 8, !tbaa !13
  call void %35(ptr noundef %36, ptr noundef nonnull %15) #2
  br label %37

37:                                               ; preds = %.sink.split52, %9
  %.0 = phi i32 [ -4, %9 ], [ %.0.ph, %.sink.split52 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %10) #2
  ret i32 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 64}
!10 = !{!"z_stream_s", !11, i64 0, !6, i64 8, !12, i64 16, !11, i64 24, !6, i64 32, !12, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !6, i64 88, !12, i64 96, !12, i64 104}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !11, i64 80}
!14 = !{!10, !11, i64 48}
!15 = !{!10, !11, i64 72}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass