; LLVM IR from LukeMcCulloch/cfd_solvers_cpp :: src/gridGen2D.ll (ZN6Grid2D9gridGen2D18generate_quad_gridEv)

; 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.Grid2D::gridGen2D" = type <{ float, float, float, float, float, float, i32, i32, %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", ptr, ptr, i32, i32, i32, i32, ptr, ptr, ptr, ptr, float, float, i32, i32, i32, [4 x i8] }>
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Grid2D9gridGen2D18generate_quad_gridEv(ptr noundef nonnull align 8 dereferenceable(276) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %12 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 16
  store i32 0, ptr %12, align 4, !tbaa !9
  %13 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 17
  store i32 -1, ptr %13, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !17
  br label %14

14:                                               ; preds = %80, %1
  %15 = load i32, ptr %8, align 4, !tbaa !17
  %16 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 7
  %17 = load i32, ptr %16, align 4, !tbaa !18
  %18 = sub nsw i32 %17, 1
  %19 = icmp slt i32 %15, %18
  br i1 %19, label %21, label %20

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

21:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !17
  br label %22

22:                                               ; preds = %76, %21
  %23 = load i32, ptr %10, align 4, !tbaa !17
  %24 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 6
  %25 = load i32, ptr %24, align 8, !tbaa !19
  %26 = sub nsw i32 %25, 1
  %27 = icmp slt i32 %23, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %22
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %79

29:                                               ; preds = %22
  %30 = load i32, ptr %10, align 4, !tbaa !17
  %31 = load i32, ptr %8, align 4, !tbaa !17
  %32 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 6
  %33 = load i32, ptr %32, align 8, !tbaa !19
  %34 = mul nsw i32 %31, %33
  %35 = add nsw i32 %30, %34
  store i32 %35, ptr %3, align 4, !tbaa !17
  %36 = load i32, ptr %3, align 4, !tbaa !17
  store i32 %36, ptr %4, align 4, !tbaa !17
  %37 = load i32, ptr %3, align 4, !tbaa !17
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %5, align 4, !tbaa !17
  %39 = load i32, ptr %3, align 4, !tbaa !17
  %40 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 6
  %41 = load i32, ptr %40, align 8, !tbaa !19
  %42 = add nsw i32 %39, %41
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %6, align 4, !tbaa !17
  %44 = load i32, ptr %3, align 4, !tbaa !17
  %45 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 6
  %46 = load i32, ptr %45, align 8, !tbaa !19
  %47 = add nsw i32 %44, %46
  store i32 %47, ptr %7, align 4, !tbaa !17
  %48 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 17
  %49 = load i32, ptr %48, align 8, !tbaa !16
  %50 = add nsw i32 %49, 1
  %51 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 17
  store i32 %50, ptr %51, align 8, !tbaa !16
  %52 = load i32, ptr %4, align 4, !tbaa !17
  %53 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 20
  %54 = load ptr, ptr %53, align 8, !tbaa !20
  %55 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 17
  %56 = load i32, ptr %55, align 8, !tbaa !16
  %57 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Array2DIiEclEii(ptr noundef nonnull align 8 dereferenceable(40) %54, i32 noundef %56, i32 noundef 0)
  store i32 %52, ptr %57, align 4, !tbaa !17
  %58 = load i32, ptr %5, align 4, !tbaa !17
  %59 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 20
  %60 = load ptr, ptr %59, align 8, !tbaa !20
  %61 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 17
  %62 = load i32, ptr %61, align 8, !tbaa !16
  %63 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Array2DIiEclEii(ptr noundef nonnull align 8 dereferenceable(40) %60, i32 noundef %62, i32 noundef 1)
  store i32 %58, ptr %63, align 4, !tbaa !17
  %64 = load i32, ptr %6, align 4, !tbaa !17
  %65 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 20
  %66 = load ptr, ptr %65, align 8, !tbaa !20
  %67 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 17
  %68 = load i32, ptr %67, align 8, !tbaa !16
  %69 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Array2DIiEclEii(ptr noundef nonnull align 8 dereferenceable(40) %66, i32 noundef %68, i32 noundef 2)
  store i32 %64, ptr %69, align 4, !tbaa !17
  %70 = load i32, ptr %7, align 4, !tbaa !17
  %71 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 20
  %72 = load ptr, ptr %71, align 8, !tbaa !20
  %73 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 17
  %74 = load i32, ptr %73, align 8, !tbaa !16
  %75 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Array2DIiEclEii(ptr noundef nonnull align 8 dereferenceable(40) %72, i32 noundef %74, i32 noundef 3)
  store i32 %70, ptr %75, align 4, !tbaa !17
  br label %76

76:                                               ; preds = %29
  %77 = load i32, ptr %10, align 4, !tbaa !17
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %10, align 4, !tbaa !17
  br label %22, !llvm.loop !21

79:                                               ; preds = %28
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %8, align 4, !tbaa !17
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %8, align 4, !tbaa !17
  br label %14, !llvm.loop !23

83:                                               ; preds = %20
  %84 = getelementptr inbounds %"class.Grid2D::gridGen2D", ptr %11, i32 0, i32 17
  %85 = load i32, ptr %84, align 8, !tbaa !16
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %84, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Array2DIiEclEii(ptr noundef nonnull align 8 dereferenceable(40), i32 noundef, i32 noundef) #1 align 2

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 = { 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, !12, i64 212}
!10 = !{!"_ZTSN6Grid2D9gridGen2DE", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !12, i64 24, !12, i64 28, !13, i64 32, !13, i64 64, !13, i64 96, !13, i64 128, !13, i64 160, !6, i64 192, !6, i64 200, !12, i64 208, !12, i64 212, !12, i64 216, !12, i64 220, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !11, i64 256, !11, i64 260, !12, i64 264, !12, i64 268, !12, i64 272}
!11 = !{!"float", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !14, i64 0, !15, i64 8, !7, i64 16}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!10, !12, i64 216}
!17 = !{!12, !12, i64 0}
!18 = !{!10, !12, i64 28}
!19 = !{!10, !12, i64 24}
!20 = !{!10, !6, i64 232}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Grid2D9gridGen2D18generate_quad_gridEv(ptr nocapture noundef nonnull align 8 dereferenceable(276) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 212
  store i32 0, ptr %2, align 4, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 216
  store i32 -1, ptr %3, align 8, !tbaa !15
  %4 = getelementptr inbounds i8, ptr %0, i64 28
  %5 = load i32, ptr %4, align 4, !tbaa !16
  %6 = icmp sgt i32 %5, 1
  br i1 %6, label %.preheader.lr.ph, label %._crit_edge17

.preheader.lr.ph:                                 ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = getelementptr inbounds i8, ptr %0, i64 232
  %9 = load i32, ptr %7, align 8, !tbaa !17
  %10 = icmp sgt i32 %9, 1
  br i1 %10, label %.preheader, label %._crit_edge17

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %11 = phi i32 [ %16, %._crit_edge ], [ %5, %.preheader.lr.ph ]
  %12 = phi i32 [ %17, %._crit_edge ], [ %9, %.preheader.lr.ph ]
  %.01416 = phi i32 [ %18, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %13 = icmp sgt i32 %12, 1
  br i1 %13, label %.lr.ph, label %._crit_edge

._crit_edge17.loopexit:                           ; preds = %._crit_edge
  %.pre19 = load i32, ptr %3, align 8, !tbaa !15
  %14 = add nsw i32 %.pre19, 1
  br label %._crit_edge17

._crit_edge17:                                    ; preds = %.preheader.lr.ph, %._crit_edge17.loopexit, %1
  %15 = phi i32 [ %14, %._crit_edge17.loopexit ], [ 0, %1 ], [ 0, %.preheader.lr.ph ]
  store i32 %15, ptr %3, align 8, !tbaa !15
  ret void

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %4, align 4, !tbaa !16
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %16 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %11, %.preheader ]
  %17 = phi i32 [ %41, %._crit_edge.loopexit ], [ %12, %.preheader ]
  %18 = add nuw nsw i32 %.01416, 1
  %19 = add nsw i32 %16, -1
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %.preheader, label %._crit_edge17.loopexit, !llvm.loop !18

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %21 = phi i32 [ %41, %.lr.ph ], [ %12, %.preheader ]
  %.015 = phi i32 [ %40, %.lr.ph ], [ 0, %.preheader ]
  %22 = mul nsw i32 %21, %.01416
  %23 = add nsw i32 %22, %.015
  %24 = add nsw i32 %23, 1
  %25 = add nsw i32 %23, %21
  %26 = add nsw i32 %25, 1
  %27 = load i32, ptr %3, align 8, !tbaa !15
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %3, align 8, !tbaa !15
  %29 = load ptr, ptr %8, align 8, !tbaa !21
  %30 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Array2DIiEclEii(ptr noundef nonnull align 8 dereferenceable(40) %29, i32 noundef %28, i32 noundef 0)
  store i32 %23, ptr %30, align 4, !tbaa !22
  %31 = load ptr, ptr %8, align 8, !tbaa !21
  %32 = load i32, ptr %3, align 8, !tbaa !15
  %33 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Array2DIiEclEii(ptr noundef nonnull align 8 dereferenceable(40) %31, i32 noundef %32, i32 noundef 1)
  store i32 %24, ptr %33, align 4, !tbaa !22
  %34 = load ptr, ptr %8, align 8, !tbaa !21
  %35 = load i32, ptr %3, align 8, !tbaa !15
  %36 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Array2DIiEclEii(ptr noundef nonnull align 8 dereferenceable(40) %34, i32 noundef %35, i32 noundef 2)
  store i32 %26, ptr %36, align 4, !tbaa !22
  %37 = load ptr, ptr %8, align 8, !tbaa !21
  %38 = load i32, ptr %3, align 8, !tbaa !15
  %39 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Array2DIiEclEii(ptr noundef nonnull align 8 dereferenceable(40) %37, i32 noundef %38, i32 noundef 3)
  store i32 %25, ptr %39, align 4, !tbaa !22
  %40 = add nuw nsw i32 %.015, 1
  %41 = load i32, ptr %7, align 8, !tbaa !17
  %42 = add nsw i32 %41, -1
  %43 = icmp slt i32 %40, %42
  br i1 %43, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !23
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Array2DIiEclEii(ptr noundef nonnull align 8 dereferenceable(40), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

attributes #0 = { 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" }

!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, !10, i64 212}
!6 = !{!"_ZTSN6Grid2D9gridGen2DE", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !10, i64 24, !10, i64 28, !11, i64 32, !11, i64 64, !11, i64 96, !11, i64 128, !11, i64 160, !13, i64 192, !13, i64 200, !10, i64 208, !10, i64 212, !10, i64 216, !10, i64 220, !13, i64 224, !13, i64 232, !13, i64 240, !13, i64 248, !7, i64 256, !7, i64 260, !10, i64 264, !10, i64 268, !10, i64 272}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !12, i64 0, !14, i64 8, !8, i64 16}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"long", !8, i64 0}
!15 = !{!6, !10, i64 216}
!16 = !{!6, !10, i64 28}
!17 = !{!6, !10, i64 24}
!18 = distinct !{!18, !19, !20}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!"llvm.loop.unswitch.partial.disable"}
!21 = !{!6, !13, i64 232}
!22 = !{!10, !10, i64 0}
!23 = distinct !{!23, !19}


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