; LLVM IR from liaojing/MorphLib :: MorphLib/Morph.ll (ZN8MorphLib6CMorph14optimize_levelEi)

; 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.MorphLib::CMorph" = type <{ ptr, ptr, i32, i32, i32, i32, i32, [4 x i8], ptr, i8, [7 x i8] }>
%"struct.MorphLib::CData" = type { %struct.anon, %struct.anon.5, %struct.anon.6, ptr, ptr, ptr, ptr, i32 }
%struct.anon = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.anon.5 = type { ptr, ptr, ptr }
%struct.anon.6 = type { ptr, ptr, ptr }
%class.CPyramid = type { %"class.std::vector.0" }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<CPyramidLevel, std::allocator<CPyramidLevel>>::_Vector_impl" }
%"struct.std::_Vector_base<CPyramidLevel, std::allocator<CPyramidLevel>>::_Vector_impl" = type { %"struct.std::_Vector_base<CPyramidLevel, std::allocator<CPyramidLevel>>::_Vector_impl_data" }
%"struct.std::_Vector_base<CPyramidLevel, std::allocator<CPyramidLevel>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%class.CPyramidLevel = type { i32, i32, float, i32, i32, i32, ptr, ptr, ptr, ptr }

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(56) ptr @_ZNSt6vectorI13CPyramidLevelSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 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: nounwind
declare i64 @clock() #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8MorphLib6CMorph14optimize_levelEi(ptr noundef nonnull align 8 dereferenceable(49) %0, i32 noundef %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %9 = call i64 @clock() #4
  store i64 %9, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %60, %2
  %11 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %8, i32 0, i32 8
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds %"struct.MorphLib::CData", ptr %12, i64 %14
  %16 = getelementptr inbounds %"struct.MorphLib::CData", ptr %15, i32 0, i32 7
  %17 = load i32, ptr %16, align 8, !tbaa !16
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %19, label %24

19:                                               ; preds = %10
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %8, i32 0, i32 6
  %22 = load i32, ptr %21, align 8, !tbaa !21
  %23 = icmp slt i32 %20, %22
  br label %24

24:                                               ; preds = %19, %10
  %25 = phi i1 [ false, %10 ], [ %23, %19 ]
  br i1 %25, label %26, label %61

26:                                               ; preds = %24
  %27 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %8, i32 0, i32 8
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %"struct.MorphLib::CData", ptr %28, i64 %30
  %32 = getelementptr inbounds %"struct.MorphLib::CData", ptr %31, i32 0, i32 7
  store i32 0, ptr %32, align 8, !tbaa !16
  %33 = load i32, ptr %4, align 4, !tbaa !9
  call void @_ZN8MorphLib6CMorph9outerloopINS_3OptEEEvi(ptr noundef nonnull align 8 dereferenceable(49) %8, i32 noundef %33)
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %7, align 4, !tbaa !9
  %36 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %8, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !22
  %38 = getelementptr inbounds %class.CPyramid, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %4, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = call noundef nonnull align 8 dereferenceable(56) ptr @_ZNSt6vectorI13CPyramidLevelSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %38, i64 noundef %40) #4
  %42 = getelementptr inbounds %class.CPyramidLevel, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !23
  %44 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %8, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !22
  %46 = getelementptr inbounds %class.CPyramid, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %4, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = call noundef nonnull align 8 dereferenceable(56) ptr @_ZNSt6vectorI13CPyramidLevelSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %46, i64 noundef %48) #4
  %50 = getelementptr inbounds %class.CPyramidLevel, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !26
  %52 = mul nsw i32 %43, %51
  %53 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %8, i32 0, i32 5
  %54 = load i32, ptr %53, align 4, !tbaa !27
  %55 = add nsw i32 %54, %52
  store i32 %55, ptr %53, align 4, !tbaa !27
  %56 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %8, i32 0, i32 9
  %57 = load i8, ptr %56, align 8, !tbaa !28, !range !29, !noundef !30
  %58 = trunc i8 %57 to i1
  br i1 %58, label %60, label %59

59:                                               ; preds = %26
  br label %61

60:                                               ; preds = %26
  br label %10, !llvm.loop !31

61:                                               ; preds = %59, %24
  %62 = call i64 @clock() #4
  store i64 %62, ptr %6, align 8, !tbaa !11
  %63 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %8, i32 0, i32 6
  %64 = load i32, ptr %63, align 8, !tbaa !21
  %65 = load i32, ptr %7, align 4, !tbaa !9
  %66 = sub nsw i32 %64, %65
  %67 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %8, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !22
  %69 = getelementptr inbounds %class.CPyramid, ptr %68, i32 0, i32 0
  %70 = load i32, ptr %4, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = call noundef nonnull align 8 dereferenceable(56) ptr @_ZNSt6vectorI13CPyramidLevelSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %69, i64 noundef %71) #4
  %73 = getelementptr inbounds %class.CPyramidLevel, ptr %72, i32 0, i32 0
  %74 = load i32, ptr %73, align 8, !tbaa !23
  %75 = mul nsw i32 %66, %74
  %76 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %8, i32 0, i32 1
  %77 = load ptr, ptr %76, align 8, !tbaa !22
  %78 = getelementptr inbounds %class.CPyramid, ptr %77, i32 0, i32 0
  %79 = load i32, ptr %4, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = call noundef nonnull align 8 dereferenceable(56) ptr @_ZNSt6vectorI13CPyramidLevelSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %78, i64 noundef %80) #4
  %82 = getelementptr inbounds %class.CPyramidLevel, ptr %81, i32 0, i32 1
  %83 = load i32, ptr %82, align 4, !tbaa !26
  %84 = mul nsw i32 %75, %83
  %85 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %8, i32 0, i32 5
  %86 = load i32, ptr %85, align 4, !tbaa !27
  %87 = add nsw i32 %86, %84
  store i32 %87, ptr %85, align 4, !tbaa !27
  %88 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret i32 %88
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8MorphLib6CMorph9outerloopINS_3OptEEEvi(ptr noundef nonnull align 8 dereferenceable(49), i32 noundef) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nounwind "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 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 40}
!14 = !{!"_ZTSN8MorphLib6CMorphE", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40, !15, i64 48}
!15 = !{!"bool", !7, i64 0}
!16 = !{!17, !10, i64 152}
!17 = !{!"_ZTSN8MorphLib5CDataE", !18, i64 0, !19, i64 72, !20, i64 96, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !10, i64 152}
!18 = !{!"_ZTSN8MorphLib5CDataUt_E", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!19 = !{!"_ZTSN8MorphLib5CDataUt0_E", !6, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!"_ZTSN8MorphLib5CDataUt1_E", !6, i64 0, !6, i64 8, !6, i64 16}
!21 = !{!14, !10, i64 32}
!22 = !{!14, !6, i64 8}
!23 = !{!24, !10, i64 0}
!24 = !{!"_ZTS13CPyramidLevel", !10, i64 0, !10, i64 4, !25, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!25 = !{!"float", !7, i64 0}
!26 = !{!24, !10, i64 4}
!27 = !{!14, !10, i64 28}
!28 = !{!14, !15, i64 48}
!29 = !{i8 0, i8 2}
!30 = !{}
!31 = distinct !{!31, !32}
!32 = !{!"llvm.loop.mustprogress"}


; 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.MorphLib::CData" = type { %struct.anon, %struct.anon.5, %struct.anon.6, ptr, ptr, ptr, ptr, i32 }
%struct.anon = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.anon.5 = type { ptr, ptr, ptr }
%struct.anon.6 = type { ptr, ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(56) ptr @_ZNSt6vectorI13CPyramidLevelSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: nounwind
declare i64 @clock() local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8MorphLib6CMorph14optimize_levelEi(ptr noundef nonnull align 8 dereferenceable(49) %0, i32 noundef %1) local_unnamed_addr #2 align 2 {
  %3 = tail call i64 @clock() #3
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  %5 = sext i32 %1 to i64
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = getelementptr inbounds i8, ptr %0, i64 28
  %9 = getelementptr inbounds i8, ptr %0, i64 48
  br label %10

10:                                               ; preds = %17, %2
  %.0 = phi i32 [ 0, %2 ], [ %18, %17 ]
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %"struct.MorphLib::CData", ptr %11, i64 %5, i32 7
  %13 = load i32, ptr %12, align 8, !tbaa !12
  %14 = icmp sgt i32 %13, 0
  %15 = load i32, ptr %6, align 8
  %16 = icmp slt i32 %.0, %15
  %or.cond = select i1 %14, i1 %16, i1 false
  br i1 %or.cond, label %17, label %.critedge

17:                                               ; preds = %10
  store i32 0, ptr %12, align 8, !tbaa !12
  tail call void @_ZN8MorphLib6CMorph9outerloopINS_3OptEEEvi(ptr noundef nonnull align 8 dereferenceable(49) %0, i32 noundef %1)
  %18 = add nuw nsw i32 %.0, 1
  %19 = load ptr, ptr %7, align 8, !tbaa !17
  %20 = tail call noundef nonnull align 8 dereferenceable(56) ptr @_ZNSt6vectorI13CPyramidLevelSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %19, i64 noundef %5) #3
  %21 = load i32, ptr %20, align 8, !tbaa !18
  %22 = load ptr, ptr %7, align 8, !tbaa !17
  %23 = tail call noundef nonnull align 8 dereferenceable(56) ptr @_ZNSt6vectorI13CPyramidLevelSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %22, i64 noundef %5) #3
  %24 = getelementptr inbounds i8, ptr %23, i64 4
  %25 = load i32, ptr %24, align 4, !tbaa !21
  %26 = mul nsw i32 %25, %21
  %27 = load i32, ptr %8, align 4, !tbaa !22
  %28 = add nsw i32 %27, %26
  store i32 %28, ptr %8, align 4, !tbaa !22
  %29 = load i8, ptr %9, align 8, !tbaa !23, !range !24, !noundef !25
  %30 = trunc nuw i8 %29 to i1
  br i1 %30, label %10, label %.critedge, !llvm.loop !26

.critedge:                                        ; preds = %10, %17
  %.1 = phi i32 [ %18, %17 ], [ %.0, %10 ]
  %31 = tail call i64 @clock() #3
  %32 = load i32, ptr %6, align 8, !tbaa !28
  %33 = sub nsw i32 %32, %.1
  %34 = load ptr, ptr %7, align 8, !tbaa !17
  %35 = tail call noundef nonnull align 8 dereferenceable(56) ptr @_ZNSt6vectorI13CPyramidLevelSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %34, i64 noundef %5) #3
  %36 = load i32, ptr %35, align 8, !tbaa !18
  %37 = mul nsw i32 %36, %33
  %38 = load ptr, ptr %7, align 8, !tbaa !17
  %39 = tail call noundef nonnull align 8 dereferenceable(56) ptr @_ZNSt6vectorI13CPyramidLevelSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %38, i64 noundef %5) #3
  %40 = getelementptr inbounds i8, ptr %39, i64 4
  %41 = load i32, ptr %40, align 4, !tbaa !21
  %42 = mul nsw i32 %37, %41
  %43 = load i32, ptr %8, align 4, !tbaa !22
  %44 = add nsw i32 %43, %42
  store i32 %44, ptr %8, align 4, !tbaa !22
  ret i32 %.1
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8MorphLib6CMorph9outerloopINS_3OptEEEvi(ptr noundef nonnull align 8 dereferenceable(49), i32 noundef) local_unnamed_addr #2 align 2

attributes #0 = { 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 #1 = { nounwind "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 = { 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 40}
!6 = !{!"_ZTSN8MorphLib6CMorphE", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !7, i64 40, !11, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!13, !10, i64 152}
!13 = !{!"_ZTSN8MorphLib5CDataE", !14, i64 0, !15, i64 72, !16, i64 96, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !10, i64 152}
!14 = !{!"_ZTSN8MorphLib5CDataUt_E", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64}
!15 = !{!"_ZTSN8MorphLib5CDataUt0_E", !7, i64 0, !7, i64 8, !7, i64 16}
!16 = !{!"_ZTSN8MorphLib5CDataUt1_E", !7, i64 0, !7, i64 8, !7, i64 16}
!17 = !{!6, !7, i64 8}
!18 = !{!19, !10, i64 0}
!19 = !{!"_ZTS13CPyramidLevel", !10, i64 0, !10, i64 4, !20, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48}
!20 = !{!"float", !8, i64 0}
!21 = !{!19, !10, i64 4}
!22 = !{!6, !10, i64 28}
!23 = !{!6, !11, i64 48}
!24 = !{i8 0, i8 2}
!25 = !{}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = !{!6, !10, i64 32}


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