; LLVM IR from sympiler/nasoq :: src/gmres/mgmres.ll (ZN5nasoq19diagonal_pointer_crEiiPiS0_S0_)

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

; 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 nounwind uwtable
define dso_local void @_ZN5nasoq19diagonal_pointer_crEiiPiS0_S0_(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %60, %5
  %17 = load i32, ptr %11, align 4, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %63

20:                                               ; preds = %16
  %21 = load ptr, ptr %10, align 8, !tbaa !9
  %22 = load i32, ptr %11, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %21, i64 %23
  store i32 -1, ptr %24, align 4, !tbaa !5
  %25 = load ptr, ptr %8, align 8, !tbaa !9
  %26 = load i32, ptr %11, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i32, ptr %25, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  store i32 %29, ptr %13, align 4, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !9
  %31 = load i32, ptr %11, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i32, ptr %30, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  store i32 %35, ptr %14, align 4, !tbaa !5
  %36 = load i32, ptr %13, align 4, !tbaa !5
  store i32 %36, ptr %12, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %56, %20
  %38 = load i32, ptr %12, align 4, !tbaa !5
  %39 = load i32, ptr %14, align 4, !tbaa !5
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %41, label %59

41:                                               ; preds = %37
  %42 = load ptr, ptr %9, align 8, !tbaa !9
  %43 = load i32, ptr %12, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i32, ptr %42, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = load i32, ptr %11, align 4, !tbaa !5
  %48 = icmp eq i32 %46, %47
  br i1 %48, label %49, label %55

49:                                               ; preds = %41
  %50 = load i32, ptr %12, align 4, !tbaa !5
  %51 = load ptr, ptr %10, align 8, !tbaa !9
  %52 = load i32, ptr %11, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i32, ptr %51, i64 %53
  store i32 %50, ptr %54, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %49, %41
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %12, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %12, align 4, !tbaa !5
  br label %37, !llvm.loop !11

59:                                               ; preds = %37
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %11, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %11, align 4, !tbaa !5
  br label %16, !llvm.loop !13

63:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  ret void
}

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 }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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 nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_ZN5nasoq19diagonal_pointer_crEiiPiS0_S0_(i32 noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #0 {
  %6 = icmp sgt i32 %0, 0
  br i1 %6, label %.lr.ph21.preheader, label %._crit_edge

.lr.ph21.preheader:                               ; preds = %5
  %wide.trip.count26 = zext nneg i32 %0 to i64
  br label %.lr.ph21

.loopexit:                                        ; preds = %.lr.ph.prol.loopexit, %34, %.lr.ph21
  %exitcond27.not = icmp eq i64 %indvars.iv.next24, %wide.trip.count26
  br i1 %exitcond27.not, label %._crit_edge, label %.lr.ph21, !llvm.loop !5

.lr.ph21:                                         ; preds = %.lr.ph21.preheader, %.loopexit
  %indvars.iv23 = phi i64 [ 0, %.lr.ph21.preheader ], [ %indvars.iv.next24, %.loopexit ]
  %7 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv23
  store i32 -1, ptr %7, align 4, !tbaa !7
  %8 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv23
  %9 = load i32, ptr %8, align 4, !tbaa !7
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %10 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv.next24
  %11 = load i32, ptr %10, align 4, !tbaa !7
  %12 = icmp slt i32 %9, %11
  br i1 %12, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.lr.ph21
  %13 = sext i32 %9 to i64
  %wide.trip.count = sext i32 %11 to i64
  %14 = sub nsw i64 %wide.trip.count, %13
  %xtraiter = and i64 %14, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader
  %15 = getelementptr inbounds i32, ptr %3, i64 %13
  %16 = load i32, ptr %15, align 4, !tbaa !7
  %17 = zext i32 %16 to i64
  %18 = icmp eq i64 %indvars.iv23, %17
  br i1 %18, label %19, label %.lr.ph.prol.loopexit.unr-lcssa

19:                                               ; preds = %.lr.ph.prol
  store i32 %9, ptr %7, align 4, !tbaa !7
  br label %.lr.ph.prol.loopexit.unr-lcssa

.lr.ph.prol.loopexit.unr-lcssa:                   ; preds = %19, %.lr.ph.prol
  %indvars.iv.next.prol = add nsw i64 %13, 1
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol.loopexit.unr-lcssa, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ %13, %.lr.ph.preheader ], [ %indvars.iv.next.prol, %.lr.ph.prol.loopexit.unr-lcssa ]
  %20 = add nsw i64 %wide.trip.count, -1
  %21 = icmp eq i64 %20, %13
  br i1 %21, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %34
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %34 ], [ %indvars.iv.unr, %.lr.ph.prol.loopexit ]
  %22 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv
  %23 = load i32, ptr %22, align 4, !tbaa !7
  %24 = zext i32 %23 to i64
  %25 = icmp eq i64 %indvars.iv23, %24
  br i1 %25, label %26, label %.lr.ph.1

26:                                               ; preds = %.lr.ph
  %27 = trunc nsw i64 %indvars.iv to i32
  store i32 %27, ptr %7, align 4, !tbaa !7
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph, %26
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %28 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv.next
  %29 = load i32, ptr %28, align 4, !tbaa !7
  %30 = zext i32 %29 to i64
  %31 = icmp eq i64 %indvars.iv23, %30
  br i1 %31, label %32, label %34

32:                                               ; preds = %.lr.ph.1
  %33 = trunc nsw i64 %indvars.iv.next to i32
  store i32 %33, ptr %7, align 4, !tbaa !7
  br label %34

34:                                               ; preds = %32, %.lr.ph.1
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %wide.trip.count
  br i1 %exitcond.not.1, label %.loopexit, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.loopexit, %5
  ret void
}

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


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