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

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #0

; Function Attrs: nounwind
declare void @_ZN8CPyramidD1Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN8MorphLib6CMorphD2Ev(ptr noundef nonnull align 8 dereferenceable(49) %0) unnamed_addr #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %4, i32 0, i32 1
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = icmp eq ptr %6, null
  br i1 %7, label %9, label %8

8:                                                ; preds = %1
  call void @_ZN8CPyramidD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %6) #4
  call void @_ZdlPvm(ptr noundef %6, i64 noundef 24) #5
  br label %9

9:                                                ; preds = %8, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !13
  br label %10

10:                                               ; preds = %87, %9
  %11 = load i32, ptr %3, align 4, !tbaa !13
  %12 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %4, i32 0, i32 2
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %14 = icmp slt i32 %11, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %90

16:                                               ; preds = %10
  %17 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %4, i32 0, i32 8
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = load i32, ptr %3, align 4, !tbaa !13
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds %"struct.MorphLib::CData", ptr %18, i64 %20
  %22 = getelementptr inbounds %"struct.MorphLib::CData", ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds %struct.anon, ptr %22, i32 0, i32 5
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %35

26:                                               ; preds = %16
  %27 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %4, i32 0, i32 8
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = load i32, ptr %3, align 4, !tbaa !13
  %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 0
  %33 = getelementptr inbounds %struct.anon, ptr %32, i32 0, i32 5
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  call void @free(ptr noundef %34) #4
  br label %35

35:                                               ; preds = %26, %16
  %36 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %4, i32 0, i32 8
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  %38 = load i32, ptr %3, align 4, !tbaa !13
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds %"struct.MorphLib::CData", ptr %37, i64 %39
  %41 = getelementptr inbounds %"struct.MorphLib::CData", ptr %40, i32 0, i32 6
  %42 = load ptr, ptr %41, align 8, !tbaa !21
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %52

44:                                               ; preds = %35
  %45 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %4, i32 0, i32 8
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = load i32, ptr %3, align 4, !tbaa !13
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds %"struct.MorphLib::CData", ptr %46, i64 %48
  %50 = getelementptr inbounds %"struct.MorphLib::CData", ptr %49, i32 0, i32 6
  %51 = load ptr, ptr %50, align 8, !tbaa !21
  call void @free(ptr noundef %51) #4
  br label %52

52:                                               ; preds = %44, %35
  %53 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %4, i32 0, i32 8
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = load i32, ptr %3, align 4, !tbaa !13
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds %"struct.MorphLib::CData", ptr %54, i64 %56
  %58 = getelementptr inbounds %"struct.MorphLib::CData", ptr %57, i32 0, i32 4
  %59 = load ptr, ptr %58, align 8, !tbaa !22
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %69

61:                                               ; preds = %52
  %62 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %4, i32 0, i32 8
  %63 = load ptr, ptr %62, align 8, !tbaa !15
  %64 = load i32, ptr %3, align 4, !tbaa !13
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds %"struct.MorphLib::CData", ptr %63, i64 %65
  %67 = getelementptr inbounds %"struct.MorphLib::CData", ptr %66, i32 0, i32 4
  %68 = load ptr, ptr %67, align 8, !tbaa !22
  call void @free(ptr noundef %68) #4
  br label %69

69:                                               ; preds = %61, %52
  %70 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %4, i32 0, i32 8
  %71 = load ptr, ptr %70, align 8, !tbaa !15
  %72 = load i32, ptr %3, align 4, !tbaa !13
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds %"struct.MorphLib::CData", ptr %71, i64 %73
  %75 = getelementptr inbounds %"struct.MorphLib::CData", ptr %74, i32 0, i32 5
  %76 = load ptr, ptr %75, align 8, !tbaa !23
  %77 = icmp ne ptr %76, null
  br i1 %77, label %78, label %86

78:                                               ; preds = %69
  %79 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %4, i32 0, i32 8
  %80 = load ptr, ptr %79, align 8, !tbaa !15
  %81 = load i32, ptr %3, align 4, !tbaa !13
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds %"struct.MorphLib::CData", ptr %80, i64 %82
  %84 = getelementptr inbounds %"struct.MorphLib::CData", ptr %83, i32 0, i32 5
  %85 = load ptr, ptr %84, align 8, !tbaa !23
  call void @free(ptr noundef %85) #4
  br label %86

86:                                               ; preds = %78, %69
  br label %87

87:                                               ; preds = %86
  %88 = load i32, ptr %3, align 4, !tbaa !13
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %3, align 4, !tbaa !13
  br label %10, !llvm.loop !24

90:                                               ; preds = %15
  %91 = getelementptr inbounds %"class.MorphLib::CMorph", ptr %4, i32 0, i32 8
  %92 = load ptr, ptr %91, align 8, !tbaa !15
  call void @free(ptr noundef %92) #4
  ret void
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

attributes #0 = { nobuiltin 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }
attributes #5 = { builtin 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, !6, i64 8}
!10 = !{!"_ZTSN8MorphLib6CMorphE", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !6, i64 40, !12, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 16}
!15 = !{!10, !6, i64 40}
!16 = !{!17, !6, i64 40}
!17 = !{!"_ZTSN8MorphLib5CDataE", !18, i64 0, !19, i64 72, !20, i64 96, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !11, 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 = !{!17, !6, i64 144}
!22 = !{!17, !6, i64 128}
!23 = !{!17, !6, i64 136}
!24 = distinct !{!24, !25}
!25 = !{!"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: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind
declare void @_ZN8CPyramidD1Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN8MorphLib6CMorphD2Ev(ptr nocapture noundef nonnull readonly align 8 dereferenceable(49) %0) unnamed_addr #2 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %6, label %5

5:                                                ; preds = %1
  tail call void @_ZN8CPyramidD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %3) #4
  tail call void @_ZdlPvm(ptr noundef nonnull %3, i64 noundef 24) #5
  br label %6

6:                                                ; preds = %5, %1
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i32, ptr %7, align 8, !tbaa !12
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  br label %13

._crit_edge:                                      ; preds = %33, %6
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  tail call void @free(ptr noundef %12) #4
  ret void

13:                                               ; preds = %.lr.ph, %33
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %33 ]
  %14 = load ptr, ptr %10, align 8, !tbaa !13
  %15 = getelementptr inbounds %"struct.MorphLib::CData", ptr %14, i64 %indvars.iv, i32 0, i32 5
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %18, label %17

17:                                               ; preds = %13
  tail call void @free(ptr noundef nonnull %16) #4
  %.pre = load ptr, ptr %10, align 8, !tbaa !13
  br label %18

18:                                               ; preds = %17, %13
  %19 = phi ptr [ %.pre, %17 ], [ %14, %13 ]
  %20 = getelementptr inbounds %"struct.MorphLib::CData", ptr %19, i64 %indvars.iv, i32 6
  %21 = load ptr, ptr %20, align 8, !tbaa !19
  %.not15 = icmp eq ptr %21, null
  br i1 %.not15, label %23, label %22

22:                                               ; preds = %18
  tail call void @free(ptr noundef nonnull %21) #4
  %.pre20 = load ptr, ptr %10, align 8, !tbaa !13
  br label %23

23:                                               ; preds = %22, %18
  %24 = phi ptr [ %.pre20, %22 ], [ %19, %18 ]
  %25 = getelementptr inbounds %"struct.MorphLib::CData", ptr %24, i64 %indvars.iv, i32 4
  %26 = load ptr, ptr %25, align 8, !tbaa !20
  %.not16 = icmp eq ptr %26, null
  br i1 %.not16, label %28, label %27

27:                                               ; preds = %23
  tail call void @free(ptr noundef nonnull %26) #4
  %.pre21 = load ptr, ptr %10, align 8, !tbaa !13
  br label %28

28:                                               ; preds = %27, %23
  %29 = phi ptr [ %.pre21, %27 ], [ %24, %23 ]
  %30 = getelementptr inbounds %"struct.MorphLib::CData", ptr %29, i64 %indvars.iv, i32 5
  %31 = load ptr, ptr %30, align 8, !tbaa !21
  %.not17 = icmp eq ptr %31, null
  br i1 %.not17, label %33, label %32

32:                                               ; preds = %28
  tail call void @free(ptr noundef nonnull %31) #4
  br label %33

33:                                               ; preds = %28, %32
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %34 = load i32, ptr %7, align 8, !tbaa !12
  %35 = sext i32 %34 to i64
  %36 = icmp slt i64 %indvars.iv.next, %35
  br i1 %36, label %13, label %._crit_edge, !llvm.loop !22
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

attributes #0 = { nobuiltin 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 #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 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 #3 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }
attributes #5 = { builtin 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 8}
!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 = !{!6, !10, i64 16}
!13 = !{!6, !7, i64 40}
!14 = !{!15, !7, i64 40}
!15 = !{!"_ZTSN8MorphLib5CDataE", !16, i64 0, !17, i64 72, !18, i64 96, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !10, i64 152}
!16 = !{!"_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}
!17 = !{!"_ZTSN8MorphLib5CDataUt0_E", !7, i64 0, !7, i64 8, !7, i64 16}
!18 = !{!"_ZTSN8MorphLib5CDataUt1_E", !7, i64 0, !7, i64 8, !7, i64 16}
!19 = !{!15, !7, i64 144}
!20 = !{!15, !7, i64 128}
!21 = !{!15, !7, i64 136}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass