; LLVM IR from sp-nitech/SPTK :: src/utils/sptk_utils.ll (ZN4sptk11WriteStreamERKNS_15SymmetricMatrixEPSo)

; 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.sptk::SymmetricMatrix::Row" = type <{ ptr, ptr, 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4sptk11WriteStreamIdEEbT_PSo(double noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4sptk15SymmetricMatrix15GetNumDimensionEv(ptr noundef nonnull align 8 dereferenceable(64)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4sptk15SymmetricMatrix3RowD2Ev(ptr noundef nonnull align 8 dereferenceable(20)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4sptk11WriteStreamERKNS_15SymmetricMatrixEPSo(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1) #1 personality ptr @__gxx_personality_v0 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %"class.sptk::SymmetricMatrix::Row", align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call noundef i32 @_ZNK4sptk15SymmetricMatrix15GetNumDimensionEv(ptr noundef nonnull align 8 dereferenceable(64) %13)
  store i32 %14, ptr %6, align 4, !tbaa !9
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp eq i32 0, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %59

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

19:                                               ; preds = %53, %18
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 2, ptr %7, align 4
  br label %56

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %25

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

29:                                               ; preds = %25
  store i32 5, ptr %7, align 4
  br label %50

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #4
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i32, ptr %8, align 4, !tbaa !9
  call void @_ZNK4sptk15SymmetricMatrixixEi(ptr dead_on_unwind writable sret(%"class.sptk::SymmetricMatrix::Row") align 8 %10, ptr noundef nonnull align 8 dereferenceable(64) %31, i32 noundef %32)
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNK4sptk15SymmetricMatrix3RowixEi(ptr noundef nonnull align 8 dereferenceable(20) %10, i32 noundef %33)
          to label %35 unwind label %42

35:                                               ; preds = %30
  %36 = load double, ptr %34, align 8, !tbaa !11
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = invoke noundef zeroext i1 @_ZN4sptk11WriteStreamIdEEbT_PSo(double noundef %36, ptr noundef %37)
          to label %39 unwind label %42

39:                                               ; preds = %35
  %40 = xor i1 %38, true
  call void @_ZN4sptk15SymmetricMatrix3RowD2Ev(ptr noundef nonnull align 8 dereferenceable(20) %10) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #4
  br i1 %40, label %41, label %46

41:                                               ; preds = %39
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %50

42:                                               ; preds = %35, %30
  %43 = landingpad { ptr, i32 }
          cleanup
  %44 = extractvalue { ptr, i32 } %43, 0
  store ptr %44, ptr %11, align 8
  %45 = extractvalue { ptr, i32 } %43, 1
  store i32 %45, ptr %12, align 4
  call void @_ZN4sptk15SymmetricMatrix3RowD2Ev(ptr noundef nonnull align 8 dereferenceable(20) %10) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %61

46:                                               ; preds = %39
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %9, align 4, !tbaa !9
  br label %25, !llvm.loop !13

50:                                               ; preds = %41, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %51 = load i32, ptr %7, align 4
  switch i32 %51, label %56 [
    i32 5, label %52
  ]

52:                                               ; preds = %50
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %8, align 4, !tbaa !9
  br label %19, !llvm.loop !15

56:                                               ; preds = %50, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %57 = load i32, ptr %7, align 4
  switch i32 %57, label %59 [
    i32 2, label %58
  ]

58:                                               ; preds = %56
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %59

59:                                               ; preds = %58, %56, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %60 = load i1, ptr %3, align 1
  ret i1 %60

61:                                               ; preds = %42
  %62 = load ptr, ptr %11, align 8
  %63 = load i32, ptr %12, align 4
  %64 = insertvalue { ptr, i32 } poison, ptr %62, 0
  %65 = insertvalue { ptr, i32 } %64, i32 %63, 1
  resume { ptr, i32 } %65
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK4sptk15SymmetricMatrixixEi(ptr dead_on_unwind noalias writable sret(%"class.sptk::SymmetricMatrix::Row") align 8, ptr noundef nonnull align 8 dereferenceable(64), i32 noundef) #1 align 2

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNK4sptk15SymmetricMatrix3RowixEi(ptr noundef nonnull align 8 dereferenceable(20), i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 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 = { "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 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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.sptk::SymmetricMatrix::Row" = type <{ ptr, ptr, i32, [4 x i8] }>

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

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4sptk11WriteStreamIdEEbT_PSo(double noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4sptk15SymmetricMatrix3RowD2Ev(ptr noundef nonnull align 8 dereferenceable(20)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4sptk11WriteStreamERKNS_15SymmetricMatrixEPSo(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %3 = alloca %"class.sptk::SymmetricMatrix::Row", align 8
  %4 = tail call noundef i32 @_ZNK4sptk15SymmetricMatrix15GetNumDimensionEv(ptr noundef nonnull align 8 dereferenceable(64) %0)
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %.loopexit, label %.preheader23

.preheader23:                                     ; preds = %2
  %.not2229 = icmp slt i32 %4, 1
  br i1 %.not2229, label %.loopexit, label %.preheader.us

.preheader.us:                                    ; preds = %.preheader23, %..critedge_crit_edge.us
  %.02030.us = phi i32 [ %14, %..critedge_crit_edge.us ], [ 0, %.preheader23 ]
  br label %8

6:                                                ; preds = %13
  %7 = add nuw nsw i32 %.01928.us, 1
  %exitcond.not = icmp eq i32 %7, %4
  br i1 %exitcond.not, label %..critedge_crit_edge.us, label %8, !llvm.loop !5

8:                                                ; preds = %.preheader.us, %6
  %.01928.us = phi i32 [ 0, %.preheader.us ], [ %7, %6 ]
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #4
  call void @_ZNK4sptk15SymmetricMatrixixEi(ptr dead_on_unwind nonnull writable sret(%"class.sptk::SymmetricMatrix::Row") align 8 %3, ptr noundef nonnull align 8 dereferenceable(64) %0, i32 noundef %.02030.us)
  %9 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNK4sptk15SymmetricMatrix3RowixEi(ptr noundef nonnull align 8 dereferenceable(20) %3, i32 noundef %.01928.us)
          to label %10 unwind label %.split.us

10:                                               ; preds = %8
  %11 = load double, ptr %9, align 8, !tbaa !7
  %12 = invoke noundef zeroext i1 @_ZN4sptk11WriteStreamIdEEbT_PSo(double noundef %11, ptr noundef %1)
          to label %13 unwind label %.split.us

13:                                               ; preds = %10
  call void @_ZN4sptk15SymmetricMatrix3RowD2Ev(ptr noundef nonnull align 8 dereferenceable(20) %3) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  br i1 %12, label %6, label %.loopexit

..critedge_crit_edge.us:                          ; preds = %6
  %14 = add nuw nsw i32 %.02030.us, 1
  %exitcond33 = icmp eq i32 %14, %4
  br i1 %exitcond33, label %.loopexit, label %.preheader.us, !llvm.loop !11

.split.us:                                        ; preds = %10, %8
  %15 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN4sptk15SymmetricMatrix3RowD2Ev(ptr noundef nonnull align 8 dereferenceable(20) %3) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  resume { ptr, i32 } %15

.loopexit:                                        ; preds = %..critedge_crit_edge.us, %13, %.preheader23, %2
  %.3 = phi i1 [ false, %2 ], [ true, %.preheader23 ], [ false, %13 ], [ true, %..critedge_crit_edge.us ]
  ret i1 %.3
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK4sptk15SymmetricMatrixixEi(ptr dead_on_unwind noalias writable sret(%"class.sptk::SymmetricMatrix::Row") align 8, ptr noundef nonnull align 8 dereferenceable(64), i32 noundef) local_unnamed_addr #1 align 2

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNK4sptk15SymmetricMatrix3RowixEi(ptr noundef nonnull align 8 dereferenceable(20), i32 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 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 = { "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6}


; Effective O3 passes: ConstraintEliminationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass