; LLVM IR from niessner/Matterport :: code/gaps/pkgs/png (deflate)

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

@configuration_table = external hidden constant [10 x %struct.config_s], align 16

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

; 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 @deflateParams(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %19, label %14

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.z_stream_s, ptr %15, i32 0, i32 7
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %14, %3
  store i32 -2, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %116

20:                                               ; preds = %14
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.z_stream_s, ptr %21, i32 0, i32 7
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  store ptr %23, ptr %8, align 8, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = icmp eq i32 %24, -1
  br i1 %25, label %26, label %27

26:                                               ; preds = %20
  store i32 6, ptr %6, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %26, %20
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = icmp slt i32 %28, 0
  br i1 %29, label %39, label %30

30:                                               ; preds = %27
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = icmp sgt i32 %31, 9
  br i1 %32, label %39, label %33

33:                                               ; preds = %30
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %39, label %36

36:                                               ; preds = %33
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = icmp sgt i32 %37, 4
  br i1 %38, label %39, label %40

39:                                               ; preds = %36, %33, %30, %27
  store i32 -2, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %116

40:                                               ; preds = %36
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.internal_state, ptr %41, i32 0, i32 33
  %43 = load i32, ptr %42, align 4, !tbaa !14
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [10 x %struct.config_s], ptr @configuration_table, i64 0, i64 %44
  %46 = getelementptr inbounds %struct.config_s, ptr %45, i32 0, i32 4
  %47 = load ptr, ptr %46, align 8, !tbaa !18
  store ptr %47, ptr %9, align 8, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.internal_state, ptr %49, i32 0, i32 34
  %51 = load i32, ptr %50, align 8, !tbaa !20
  %52 = icmp ne i32 %48, %51
  br i1 %52, label %61, label %53

53:                                               ; preds = %40
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [10 x %struct.config_s], ptr @configuration_table, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.config_s, ptr %57, i32 0, i32 4
  %59 = load ptr, ptr %58, align 8, !tbaa !18
  %60 = icmp ne ptr %54, %59
  br i1 %60, label %61, label %69

61:                                               ; preds = %53, %40
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.z_stream_s, ptr %62, i32 0, i32 2
  %64 = load i64, ptr %63, align 8, !tbaa !21
  %65 = icmp ne i64 %64, 0
  br i1 %65, label %66, label %69

66:                                               ; preds = %61
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = call i32 @deflate(ptr noundef %67, i32 noundef 5)
  store i32 %68, ptr %10, align 4, !tbaa !9
  br label %69

69:                                               ; preds = %66, %61, %53
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.internal_state, ptr %70, i32 0, i32 33
  %72 = load i32, ptr %71, align 4, !tbaa !14
  %73 = load i32, ptr %6, align 4, !tbaa !9
  %74 = icmp ne i32 %72, %73
  br i1 %74, label %75, label %111

75:                                               ; preds = %69
  %76 = load i32, ptr %6, align 4, !tbaa !9
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.internal_state, ptr %77, i32 0, i32 33
  store i32 %76, ptr %78, align 4, !tbaa !14
  %79 = load i32, ptr %6, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [10 x %struct.config_s], ptr @configuration_table, i64 0, i64 %80
  %82 = getelementptr inbounds %struct.config_s, ptr %81, i32 0, i32 1
  %83 = load i16, ptr %82, align 2, !tbaa !22
  %84 = zext i16 %83 to i32
  %85 = load ptr, ptr %8, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.internal_state, ptr %85, i32 0, i32 32
  store i32 %84, ptr %86, align 8, !tbaa !23
  %87 = load i32, ptr %6, align 4, !tbaa !9
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [10 x %struct.config_s], ptr @configuration_table, i64 0, i64 %88
  %90 = getelementptr inbounds %struct.config_s, ptr %89, i32 0, i32 0
  %91 = load i16, ptr %90, align 16, !tbaa !24
  %92 = zext i16 %91 to i32
  %93 = load ptr, ptr %8, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.internal_state, ptr %93, i32 0, i32 35
  store i32 %92, ptr %94, align 4, !tbaa !25
  %95 = load i32, ptr %6, align 4, !tbaa !9
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [10 x %struct.config_s], ptr @configuration_table, i64 0, i64 %96
  %98 = getelementptr inbounds %struct.config_s, ptr %97, i32 0, i32 2
  %99 = load i16, ptr %98, align 4, !tbaa !26
  %100 = zext i16 %99 to i32
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.internal_state, ptr %101, i32 0, i32 36
  store i32 %100, ptr %102, align 8, !tbaa !27
  %103 = load i32, ptr %6, align 4, !tbaa !9
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [10 x %struct.config_s], ptr @configuration_table, i64 0, i64 %104
  %106 = getelementptr inbounds %struct.config_s, ptr %105, i32 0, i32 3
  %107 = load i16, ptr %106, align 2, !tbaa !28
  %108 = zext i16 %107 to i32
  %109 = load ptr, ptr %8, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.internal_state, ptr %109, i32 0, i32 31
  store i32 %108, ptr %110, align 4, !tbaa !29
  br label %111

111:                                              ; preds = %75, %69
  %112 = load i32, ptr %7, align 4, !tbaa !9
  %113 = load ptr, ptr %8, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.internal_state, ptr %113, i32 0, i32 34
  store i32 %112, ptr %114, align 8, !tbaa !20
  %115 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %115, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %116

116:                                              ; preds = %111, %39, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %117 = load i32, ptr %4, align 4
  ret i32 %117
}

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

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 = !{!"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, !6, i64 56}
!12 = !{!"z_stream_s", !6, i64 0, !10, i64 8, !13, i64 16, !6, i64 24, !10, i64 32, !13, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !13, i64 96, !13, i64 104}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !10, i64 180}
!15 = !{!"internal_state", !6, i64 0, !10, i64 8, !6, i64 16, !13, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !6, i64 48, !10, i64 56, !7, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !6, i64 80, !13, i64 88, !6, i64 96, !6, i64 104, !10, i64 112, !10, i64 116, !10, i64 120, !10, i64 124, !10, i64 128, !13, 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, !7, i64 196, !7, i64 2488, !7, i64 2732, !16, i64 2888, !16, i64 2912, !16, i64 2936, !7, i64 2960, !7, i64 2992, !10, i64 5284, !10, i64 5288, !7, i64 5292, !6, i64 5872, !10, i64 5880, !10, i64 5884, !6, i64 5888, !13, i64 5896, !13, i64 5904, !10, i64 5912, !10, i64 5916, !17, i64 5920, !10, i64 5924, !13, i64 5928}
!16 = !{!"tree_desc_s", !6, i64 0, !10, i64 8, !6, i64 16}
!17 = !{!"short", !7, i64 0}
!18 = !{!19, !6, i64 8}
!19 = !{!"config_s", !17, i64 0, !17, i64 2, !17, i64 4, !17, i64 6, !6, i64 8}
!20 = !{!15, !10, i64 184}
!21 = !{!12, !13, i64 16}
!22 = !{!19, !17, i64 2}
!23 = !{!15, !10, i64 176}
!24 = !{!19, !17, i64 0}
!25 = !{!15, !10, i64 188}
!26 = !{!19, !17, i64 4}
!27 = !{!15, !10, i64 192}
!28 = !{!19, !17, i64 6}
!29 = !{!15, !10, i64 172}


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

