; LLVM IR from doyubkim/fluid-engine-dev :: src/jet/fdm_linear_system2.ll (ZN3jet8FdmBlas28lInfNormERKNS_5ArrayIdLm2EEE)

; 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.jet::Size2" = type { i64, i64 }

; 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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK3jet5ArrayIdLm2EE4sizeEv(ptr dead_on_unwind noalias writable sret(%"class.jet::Size2") align 8, ptr noundef nonnull align 8 dereferenceable(40)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNK3jet5ArrayIdLm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN3jet8FdmBlas28lInfNormERKNS_5ArrayIdLm2EEE(ptr noundef nonnull align 8 dereferenceable(40) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca %"class.jet::Size2", align 8
  %4 = alloca double, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZNK3jet5ArrayIdLm2EE4sizeEv(ptr dead_on_unwind writable sret(%"class.jet::Size2") align 8 %3, ptr noundef nonnull align 8 dereferenceable(40) %8)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store double 0.000000e+00, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 0, ptr %5, align 8, !tbaa !11
  br label %9

9:                                                ; preds = %34, %1
  %10 = load i64, ptr %5, align 8, !tbaa !11
  %11 = getelementptr inbounds %"class.jet::Size2", ptr %3, i32 0, i32 1
  %12 = load i64, ptr %11, align 8, !tbaa !13
  %13 = icmp ult i64 %10, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %9
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %37

15:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 0, ptr %7, align 8, !tbaa !11
  br label %16

16:                                               ; preds = %30, %15
  %17 = load i64, ptr %7, align 8, !tbaa !11
  %18 = getelementptr inbounds %"class.jet::Size2", ptr %3, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !15
  %20 = icmp ult i64 %17, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %33

22:                                               ; preds = %16
  %23 = load double, ptr %4, align 8, !tbaa !9
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = load i64, ptr %7, align 8, !tbaa !11
  %26 = load i64, ptr %5, align 8, !tbaa !11
  %27 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK3jet5ArrayIdLm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %24, i64 noundef %25, i64 noundef %26)
  %28 = load double, ptr %27, align 8, !tbaa !9
  %29 = call noundef double @_ZN3jet6absmaxIdEET_S1_S1_(double noundef %23, double noundef %28)
  store double %29, ptr %4, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %22
  %31 = load i64, ptr %7, align 8, !tbaa !11
  %32 = add i64 %31, 1
  store i64 %32, ptr %7, align 8, !tbaa !11
  br label %16, !llvm.loop !16

33:                                               ; preds = %21
  br label %34

34:                                               ; preds = %33
  %35 = load i64, ptr %5, align 8, !tbaa !11
  %36 = add i64 %35, 1
  store i64 %36, ptr %5, align 8, !tbaa !11
  br label %9, !llvm.loop !18

37:                                               ; preds = %14
  %38 = load double, ptr %4, align 8, !tbaa !9
  %39 = call double @llvm.fabs.f64(double %38)
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #5
  ret double %39
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZN3jet6absmaxIdEET_S1_S1_(double noundef, double noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #4

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 = { inlinehint 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"_ZTSN3jet5Size2E", !12, i64 0, !12, i64 8}
!15 = !{!14, !12, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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.jet::Size2" = type { i64, i64 }

; 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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK3jet5ArrayIdLm2EE4sizeEv(ptr dead_on_unwind noalias writable sret(%"class.jet::Size2") align 8, ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNK3jet5ArrayIdLm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN3jet8FdmBlas28lInfNormERKNS_5ArrayIdLm2EEE(ptr noundef nonnull align 8 dereferenceable(40) %0) local_unnamed_addr #1 align 2 {
  %2 = alloca %"class.jet::Size2", align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #5
  call void @_ZNK3jet5ArrayIdLm2EE4sizeEv(ptr dead_on_unwind nonnull writable sret(%"class.jet::Size2") align 8 %2, ptr noundef nonnull align 8 dereferenceable(40) %0)
  %3 = getelementptr inbounds i8, ptr %2, i64 8
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i64 %4, 0
  %5 = load i64, ptr %2, align 8
  %.not17 = icmp eq i64 %5, 0
  %or.cond = select i1 %.not, i1 true, i1 %.not17
  br i1 %or.cond, label %._crit_edge15, label %.preheader

.preheader:                                       ; preds = %1, %._crit_edge
  %6 = phi i64 [ %9, %._crit_edge ], [ %4, %1 ]
  %7 = phi i64 [ %10, %._crit_edge ], [ 1, %1 ]
  %.0914 = phi i64 [ %11, %._crit_edge ], [ 0, %1 ]
  %.01013 = phi double [ %.1.lcssa, %._crit_edge ], [ 0.000000e+00, %1 ]
  %.not18 = icmp eq i64 %7, 0
  br i1 %.not18, label %._crit_edge, label %.lr.ph

._crit_edge15:                                    ; preds = %._crit_edge, %1
  %.010.lcssa = phi double [ 0.000000e+00, %1 ], [ %.1.lcssa, %._crit_edge ]
  %8 = call double @llvm.fabs.f64(double %.010.lcssa)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #5
  ret double %8

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i64, ptr %3, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %9 = phi i64 [ %6, %.preheader ], [ %.pre, %._crit_edge.loopexit ]
  %10 = phi i64 [ 0, %.preheader ], [ %17, %._crit_edge.loopexit ]
  %.1.lcssa = phi double [ %.01013, %.preheader ], [ %15, %._crit_edge.loopexit ]
  %11 = add nuw i64 %.0914, 1
  %12 = icmp ult i64 %11, %9
  br i1 %12, label %.preheader, label %._crit_edge15, !llvm.loop !10

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.012 = phi i64 [ %16, %.lr.ph ], [ 0, %.preheader ]
  %.111 = phi double [ %15, %.lr.ph ], [ %.01013, %.preheader ]
  %13 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK3jet5ArrayIdLm2EEclEmm(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %.012, i64 noundef %.0914)
  %14 = load double, ptr %13, align 8, !tbaa !13
  %15 = call noundef double @_ZN3jet6absmaxIdEET_S1_S1_(double noundef %.111, double noundef %14)
  %16 = add nuw i64 %.012, 1
  %17 = load i64, ptr %2, align 8, !tbaa !15
  %18 = icmp ult i64 %16, %17
  br i1 %18, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !16
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZN3jet6absmaxIdEET_S1_S1_(double noundef, double noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #4

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 = { inlinehint 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"_ZTSN3jet5Size2E", !7, i64 0, !7, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = distinct !{!10, !11, !12}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!"llvm.loop.unswitch.partial.disable"}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !8, i64 0}
!15 = !{!6, !7, i64 0}
!16 = distinct !{!16, !11}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass