; LLVM IR from JayXon/Leanify :: lib/zopflipng/zopflipng_lib.ll (Z16CustomPNGDeflatePPhPmPKhmPK23LodePNGCompressSettings)

; 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.ZopfliOptions = type { i32, i32, i32, i32, i32, i32 }
%struct.LodePNGCompressSettings = type { i32, i32, i32, i32, i32, i32, ptr, ptr, ptr }
%struct.ZopfliPNGOptions = type { i8, i8, i8, %"class.std::vector", i8, %"class.std::vector.0", i8, i32, i32, i32 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<ZopfliPNGFilterStrategy, std::allocator<ZopfliPNGFilterStrategy>>::_Vector_impl" }
%"struct.std::_Vector_base<ZopfliPNGFilterStrategy, std::allocator<ZopfliPNGFilterStrategy>>::_Vector_impl" = type { %"struct.std::_Vector_base<ZopfliPNGFilterStrategy, std::allocator<ZopfliPNGFilterStrategy>>::_Vector_impl_data" }
%"struct.std::_Vector_base<ZopfliPNGFilterStrategy, std::allocator<ZopfliPNGFilterStrategy>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z16CustomPNGDeflatePPhPmPKhmPK23LodePNGCompressSettings(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i8, align 1
  %13 = alloca %struct.ZopfliOptions, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %14 = load ptr, ptr %10, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.LodePNGCompressSettings, ptr %14, i32 0, i32 8
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  store ptr %16, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #3
  store i8 0, ptr %12, align 1, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 24, ptr %13) #3
  call void @ZopfliInitOptions(ptr noundef %13)
  %17 = load ptr, ptr %11, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ZopfliPNGOptions, ptr %17, i32 0, i32 0
  %19 = load i8, ptr %18, align 8, !tbaa !15, !range !26, !noundef !27
  %20 = trunc i8 %19 to i1
  %21 = zext i1 %20 to i32
  %22 = getelementptr inbounds %struct.ZopfliOptions, ptr %13, i32 0, i32 0
  store i32 %21, ptr %22, align 4, !tbaa !28
  %23 = load i64, ptr %9, align 8, !tbaa !9
  %24 = icmp ult i64 %23, 200000
  br i1 %24, label %25, label %29

25:                                               ; preds = %5
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ZopfliPNGOptions, ptr %26, i32 0, i32 7
  %28 = load i32, ptr %27, align 4, !tbaa !30
  br label %33

29:                                               ; preds = %5
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ZopfliPNGOptions, ptr %30, i32 0, i32 8
  %32 = load i32, ptr %31, align 8, !tbaa !31
  br label %33

33:                                               ; preds = %29, %25
  %34 = phi i32 [ %28, %25 ], [ %32, %29 ]
  %35 = getelementptr inbounds %struct.ZopfliOptions, ptr %13, i32 0, i32 2
  store i32 %34, ptr %35, align 4, !tbaa !32
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load i64, ptr %9, align 8, !tbaa !9
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ZopfliDeflate(ptr noundef %13, i32 noundef 2, i32 noundef 1, ptr noundef %36, i64 noundef %37, ptr noundef %12, ptr noundef %38, ptr noundef %39)
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret i32 0
}

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

declare void @ZopfliInitOptions(ptr noundef) #2

declare void @ZopfliDeflate(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) #2

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

attributes #0 = { mustprogress 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 = { "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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 40}
!12 = !{!"_ZTS23LodePNGCompressSettings", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !6, i64 24, !6, i64 32, !6, i64 40}
!13 = !{!"int", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !17, i64 0}
!16 = !{!"_ZTS16ZopfliPNGOptions", !17, i64 0, !17, i64 1, !17, i64 2, !18, i64 8, !17, i64 32, !22, i64 40, !17, i64 64, !13, i64 68, !13, i64 72, !13, i64 76}
!17 = !{!"bool", !7, i64 0}
!18 = !{!"_ZTSSt6vectorI23ZopfliPNGFilterStrategySaIS0_EE", !19, i64 0}
!19 = !{!"_ZTSSt12_Vector_baseI23ZopfliPNGFilterStrategySaIS0_EE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseI23ZopfliPNGFilterStrategySaIS0_EE12_Vector_implE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseI23ZopfliPNGFilterStrategySaIS0_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!22 = !{!"_ZTSSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE", !23, i64 0}
!23 = !{!"_ZTSSt12_Vector_baseINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE", !24, i64 0}
!24 = !{!"_ZTSNSt12_Vector_baseINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE12_Vector_implE", !25, i64 0}
!25 = !{!"_ZTSNSt12_Vector_baseINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = !{!29, !13, i64 0}
!29 = !{!"_ZTS13ZopfliOptions", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!30 = !{!16, !13, i64 68}
!31 = !{!16, !13, i64 72}
!32 = !{!29, !13, i64 8}


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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z16CustomPNGDeflatePPhPmPKhmPK23LodePNGCompressSettings(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr nocapture noundef readonly %4) local_unnamed_addr #0 {
  %6 = alloca i8, align 1
  %7 = alloca %struct.ZopfliOptions, align 4
  %8 = getelementptr inbounds i8, ptr %4, i64 40
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %6) #3
  store i8 0, ptr %6, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %7) #3
  call void @ZopfliInitOptions(ptr noundef nonnull %7)
  %10 = load i8, ptr %9, align 8, !tbaa !12, !range !23, !noundef !24
  %11 = zext nneg i8 %10 to i32
  store i32 %11, ptr %7, align 4, !tbaa !25
  %12 = icmp ult i64 %3, 200000
  %.in.v = select i1 %12, i64 68, i64 72
  %.in = getelementptr inbounds i8, ptr %9, i64 %.in.v
  %13 = load i32, ptr %.in, align 4, !tbaa !27
  %14 = getelementptr inbounds i8, ptr %7, i64 8
  store i32 %13, ptr %14, align 4, !tbaa !28
  call void @ZopfliDeflate(ptr noundef nonnull %7, i32 noundef 2, i32 noundef 1, ptr noundef %2, i64 noundef %3, ptr noundef nonnull %6, ptr noundef %0, ptr noundef %1)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %6) #3
  ret i32 0
}

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

declare void @ZopfliInitOptions(ptr noundef) local_unnamed_addr #2

declare void @ZopfliDeflate(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !10, i64 40}
!6 = !{!"_ZTS23LodePNGCompressSettings", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !10, i64 24, !10, i64 32, !10, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"_ZTS16ZopfliPNGOptions", !14, i64 0, !14, i64 1, !14, i64 2, !15, i64 8, !14, i64 32, !19, i64 40, !14, i64 64, !7, i64 68, !7, i64 72, !7, i64 76}
!14 = !{!"bool", !8, i64 0}
!15 = !{!"_ZTSSt6vectorI23ZopfliPNGFilterStrategySaIS0_EE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseI23ZopfliPNGFilterStrategySaIS0_EE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseI23ZopfliPNGFilterStrategySaIS0_EE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseI23ZopfliPNGFilterStrategySaIS0_EE17_Vector_impl_dataE", !10, i64 0, !10, i64 8, !10, i64 16}
!19 = !{!"_ZTSSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE", !20, i64 0}
!20 = !{!"_ZTSSt12_Vector_baseINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE12_Vector_implE", !22, i64 0}
!22 = !{!"_ZTSNSt12_Vector_baseINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE17_Vector_impl_dataE", !10, i64 0, !10, i64 8, !10, i64 16}
!23 = !{i8 0, i8 2}
!24 = !{}
!25 = !{!26, !7, i64 0}
!26 = !{!"_ZTS13ZopfliOptions", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!27 = !{!7, !7, i64 0}
!28 = !{!26, !7, i64 8}


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