%struct.config_s = type { i16, i16, i16, i16, ptr }

@configuration_table = external hidden local_unnamed_addr constant [10 x %struct.config_s], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @deflateParams(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %50, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 56
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %50, label %9

9:                                                ; preds = %5
  %10 = icmp eq i32 %1, -1
  %spec.store.select = select i1 %10, i32 6, i32 %1
  %or.cond = icmp ugt i32 %spec.store.select, 9
  %11 = icmp ugt i32 %2, 4
  %or.cond5 = or i1 %11, %or.cond
  br i1 %or.cond5, label %50, label %12

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %7, i64 180
  %14 = getelementptr inbounds i8, ptr %7, i64 184
  %15 = load i32, ptr %14, align 8, !tbaa !12
  %.not = icmp eq i32 %15, %2
  br i1 %.not, label %16, label %24

16:                                               ; preds = %12
  %17 = load i32, ptr %13, align 4, !tbaa !16
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [10 x %struct.config_s], ptr @configuration_table, i64 0, i64 %18, i32 4
  %20 = load ptr, ptr %19, align 8, !tbaa !17
  %21 = zext nneg i32 %spec.store.select to i64
  %22 = getelementptr inbounds [10 x %struct.config_s], ptr @configuration_table, i64 0, i64 %21, i32 4
  %23 = load ptr, ptr %22, align 8, !tbaa !17
  %.not39 = icmp eq ptr %20, %23
  br i1 %.not39, label %29, label %24

24:                                               ; preds = %16, %12
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  %26 = load i64, ptr %25, align 8, !tbaa !19
  %.not40 = icmp eq i64 %26, 0
  br i1 %.not40, label %29, label %27

27:                                               ; preds = %24
  %28 = tail call i32 @deflate(ptr noundef nonnull %0, i32 noundef 5)
  br label %29

29:                                               ; preds = %27, %24, %16
  %.0 = phi i32 [ %28, %27 ], [ 0, %24 ], [ 0, %16 ]
  %30 = load i32, ptr %13, align 4, !tbaa !16
  %.not41 = icmp eq i32 %30, %spec.store.select
  br i1 %.not41, label %49, label %31

31:                                               ; preds = %29
  store i32 %spec.store.select, ptr %13, align 4, !tbaa !16
  %32 = zext nneg i32 %spec.store.select to i64
  %33 = getelementptr inbounds [10 x %struct.config_s], ptr @configuration_table, i64 0, i64 %32
  %34 = getelementptr inbounds i8, ptr %33, i64 2
  %35 = load i16, ptr %34, align 2, !tbaa !20
  %36 = zext i16 %35 to i32
  %37 = getelementptr inbounds i8, ptr %7, i64 176
  store i32 %36, ptr %37, align 8, !tbaa !21
  %38 = load i16, ptr %33, align 16, !tbaa !22
  %39 = zext i16 %38 to i32
  %40 = getelementptr inbounds i8, ptr %7, i64 188
  store i32 %39, ptr %40, align 4, !tbaa !23
  %41 = getelementptr inbounds i8, ptr %33, i64 4
  %42 = load i16, ptr %41, align 4, !tbaa !24
  %43 = zext i16 %42 to i32
  %44 = getelementptr inbounds i8, ptr %7, i64 192
  store i32 %43, ptr %44, align 8, !tbaa !25
  %45 = getelementptr inbounds i8, ptr %33, i64 6
  %46 = load i16, ptr %45, align 2, !tbaa !26
  %47 = zext i16 %46 to i32
  %48 = getelementptr inbounds i8, ptr %7, i64 172
  store i32 %47, ptr %48, align 4, !tbaa !27
  br label %49

49:                                               ; preds = %31, %29
  store i32 %2, ptr %14, align 8, !tbaa !12
  br label %50

50:                                               ; preds = %9, %3, %5, %49
  %.035 = phi i32 [ %.0, %49 ], [ -2, %5 ], [ -2, %3 ], [ -2, %9 ]
  ret i32 %.035
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @deflate(ptr 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, !7, i64 56}
!6 = !{!"z_stream_s", !7, i64 0, !10, i64 8, !11, i64 16, !7, i64 24, !10, i64 32, !11, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !10, i64 88, !11, i64 96, !11, i64 104}
!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 = !{!13, !10, i64 184}
!13 = !{!"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, !14, i64 2888, !14, i64 2912, !14, 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, !15, i64 5920, !10, i64 5924, !11, i64 5928}
!14 = !{!"tree_desc_s", !7, i64 0, !10, i64 8, !7, i64 16}
!15 = !{!"short", !8, i64 0}
!16 = !{!13, !10, i64 180}
!17 = !{!18, !7, i64 8}
!18 = !{!"config_s", !15, i64 0, !15, i64 2, !15, i64 4, !15, i64 6, !7, i64 8}
!19 = !{!6, !11, i64 16}
!20 = !{!18, !15, i64 2}
!21 = !{!13, !10, i64 176}
!22 = !{!18, !15, i64 0}
!23 = !{!13, !10, i64 188}
!24 = !{!18, !15, i64 4}
!25 = !{!13, !10, i64 192}
!26 = !{!18, !15, i64 6}
!27 = !{!13, !10, i64 172}


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