; LLVM IR from sp-nitech/SPTK :: src/math (minmax_accumulation)

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

%"class.std::reverse_iterator" = type { %"struct.std::_Rb_tree_const_iterator" }
%"struct.std::_Rb_tree_const_iterator" = type { ptr }
%"class.sptk::MinMaxAccumulation::Buffer" = type { ptr, i32, %"class.std::multimap", %"class.std::multimap.0" }
%"class.std::multimap" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<double, std::pair<const double, int>, std::_Select1st<std::pair<const double, int>>, std::greater<double>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<double, std::pair<const double, int>, std::_Select1st<std::pair<const double, int>>, std::greater<double>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"class.std::multimap.0" = type { %"class.std::_Rb_tree.1" }
%"class.std::_Rb_tree.1" = type { %"struct.std::_Rb_tree<double, std::pair<const double, int>, std::_Select1st<std::pair<const double, int>>, std::less<double>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<double, std::pair<const double, int>, std::_Select1st<std::pair<const double, int>>, std::less<double>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::pair" = type <{ double, i32, [4 x i8] }>

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt7advanceISt16reverse_iteratorISt23_Rb_tree_const_iteratorISt4pairIKdiEEEiEvRT_T0_(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZNKSt16reverse_iteratorISt23_Rb_tree_const_iteratorISt4pairIKdiEEEptEv(ptr noundef nonnull align 8 dereferenceable(8)) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK4sptk18MinMaxAccumulation10GetMaximumEiRKNS0_6BufferEPdPi(ptr noundef nonnull align 8 dereferenceable(13) %0, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(112) %2, ptr noundef %3, ptr noundef %4) #2 align 2 {
  %6 = alloca i1, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca %"class.std::reverse_iterator", align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %13 = load ptr, ptr %7, align 8
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = icmp sle i32 %14, 0
  br i1 %15, label %23, label %16

16:                                               ; preds = %5
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = getelementptr inbounds %"class.sptk::MinMaxAccumulation::Buffer", ptr %17, i32 0, i32 3
  %19 = call noundef i64 @_ZNKSt8multimapIdiSt4lessIdESaISt4pairIKdiEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(48) %18) #4
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = icmp ult i64 %19, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %16, %5
  store i1 false, ptr %6, align 1
  br label %45

24:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = getelementptr inbounds %"class.sptk::MinMaxAccumulation::Buffer", ptr %25, i32 0, i32 3
  call void @_ZNKSt8multimapIdiSt4lessIdESaISt4pairIKdiEEE6rbeginEv(ptr dead_on_unwind writable sret(%"class.std::reverse_iterator") align 8 %12, ptr noundef nonnull align 8 dereferenceable(48) %26) #4
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = sub nsw i32 %27, 1
  call void @_ZSt7advanceISt16reverse_iteratorISt23_Rb_tree_const_iteratorISt4pairIKdiEEEiEvRT_T0_(ptr noundef nonnull align 8 dereferenceable(8) %12, i32 noundef %28)
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = icmp ne ptr null, %29
  br i1 %30, label %31, label %36

31:                                               ; preds = %24
  %32 = call noundef ptr @_ZNKSt16reverse_iteratorISt23_Rb_tree_const_iteratorISt4pairIKdiEEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %12)
  %33 = getelementptr inbounds %"struct.std::pair", ptr %32, i32 0, i32 0
  %34 = load double, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  store double %34, ptr %35, align 8, !tbaa !14
  br label %36

36:                                               ; preds = %31, %24
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = icmp ne ptr null, %37
  br i1 %38, label %39, label %44

39:                                               ; preds = %36
  %40 = call noundef ptr @_ZNKSt16reverse_iteratorISt23_Rb_tree_const_iteratorISt4pairIKdiEEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %12)
  %41 = getelementptr inbounds %"struct.std::pair", ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 8, !tbaa !15
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 %42, ptr %43, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %39, %36
  store i1 true, ptr %6, align 1
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %45

45:                                               ; preds = %44, %23
  %46 = load i1, ptr %6, align 1
  ret i1 %46
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt8multimapIdiSt4lessIdESaISt4pairIKdiEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(48)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNKSt8multimapIdiSt4lessIdESaISt4pairIKdiEEE6rbeginEv(ptr dead_on_unwind noalias writable sret(%"class.std::reverse_iterator") align 8, ptr noundef nonnull align 8 dereferenceable(48)) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #2 = { 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 #3 = { mustprogress 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 #4 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSSt4pairIKdiE", !13, i64 0, !10, i64 8}
!13 = !{!"double", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !10, 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"

%"class.std::reverse_iterator" = type { %"struct.std::_Rb_tree_const_iterator" }
%"struct.std::_Rb_tree_const_iterator" = type { ptr }

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt7advanceISt16reverse_iteratorISt23_Rb_tree_const_iteratorISt4pairIKdiEEEiEvRT_T0_(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZNKSt16reverse_iteratorISt23_Rb_tree_const_iteratorISt4pairIKdiEEEptEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK4sptk18MinMaxAccumulation10GetMaximumEiRKNS0_6BufferEPdPi(ptr nocapture noundef nonnull readnone align 8 dereferenceable(13) %0, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(112) %2, ptr noundef writeonly %3, ptr noundef writeonly %4) local_unnamed_addr #2 align 2 {
  %6 = alloca %"class.std::reverse_iterator", align 8
  %7 = icmp slt i32 %1, 1
  br i1 %7, label %24, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %2, i64 64
  %10 = tail call noundef i64 @_ZNKSt8multimapIdiSt4lessIdESaISt4pairIKdiEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(48) %9) #4
  %11 = zext nneg i32 %1 to i64
  %12 = icmp ult i64 %10, %11
  br i1 %12, label %24, label %13

13:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  call void @_ZNKSt8multimapIdiSt4lessIdESaISt4pairIKdiEEE6rbeginEv(ptr dead_on_unwind nonnull writable sret(%"class.std::reverse_iterator") align 8 %6, ptr noundef nonnull align 8 dereferenceable(48) %9) #4
  %14 = add nsw i32 %1, -1
  call void @_ZSt7advanceISt16reverse_iteratorISt23_Rb_tree_const_iteratorISt4pairIKdiEEEiEvRT_T0_(ptr noundef nonnull align 8 dereferenceable(8) %6, i32 noundef %14)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %18, label %15

15:                                               ; preds = %13
  %16 = call noundef ptr @_ZNKSt16reverse_iteratorISt23_Rb_tree_const_iteratorISt4pairIKdiEEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %6)
  %17 = load double, ptr %16, align 8, !tbaa !5
  store double %17, ptr %3, align 8, !tbaa !11
  br label %18

18:                                               ; preds = %15, %13
  %.not13 = icmp eq ptr %4, null
  br i1 %.not13, label %23, label %19

19:                                               ; preds = %18
  %20 = call noundef ptr @_ZNKSt16reverse_iteratorISt23_Rb_tree_const_iteratorISt4pairIKdiEEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %6)
  %21 = getelementptr inbounds i8, ptr %20, i64 8
  %22 = load i32, ptr %21, align 8, !tbaa !12
  store i32 %22, ptr %4, align 4, !tbaa !13
  br label %23

23:                                               ; preds = %19, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  br label %24

24:                                               ; preds = %5, %8, %23
  %.0 = phi i1 [ true, %23 ], [ false, %8 ], [ false, %5 ]
  ret i1 %.0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt8multimapIdiSt4lessIdESaISt4pairIKdiEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNKSt8multimapIdiSt4lessIdESaISt4pairIKdiEEE6rbeginEv(ptr dead_on_unwind noalias writable sret(%"class.std::reverse_iterator") align 8, ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #3 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #2 = { 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 #3 = { mustprogress 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 #4 = { 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, !7, i64 0}
!6 = !{!"_ZTSSt4pairIKdiE", !7, i64 0, !10, i64 8}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!10, !10, i64 0}


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