; LLVM IR from TharushaDinujaya/MicroMouse :: test/mms-cpp/tracker.ll (Z11updateTrackPPiS0_ii)

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

%struct.Point = type { i32, i32 }

@_ZL8colorMap = external hidden global <{ <{ i8, [15 x i8] }>, [15 x <{ i8, [15 x i8] }>] }>, align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z11updateTrackPPiS0_ii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.Point, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @_Z15unregisterTrackv()
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %27, %4
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds ptr, ptr %12, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i32, ptr %16, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %25

22:                                               ; preds = %11
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = icmp slt i32 %23, 300
  br label %25

25:                                               ; preds = %22, %11
  %26 = phi i1 [ false, %11 ], [ %24, %22 ]
  br i1 %26, label %27, label %45

27:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = call i64 @_Z19getMinimumNeighbourPPiS0_ii(ptr noundef %28, ptr noundef %29, i32 noundef %30, i32 noundef %31)
  store i64 %32, ptr %10, align 4
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [16 x [16 x i8]], ptr @_ZL8colorMap, i64 0, i64 %34
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [16 x i8], ptr %35, i64 0, i64 %37
  store i8 71, ptr %38, align 1, !tbaa !11
  %39 = getelementptr inbounds %struct.Point, ptr %10, i32 0, i32 0
  %40 = load i32, ptr %39, align 4, !tbaa !12
  store i32 %40, ptr %7, align 4, !tbaa !9
  %41 = getelementptr inbounds %struct.Point, ptr %10, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !14
  store i32 %42, ptr %8, align 4, !tbaa !9
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %11, !llvm.loop !15

45:                                               ; preds = %25
  call void @_Z14renderColorMapv()
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z15unregisterTrackv() #0

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

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_Z19getMinimumNeighbourPPiS0_ii(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #0

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z14renderColorMapv() #0

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 0}
!13 = !{!"_ZTS5Point", !10, i64 0, !10, i64 4}
!14 = !{!13, !10, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@_ZL8colorMap = external hidden local_unnamed_addr global <{ <{ i8, [15 x i8] }>, [15 x <{ i8, [15 x i8] }>] }>, align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z11updateTrackPPiS0_ii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  tail call void @_Z15unregisterTrackv()
  %5 = sext i32 %2 to i64
  %6 = getelementptr inbounds ptr, ptr %0, i64 %5
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = sext i32 %3 to i64
  %9 = getelementptr inbounds i32, ptr %7, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %.lr.ph
  %11 = phi i64 [ %19, %.lr.ph ], [ %8, %4 ]
  %12 = phi i64 [ %16, %.lr.ph ], [ %5, %4 ]
  %.014 = phi i32 [ %.sroa.0.0.extract.trunc, %.lr.ph ], [ %2, %4 ]
  %.01013 = phi i32 [ %.sroa.4.0.extract.trunc, %.lr.ph ], [ %3, %4 ]
  %.01112 = phi i32 [ %15, %.lr.ph ], [ 0, %4 ]
  %13 = tail call i64 @_Z19getMinimumNeighbourPPiS0_ii(ptr noundef nonnull %0, ptr noundef %1, i32 noundef %.014, i32 noundef %.01013)
  %.sroa.0.0.extract.trunc = trunc i64 %13 to i32
  %.sroa.4.0.extract.shift = lshr i64 %13, 32
  %.sroa.4.0.extract.trunc = trunc nuw i64 %.sroa.4.0.extract.shift to i32
  %14 = getelementptr inbounds [16 x [16 x i8]], ptr @_ZL8colorMap, i64 0, i64 %12, i64 %11
  store i8 71, ptr %14, align 1, !tbaa !11
  %15 = add nuw nsw i32 %.01112, 1
  %sext = shl i64 %13, 32
  %16 = ashr exact i64 %sext, 32
  %17 = getelementptr inbounds ptr, ptr %0, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %19 = ashr i64 %13, 32
  %20 = getelementptr inbounds i32, ptr %18, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = icmp ne i32 %21, 0
  %23 = icmp ult i32 %.01112, 299
  %24 = select i1 %22, i1 %23, i1 false
  br i1 %24, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %4
  tail call void @_Z14renderColorMapv()
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z15unregisterTrackv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_Z19getMinimumNeighbourPPiS0_ii(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z14renderColorMapv() local_unnamed_addr #0

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, !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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass